summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/plattools/test_power.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-10-20 18:21:00 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-26 20:46:57 +0200
commitd42b43c7860aacafbce97cccb3b2f19ad8812d56 (patch)
treeccfc7fa50ad154c47a1ebef85997fd316419aac7 /utils/nwztools/plattools/test_power.c
parentfed083cf06628b8912e3a355ad2c7c671e208ce3 (diff)
downloadrockbox-d42b43c7860aacafbce97cccb3b2f19ad8812d56.tar.gz
rockbox-d42b43c7860aacafbce97cccb3b2f19ad8812d56.tar.bz2
rockbox-d42b43c7860aacafbce97cccb3b2f19ad8812d56.zip
nwztools/plattools: add test_power, rework input, add test_ts (touchscreen)
Change-Id: I55ca29627801b5e760d1dbe407d96cd055f659ab
Diffstat (limited to 'utils/nwztools/plattools/test_power.c')
-rw-r--r--utils/nwztools/plattools/test_power.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/test_power.c b/utils/nwztools/plattools/test_power.c
new file mode 100644
index 0000000000..c02f689b17
--- /dev/null
+++ b/utils/nwztools/plattools/test_power.c
@@ -0,0 +1,134 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2016 Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "nwz_lib.h"
+
+static const char *charge_status_name(int chgstat)
+{
+ switch(chgstat)
+ {
+ case NWZ_POWER_STATUS_CHARGE_STATUS_CHARGING: return "charging";
+ case NWZ_POWER_STATUS_CHARGE_STATUS_SUSPEND: return "suspend";
+ case NWZ_POWER_STATUS_CHARGE_STATUS_TIMEOUT: return "timeout";
+ case NWZ_POWER_STATUS_CHARGE_STATUS_NORMAL: return "normal";
+ default: return "unknown";
+ }
+}
+
+static const char *get_batt_gauge_name(int gauge)
+{
+ switch(gauge)
+ {
+ case NWZ_POWER_BAT_NOBAT: return "no batt";
+ case NWZ_POWER_BAT_VERYLOW: return "very low";
+ case NWZ_POWER_BAT_LOW: return "low";
+ case NWZ_POWER_BAT_GAUGE0: return "____";
+ case NWZ_POWER_BAT_GAUGE1: return "O___";
+ case NWZ_POWER_BAT_GAUGE2: return "OO__";
+ case NWZ_POWER_BAT_GAUGE3: return "OOO_";
+ case NWZ_POWER_BAT_GAUGE4: return "OOOO";
+ default: return "unknown";
+ }
+}
+
+static const char *acc_charge_mode_name(int mode)
+{
+ switch(mode)
+ {
+ case NWZ_POWER_ACC_CHARGE_NONE: return "none";
+ case NWZ_POWER_ACC_CHARGE_VBAT: return "vbat";
+ case NWZ_POWER_ACC_CHARGE_VSYS: return "vsys";
+ default: return "unknown";
+ }
+}
+
+int main(int argc, char **argv)
+{
+ /* clear screen and display welcome message */
+ nwz_lcdmsg(true, 0, 0, "test_power");
+ nwz_lcdmsg(false, 0, 2, "PWR OFF: quit");
+ /* open input device */
+ int input_fd = nwz_key_open();
+ if(input_fd < 0)
+ {
+ nwz_lcdmsg(false, 3, 4, "Cannot open input device");
+ sleep(2);
+ return 1;
+ }
+ /* open adc device */
+ int power_fd = nwz_power_open();
+ if(power_fd < 0)
+ {
+ nwz_lcdmsg(false, 3, 4, "Cannot open power device");
+ sleep(2);
+ return 1;
+ }
+ /* display input state in a loop */
+ while(1)
+ {
+ /* print status */
+ int line = 4;
+ int status = nwz_power_get_status(power_fd);
+ int chgstat = status & NWZ_POWER_STATUS_CHARGE_STATUS;
+ int acc_chg_mode = nwz_power_get_acc_charge_mode(power_fd);
+ nwz_lcdmsgf(false, 0, line++, "ac detected: %s ",
+ (status & NWZ_POWER_STATUS_AC_DET) ? "yes" : "no");
+ nwz_lcdmsgf(false, 0, line++, "vbus detected: %s ",
+ (status & NWZ_POWER_STATUS_VBUS_DET) ? "yes" : "no");
+ nwz_lcdmsgf(false, 0, line++, "vbus voltage: %d mV (AD=%d) ",
+ nwz_power_get_vbus_voltage(power_fd), nwz_power_get_vbus_adval(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "vbus limit: %d mA ",
+ nwz_power_get_vbus_limit(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "vsys voltage: %d mV (AD=%d) ",
+ nwz_power_get_vsys_voltage(power_fd), nwz_power_get_vsys_adval(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "charge switch: %s ",
+ nwz_power_get_charge_switch(power_fd) ? "on" : "off");
+ nwz_lcdmsgf(false, 0, line++, "full voltage: %s V ",
+ (status & NWZ_POWER_STATUS_CHARGE_LOW) ? "4.1" : "4.2");
+ nwz_lcdmsgf(false, 0, line++, "current limit: %d mA ",
+ nwz_power_get_charge_current(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "charge status: %s (%x) ",
+ charge_status_name(chgstat), chgstat);
+ nwz_lcdmsgf(false, 0, line++, "battery full: %s ",
+ nwz_power_is_fully_charged(power_fd) ? "yes" : "no");
+ nwz_lcdmsgf(false, 0, line++, "bat gauge: %s (%d) ",
+ get_batt_gauge_name(nwz_power_get_battery_gauge(power_fd)),
+ nwz_power_get_battery_gauge(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "avg voltage: %d mV (AD=%d) ",
+ nwz_power_get_battery_voltage(power_fd), nwz_power_get_battery_adval(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "sample count: %d ",
+ nwz_power_get_sample_count(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "raw voltage: %d mV (AD=%d) ",
+ nwz_power_get_vbat_voltage(power_fd), nwz_power_get_vbat_adval(power_fd));
+ nwz_lcdmsgf(false, 0, line++, "acc charge mode: %s (%d) ",
+ acc_charge_mode_name(acc_chg_mode), acc_chg_mode);
+ /* wait for event (1s) */
+ int ret = nwz_key_wait_event(input_fd, 1000000);
+ if(ret != 1)
+ continue;
+ struct input_event evt;
+ if(nwz_key_read_event(input_fd, &evt) != 1)
+ continue;
+ if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && !nwz_key_event_is_press(&evt))
+ break;
+ }
+ /* finish nicely */
+ return 0;
+}