mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 10:31:02 +00:00
Each device keeps track of the last known state. If device_set_state updates the device state to a new known state, then return true. Cr50 uses this returned value to check if the state has changed instead of calculating it itself. BUG=none BRANCH=none TEST=device detection still works Change-Id: I8afac178c2c731def6f4f62ff7023fe169ec1479 Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/430970 Reviewed-by: Aaron Durbin <adurbin@chromium.org>
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
/* Copyright 2016 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "console.h"
|
|
#include "device_state.h"
|
|
#include "hooks.h"
|
|
|
|
int device_get_state(enum device_type device)
|
|
{
|
|
return device_states[device].state;
|
|
}
|
|
|
|
int device_set_state(enum device_type device, enum device_state state)
|
|
{
|
|
device_states[device].state = state;
|
|
|
|
if (state != DEVICE_STATE_UNKNOWN &&
|
|
device_states[device].last_known_state != state) {
|
|
device_states[device].last_known_state = state;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void check_device_state(void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < DEVICE_COUNT; i++)
|
|
board_update_device_state(i);
|
|
}
|
|
DECLARE_HOOK(HOOK_SECOND, check_device_state, HOOK_PRIO_DEFAULT);
|
|
|
|
static void print_state(const char *name, enum device_state state)
|
|
{
|
|
ccprintf("%-9s %s\n", name, state == DEVICE_STATE_ON ? "on" :
|
|
state == DEVICE_STATE_OFF ? "off" : "unknown");
|
|
}
|
|
|
|
static int command_devices(int argc, char **argv)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < DEVICE_COUNT; i++)
|
|
print_state(device_states[i].name,
|
|
device_states[i].state);
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
DECLARE_SAFE_CONSOLE_COMMAND(devices, command_devices,
|
|
"",
|
|
"Get the device states");
|