summaryrefslogtreecommitdiff
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-8d24b62912305191b0aa83b802ac6f12014f1dc5.tar.gz
rockbox-8d24b62912305191b0aa83b802ac6f12014f1dc5.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)
157 else 157 else
158 return nwz_keyname[keycode]; 158 return nwz_keyname[keycode];
159} 159}
160
161int nwz_fb_open(bool lcd)
162{
163 return open(lcd ? "/dev/fb/0" : "/dev/fb/1", O_RDWR);
164}
165
166void nwz_fb_close(int fd)
167{
168 close(fd);
169}
170
171int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl)
172{
173 if(ioctl(fd, NWZ_FB_GET_BRIGHTNESS, bl) < 0)
174 return -1;
175 else
176 return 1;
177}
178
179int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl)
180{
181 if(ioctl(fd, NWZ_FB_SET_BRIGHTNESS, bl) < 0)
182 return -1;
183 else
184 return 1;
185}
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 @@
31#include <fcntl.h> 31#include <fcntl.h>
32 32
33#include "nwz_keys.h" 33#include "nwz_keys.h"
34#include "nwz_fb.h"
34 35
35/* run a program and exit with nonzero status in case of error 36/* run a program and exit with nonzero status in case of error
36 * argument list must be NULL terminated */ 37 * argument list must be NULL terminated */
@@ -60,5 +61,13 @@ bool nwz_key_event_is_press(struct input_event *evt);
60bool nwz_key_event_get_hold_status(struct input_event *evt); 61bool nwz_key_event_get_hold_status(struct input_event *evt);
61/* get keycode name */ 62/* get keycode name */
62const char *nwz_key_get_name(int keycode); 63const char *nwz_key_get_name(int keycode);
64/* open framebuffer device */
65int nwz_fb_open(bool lcd);
66/* close framebuffer device */
67void nwz_fb_close(int fb);
68/* get backlight brightness (return -1 on error, 1 on success) */
69int nwz_fb_get_brightness(int fd, struct nwz_fb_brightness *bl);
70/* set backlight brightness (return -1 on error, 1 on success) */
71int nwz_fb_set_brightness(int fd, struct nwz_fb_brightness *bl);
63 72
64#endif /* _NWZLIB_H_ */ 73#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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "nwz_lib.h"
22
23int main(int argc, char **argv)
24{
25 /* clear screen and display welcome message */
26 nwz_lcdmsg(true, 0, 0, "test_bl");
27 nwz_lcdmsg(false, 0, 2, "UP/DOWN: level");
28 nwz_lcdmsg(false, 0, 3, "LEFT/RIGHT: step");
29 nwz_lcdmsg(false, 0, 4, "VOL UP/DOWN: period");
30 nwz_lcdmsg(false, 0, 5, "PWR OFF: quit");
31 /* open input and framebuffer device */
32 int input_fd = nwz_key_open();
33 if(input_fd < 0)
34 {
35 nwz_lcdmsg(false, 3, 7, "Cannot open input device");
36 sleep(2);
37 return 1;
38 }
39 int fb_fd = nwz_fb_open(true);
40 if(fb_fd < 0)
41 {
42 nwz_lcdmsg(false, 3, 7, "Cannot open framebuffer device");
43 sleep(2);
44 return 1;
45 }
46 /* display input state in a loop */
47 while(1)
48 {
49 struct nwz_fb_brightness bl;
50 if(nwz_fb_get_brightness(fb_fd, &bl) == 1)
51 {
52 nwz_lcdmsgf(false, 1, 7, "level: %d ", bl.level);
53 nwz_lcdmsgf(false, 1, 8, "step: %d ", bl.step);
54 nwz_lcdmsgf(false, 1, 9, "period: %d ", bl.period);
55 }
56 /* wait for event */
57 int ret = nwz_key_wait_event(input_fd, -1);
58 if(ret != 1)
59 continue;
60 struct input_event evt;
61 if(nwz_key_read_event(input_fd, &evt) != 1)
62 continue;
63 int code = nwz_key_event_get_keycode(&evt);
64 bool press = nwz_key_event_is_press(&evt);
65 /* only act on release */
66 if(press)
67 continue;
68 if(code == NWZ_KEY_OPTION)
69 break; /* quit */
70 bool change_bl = false;
71 if(code == NWZ_KEY_UP && bl.level < NWZ_FB_BL_MAX_LEVEL)
72 {
73 change_bl = true;
74 bl.level++;
75 }
76 else if(code == NWZ_KEY_DOWN && bl.level > NWZ_FB_BL_MIN_LEVEL)
77 {
78 change_bl = true;
79 bl.level--;
80 }
81 else if(code == NWZ_KEY_RIGHT && bl.step < NWZ_FB_BL_MAX_STEP)
82 {
83 change_bl = true;
84 bl.step++;
85 }
86 else if(code == NWZ_KEY_LEFT && bl.step > NWZ_FB_BL_MIN_STEP)
87 {
88 change_bl = true;
89 bl.step--;
90 }
91 else if(code == NWZ_KEY_VOL_UP && bl.period < 100) /* artificial bound on period */
92 {
93 change_bl = true;
94 bl.period++;
95 }
96 else if(code == NWZ_KEY_VOL_DOWN && bl.period > NWZ_FB_BL_MIN_PERIOD)
97 {
98 change_bl = true;
99 bl.period--;
100 }
101 /* change bl */
102 if(change_bl)
103 nwz_fb_set_brightness(fb_fd, &bl);
104 }
105 /* close input device */
106 close(input_fd);
107 /* finish nicely */
108 return 0;
109}
110
111