summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/plattools/test_adc.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/plattools/test_adc.c')
-rw-r--r--utils/nwztools/plattools/test_adc.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/test_adc.c b/utils/nwztools/plattools/test_adc.c
new file mode 100644
index 0000000000..52eafd042d
--- /dev/null
+++ b/utils/nwztools/plattools/test_adc.c
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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_adc");
+ 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, 7, "Cannot open input device");
+ sleep(2);
+ return 1;
+ }
+ /* open adc device */
+ int adc_fd = nwz_adc_open();
+ if(adc_fd < 0)
+ {
+ nwz_lcdmsg(false, 3, 4, "Cannot open adc device");
+ sleep(2);
+ return 1;
+ }
+ /* display input state in a loop */
+ while(1)
+ {
+ /* print channels */
+ for(int i = NWZ_ADC_MIN_CHAN; i <= NWZ_ADC_MAX_CHAN; i++)
+ nwz_lcdmsgf(false, 1, 4 + i, "%s: %d ", nwz_adc_get_name(i),
+ nwz_adc_get_val(adc_fd, i));
+ /* wait for event (10ms) */
+ int ret = nwz_key_wait_event(input_fd, 10000);
+ 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;
+}
+