summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:58:40 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2016-10-19 17:58:40 +0200
commit8d24b62912305191b0aa83b802ac6f12014f1dc5 (patch)
tree5247ac482f786417db24dccd9403837a9d4c0f69
parentba91ff10e8c974e50e429d072641ac5e0acdd72e (diff)
downloadrockbox-8d24b62.tar.gz
rockbox-8d24b62.zip
nwztools/plattools: add backlight test
Change-Id: I4bef0824eeed54238578d8b24a9845e8602d61af
-rw-r--r--utils/nwztools/plattools/nwz_lib.c26
-rw-r--r--utils/nwztools/plattools/nwz_lib.h9
-rw-r--r--utils/nwztools/plattools/test_bl.c111
3 files changed, 146 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/nwz_lib.c b/utils/nwztools/plattools/nwz_lib.c
index ec862e638b..6316217902 100644
--- a/utils/nwztools/plattools/nwz_lib.c
+++ b/utils/nwztools/plattools/nwz_lib.c
@@ -157,3 +157,29 @@ const char *nwz_key_get_name(int keycode)
else
return nwz_keyname[keycode];
}
+
+int nwz_fb_open(bool lcd)
+{
+ return open(lcd ? "/dev/fb/0" : "/dev/fb/1", O_RDWR);
+}
+
+void nwz_fb_close(int fd)
+{
+ close(fd);
+}
+
+int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl)
+{
+ if(ioctl(fd, NWZ_FB_GET_BRIGHTNESS, bl) < 0)
+ return -1;
+ else
+ return 1;
+}
+
+int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl)
+{
+ if(ioctl(fd, NWZ_FB_SET_BRIGHTNESS, bl) < 0)
+ return -1;
+ else
+ return 1;
+}
diff --git a/utils/nwztools/plattools/nwz_lib.h b/utils/nwztools/plattools/nwz_lib.h
index e9d885d87a..86f11ac346 100644
--- a/utils/nwztools/plattools/nwz_lib.h
+++ b/utils/nwztools/plattools/nwz_lib.h
@@ -31,6 +31,7 @@
#include <fcntl.h>
#include "nwz_keys.h"
+#include "nwz_fb.h"
/* run a program and exit with nonzero status in case of error
* argument list must be NULL terminated */
@@ -60,5 +61,13 @@ bool nwz_key_event_is_press(struct input_event *evt);
bool nwz_key_event_get_hold_status(struct input_event *evt);
/* get keycode name */
const char *nwz_key_get_name(int keycode);
+/* open framebuffer device */
+int nwz_fb_open(bool lcd);
+/* close framebuffer device */
+void nwz_fb_close(int fb);
+/* get backlight brightness (return -1 on error, 1 on success) */
+int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl);
+/* set backlight brightness (return -1 on error, 1 on success) */
+int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl);
#endif /* _NWZLIB_H_ */
diff --git a/utils/nwztools/plattools/test_bl.c b/utils/nwztools/plattools/test_bl.c
new file mode 100644
index 0000000000..b70f81b957
--- /dev/null
+++ b/utils/nwztools/plattools/test_bl.c
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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_bl");
+ nwz_lcdmsg(false, 0, 2, "UP/DOWN: level");
+ nwz_lcdmsg(false, 0, 3, "LEFT/RIGHT: step");
+ nwz_lcdmsg(false, 0, 4, "VOL UP/DOWN: period");
+ nwz_lcdmsg(false, 0, 5, "PWR OFF: quit");
+ /* open input and framebuffer device */
+ int input_fd = nwz_key_open();
+ if(input_fd < 0)
+ {
+ nwz_lcdmsg(false, 3, 7, "Cannot open input device");
+ sleep(2);
+ return 1;
+ }
+ int fb_fd = nwz_fb_open(true);
+ if(fb_fd < 0)
+ {
+ nwz_lcdmsg(false, 3, 7, "Cannot open framebuffer device");
+ sleep(2);
+ return 1;
+ }
+ /* display input state in a loop */
+ while(1)
+ {
+ struct nwz_fb_brightness bl;
+ if(nwz_fb_get_brightness(fb_fd, &bl) == 1)
+ {
+ nwz_lcdmsgf(false, 1, 7, "level: %d ", bl.level);
+ nwz_lcdmsgf(false, 1, 8, "step: %d ", bl.step);
+ nwz_lcdmsgf(false, 1, 9, "period: %d ", bl.period);
+ }
+ /* wait for event */
+ int ret = nwz_key_wait_event(input_fd, -1);
+ if(ret != 1)
+ continue;
+ struct input_event evt;
+ if(nwz_key_read_event(input_fd, &evt) != 1)
+ continue;
+ int code = nwz_key_event_get_keycode(&evt);
+ bool press = nwz_key_event_is_press(&evt);
+ /* only act on release */
+ if(press)
+ continue;
+ if(code == NWZ_KEY_OPTION)
+ break; /* quit */
+ bool change_bl = false;
+ if(code == NWZ_KEY_UP && bl.level < NWZ_FB_BL_MAX_LEVEL)
+ {
+ change_bl = true;
+ bl.level++;
+ }
+ else if(code == NWZ_KEY_DOWN && bl.level > NWZ_FB_BL_MIN_LEVEL)
+ {
+ change_bl = true;
+ bl.level--;
+ }
+ else if(code == NWZ_KEY_RIGHT && bl.step < NWZ_FB_BL_MAX_STEP)
+ {
+ change_bl = true;
+ bl.step++;
+ }
+ else if(code == NWZ_KEY_LEFT && bl.step > NWZ_FB_BL_MIN_STEP)
+ {
+ change_bl = true;
+ bl.step--;
+ }
+ else if(code == NWZ_KEY_VOL_UP && bl.period < 100) /* artificial bound on period */
+ {
+ change_bl = true;
+ bl.period++;
+ }
+ else if(code == NWZ_KEY_VOL_DOWN && bl.period > NWZ_FB_BL_MIN_PERIOD)
+ {
+ change_bl = true;
+ bl.period--;
+ }
+ /* change bl */
+ if(change_bl)
+ nwz_fb_set_brightness(fb_fd, &bl);
+ }
+ /* close input device */
+ close(input_fd);
+ /* finish nicely */
+ return 0;
+}
+
+