summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/charge_state_v2.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index db5966ee0a..5eb37e83a0 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -50,6 +50,8 @@ static int battery_seems_to_be_dead;
static int battery_seems_to_be_disconnected;
static int problems_exist;
static int debugging;
+static int fake_state_of_charge = -1;
+
/* Track problems in communicating with the battery or charger */
enum problem_type {
@@ -597,6 +599,12 @@ void charger_task(void)
charger_get_params(&curr.chg);
battery_get_params(&curr.batt);
+ /* Fake state of charge if necessary */
+ if (fake_state_of_charge >= 0) {
+ curr.batt.state_of_charge = fake_state_of_charge;
+ curr.batt.flags &= ~BATT_FLAG_BAD_STATE_OF_CHARGE;
+ }
+
/*
* TODO(crosbug.com/p/27527). Sometimes the battery thinks its
* temperature is 6280C, which seems a bit high. Let's ignore
@@ -1121,6 +1129,30 @@ DECLARE_HOST_COMMAND(EC_CMD_CHARGE_STATE, charge_command_charge_state,
/*****************************************************************************/
/* Console commands */
+static int command_battfake(int argc, char **argv)
+{
+ char *e;
+ int v;
+
+ if (argc == 2) {
+ v = strtoi(argv[1], &e, 0);
+ if (*e || v < -1 || v > 100)
+ return EC_ERROR_PARAM1;
+
+ fake_state_of_charge = v;
+ }
+
+ if (fake_state_of_charge >= 0)
+ ccprintf("Fake batt %d%%\n",
+ fake_state_of_charge);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(battfake, command_battfake,
+ "percent (-1 = use real level)",
+ "Set fake battery level",
+ NULL);
+
static int command_chgstate(int argc, char **argv)
{
int rv;