diff options
Diffstat (limited to 'apps/plugins/oscillograph.c')
-rw-r--r-- | apps/plugins/oscillograph.c | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/apps/plugins/oscillograph.c b/apps/plugins/oscillograph.c index a34aa8bfa9..5beeb8891b 100644 --- a/apps/plugins/oscillograph.c +++ b/apps/plugins/oscillograph.c | |||
@@ -29,6 +29,28 @@ | |||
29 | 29 | ||
30 | #define MAX_PEAK 0x8000 | 30 | #define MAX_PEAK 0x8000 |
31 | 31 | ||
32 | /* variable button definitions */ | ||
33 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
34 | #define OSCILLOGRAPH_QUIT BUTTON_OFF | ||
35 | #define OSCILLOGRAPH_SPEED_UP BUTTON_UP | ||
36 | #define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN | ||
37 | #define OSCILLOGRAPH_ROLL BUTTON_F1 | ||
38 | #define OSCILLOGRAPH_MODE BUTTON_F2 | ||
39 | #define OSCILLOGRAPH_SPEED_RESET BUTTON_F3 | ||
40 | #define OSCILLOGRAPH_PAUSE BUTTON_PLAY | ||
41 | |||
42 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
43 | #define OSCILLOGRAPH_QUIT BUTTON_OFF | ||
44 | #define OSCILLOGRAPH_SPEED_UP BUTTON_UP | ||
45 | #define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN | ||
46 | #define OSCILLOGRAPH_ROLL BUTTON_RIGHT | ||
47 | #define OSCILLOGRAPH_MODE BUTTON_MENU | ||
48 | #define OSCILLOGRAPH_SPEED_RESET BUTTON_LEFT | ||
49 | |||
50 | #endif | ||
51 | |||
52 | /* global api struct pointer */ | ||
53 | static struct plugin_api* rb; | ||
32 | /* number of ticks between two volume samples */ | 54 | /* number of ticks between two volume samples */ |
33 | static int speed = 1; | 55 | static int speed = 1; |
34 | /* roll == true -> lcd rolls */ | 56 | /* roll == true -> lcd rolls */ |
@@ -37,12 +59,26 @@ static bool roll = true; | |||
37 | static int drawMode = DRAW_MODE_FILLED; | 59 | static int drawMode = DRAW_MODE_FILLED; |
38 | 60 | ||
39 | /** | 61 | /** |
62 | * cleanup on return / usb | ||
63 | */ | ||
64 | void cleanup(void *parameter) | ||
65 | { | ||
66 | (void)parameter; | ||
67 | |||
68 | /* restore to default roll position. | ||
69 | Looks funny if you forget to do this... */ | ||
70 | rb->lcd_roll(0); | ||
71 | rb->lcd_update(); | ||
72 | } | ||
73 | |||
74 | /** | ||
40 | * Displays a vertically scrolling oscillosgraph using | 75 | * Displays a vertically scrolling oscillosgraph using |
41 | * hardware scrolling of the display. The user can change | 76 | * hardware scrolling of the display. The user can change |
42 | * speed | 77 | * speed |
43 | */ | 78 | */ |
44 | enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) | 79 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
45 | { | 80 | { |
81 | int button; | ||
46 | /* stores current volume value left */ | 82 | /* stores current volume value left */ |
47 | int left; | 83 | int left; |
48 | /* stores current volume value right */ | 84 | /* stores current volume value right */ |
@@ -57,8 +93,9 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) | |||
57 | 93 | ||
58 | bool exit = false; | 94 | bool exit = false; |
59 | 95 | ||
60 | TEST_PLUGIN_API(rb); | 96 | TEST_PLUGIN_API(api); |
61 | (void)parameter; | 97 | (void)parameter; |
98 | rb = api; | ||
62 | 99 | ||
63 | /* the main loop */ | 100 | /* the main loop */ |
64 | while (!exit) { | 101 | while (!exit) { |
@@ -135,28 +172,31 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) | |||
135 | it must be ensured that at least 1 is passed. */ | 172 | it must be ensured that at least 1 is passed. */ |
136 | 173 | ||
137 | /* react to user input */ | 174 | /* react to user input */ |
138 | switch (rb->button_get_w_tmo(MAX(speed, 1))) { | 175 | button = rb->button_get_w_tmo(MAX(speed, 1)); |
139 | case BUTTON_UP: | 176 | switch (button) { |
177 | case OSCILLOGRAPH_SPEED_UP: | ||
140 | speed++; | 178 | speed++; |
141 | draw = true; | 179 | draw = true; |
142 | break; | 180 | break; |
143 | 181 | ||
144 | case BUTTON_DOWN: | 182 | case OSCILLOGRAPH_SPEED_DOWN: |
145 | speed--; | 183 | speed--; |
146 | draw = true; | 184 | draw = true; |
147 | break; | 185 | break; |
148 | 186 | ||
149 | case BUTTON_PLAY: | 187 | #ifdef OSCILLOGRAPH_PAUSE |
188 | case OSCILLOGRAPH_PAUSE: | ||
150 | /* pause the demo */ | 189 | /* pause the demo */ |
151 | rb->button_get(true); | 190 | rb->button_get(true); |
152 | break; | 191 | break; |
192 | #endif | ||
153 | 193 | ||
154 | case BUTTON_F1: | 194 | case OSCILLOGRAPH_ROLL: |
155 | /* toggle rolling */ | 195 | /* toggle rolling */ |
156 | roll = !roll; | 196 | roll = !roll; |
157 | break; | 197 | break; |
158 | 198 | ||
159 | case BUTTON_F2: | 199 | case OSCILLOGRAPH_MODE: |
160 | /* step through the display modes */ | 200 | /* step through the display modes */ |
161 | drawMode ++; | 201 | drawMode ++; |
162 | drawMode = drawMode % DRAW_MODE_COUNT; | 202 | drawMode = drawMode % DRAW_MODE_COUNT; |
@@ -170,18 +210,20 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) | |||
170 | rb->lcd_roll(0); | 210 | rb->lcd_roll(0); |
171 | break; | 211 | break; |
172 | 212 | ||
173 | case BUTTON_F3: | 213 | case OSCILLOGRAPH_SPEED_RESET: |
174 | speed = 1; | 214 | speed = 1; |
175 | draw = true; | 215 | draw = true; |
176 | break; | 216 | break; |
177 | 217 | ||
178 | case BUTTON_OFF: | 218 | case OSCILLOGRAPH_QUIT: |
179 | exit = true; | 219 | exit = true; |
180 | break; | 220 | break; |
181 | 221 | ||
182 | case SYS_USB_CONNECTED: | 222 | default: |
183 | rb->usb_screen(); | 223 | if (rb->default_event_handler_ex(button, cleanup, NULL) |
184 | return PLUGIN_USB_CONNECTED; | 224 | == SYS_USB_CONNECTED) |
225 | return PLUGIN_USB_CONNECTED; | ||
226 | break; | ||
185 | } | 227 | } |
186 | 228 | ||
187 | if (draw) { | 229 | if (draw) { |
@@ -191,14 +233,10 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) | |||
191 | rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT, | 233 | rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT, |
192 | LCD_WIDTH, 8); | 234 | LCD_WIDTH, 8); |
193 | } | 235 | } |
194 | } | 236 | } |
195 | } | 237 | } |
196 | 238 | ||
197 | /* restore to default roll position. | 239 | cleanup(NULL); |
198 | Looks funny if you forget to do this... */ | ||
199 | rb->lcd_roll(0); | ||
200 | rb->lcd_update(); | ||
201 | |||
202 | /* standard return */ | 240 | /* standard return */ |
203 | return PLUGIN_OK; | 241 | return PLUGIN_OK; |
204 | } | 242 | } |