summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/plattools/test_keys.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:03:52 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:09:04 +0200
commitba91ff10e8c974e50e429d072641ac5e0acdd72e (patch)
treea8ef07988845f67e22dfed9bef3602126e831da0 /utils/nwztools/plattools/test_keys.c
parent13d892eef1c78d14314b7d3a2cb9035e9ba1420c (diff)
downloadrockbox-ba91ff10e8c974e50e429d072641ac5e0acdd72e.tar.gz
rockbox-ba91ff10e8c974e50e429d072641ac5e0acdd72e.zip
nwztools: add a new plattools directory with code to run on the device
This is code is intended to development into a library of code for the NWZ that will be useful to write the "bootloader" on those device. At the same time, it comes with test programs that are easy to run in firmware upgrade mode and also provide a great test bench for the library. At the moment, two test programs are available: - test_display: simply prints two messages using /usr/bin/lcdmsg - test_keys: displays input key event Change-Id: I9d214894ffc9127b528fcdd3eb5d6b61f4e657a7
Diffstat (limited to 'utils/nwztools/plattools/test_keys.c')
-rw-r--r--utils/nwztools/plattools/test_keys.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/test_keys.c b/utils/nwztools/plattools/test_keys.c
new file mode 100644
index 0000000000..3640e007fc
--- /dev/null
+++ b/utils/nwztools/plattools/test_keys.c
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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"
+
+int main(int argc, char **argv)
+{
+ /* clear screen and display welcome message */
+ nwz_lcdmsg(true, 0, 0, "test_keys");
+ nwz_lcdmsg(false, 0, 2, "hold PWR OFF for 3 seconds to 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;
+ }
+ /* display input state in a loop */
+ int pwr_off_pressed = 0; /* 0 = no pressed, >0 = number of seconds pressed - 1 */
+ while(1)
+ {
+ /* display HOLD status */
+ nwz_lcdmsgf(false, 2, 5, "HOLD: %d", nwz_key_get_hold_status(input_fd));
+ /* wait for event */
+ int ret = nwz_key_wait_event(input_fd, 1000000);
+ if(ret != 1)
+ {
+ if(pwr_off_pressed > 0)
+ pwr_off_pressed++;
+ if(pwr_off_pressed >= 4)
+ break;
+ continue;
+ }
+ struct input_event evt;
+ if(nwz_key_read_event(input_fd, &evt) != 1)
+ continue;
+ nwz_lcdmsgf(false, 2, 6, "%s %s (HOLD=%d) ",
+ nwz_key_get_name(nwz_key_event_get_keycode(&evt)),
+ nwz_key_event_is_press(&evt) ? "pressed" : "released",
+ nwz_key_event_get_hold_status(&evt));
+ if(nwz_key_event_get_keycode(&evt) == NWZ_KEY_OPTION && nwz_key_event_is_press(&evt))
+ pwr_off_pressed = 1;
+ else
+ pwr_off_pressed = 0;
+ }
+ /* close input device */
+ close(input_fd);
+ /* finish nicely */
+ return 0;
+}
+