diff options
Diffstat (limited to 'apps/plugins/flipit.c')
-rw-r--r-- | apps/plugins/flipit.c | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/apps/plugins/flipit.c b/apps/plugins/flipit.c index 0b7893c969..973e27e299 100644 --- a/apps/plugins/flipit.c +++ b/apps/plugins/flipit.c | |||
@@ -19,6 +19,24 @@ | |||
19 | #include "plugin.h" | 19 | #include "plugin.h" |
20 | #ifdef HAVE_LCD_BITMAP | 20 | #ifdef HAVE_LCD_BITMAP |
21 | 21 | ||
22 | /* variable button definitions */ | ||
23 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
24 | #define FLIPIT_QUIT BUTTON_OFF | ||
25 | #define FLIPIT_SHUFFLE BUTTON_F1 | ||
26 | #define FLIPIT_SOLVE BUTTON_F2 | ||
27 | #define FLIPIT_STEP_BY_STEP BUTTON_F3 | ||
28 | #define FLIPIT_TOGGLE BUTTON_PLAY | ||
29 | |||
30 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
31 | #define FLIPIT_QUIT BUTTON_OFF | ||
32 | #define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT) | ||
33 | #define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP) | ||
34 | #define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT) | ||
35 | #define FLIPIT_TOGGLE_PRE BUTTON_MENU | ||
36 | #define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL) | ||
37 | |||
38 | #endif | ||
39 | |||
22 | static struct plugin_api* rb; | 40 | static struct plugin_api* rb; |
23 | static int spots[20]; | 41 | static int spots[20]; |
24 | static int toggle[20]; | 42 | static int toggle[20]; |
@@ -152,19 +170,23 @@ static void flipit_init(void) { | |||
152 | /* the main game loop */ | 170 | /* the main game loop */ |
153 | static bool flipit_loop(void) { | 171 | static bool flipit_loop(void) { |
154 | int i; | 172 | int i; |
173 | int button; | ||
174 | int lastbutton = BUTTON_NONE; | ||
175 | |||
155 | flipit_init(); | 176 | flipit_init(); |
156 | while(true) { | 177 | while(true) { |
157 | switch (rb->button_get(true)) { | 178 | button = rb->button_get(true); |
158 | case BUTTON_OFF: | 179 | switch (button) { |
180 | case FLIPIT_QUIT: | ||
159 | /* get out of here */ | 181 | /* get out of here */ |
160 | return PLUGIN_OK; | 182 | return PLUGIN_OK; |
161 | 183 | ||
162 | case BUTTON_F1: | 184 | case FLIPIT_SHUFFLE: |
163 | /* mix up the pieces */ | 185 | /* mix up the pieces */ |
164 | flipit_init(); | 186 | flipit_init(); |
165 | break; | 187 | break; |
166 | 188 | ||
167 | case BUTTON_F2: | 189 | case FLIPIT_SOLVE: |
168 | /* solve the puzzle */ | 190 | /* solve the puzzle */ |
169 | if (!flipit_finished()) { | 191 | if (!flipit_finished()) { |
170 | for (i=0; i<20; i++) | 192 | for (i=0; i<20; i++) |
@@ -179,7 +201,7 @@ static bool flipit_loop(void) { | |||
179 | } | 201 | } |
180 | break; | 202 | break; |
181 | 203 | ||
182 | case BUTTON_F3: | 204 | case FLIPIT_STEP_BY_STEP: |
183 | if (!flipit_finished()) { | 205 | if (!flipit_finished()) { |
184 | for (i=0; i<20; i++) | 206 | for (i=0; i<20; i++) |
185 | if (!toggle[i]) { | 207 | if (!toggle[i]) { |
@@ -193,7 +215,11 @@ static bool flipit_loop(void) { | |||
193 | } | 215 | } |
194 | break; | 216 | break; |
195 | 217 | ||
196 | case BUTTON_PLAY: | 218 | case FLIPIT_TOGGLE: |
219 | #ifdef FLIPIT_TOGGLE_PRE | ||
220 | if (lastbutton != FLIPIT_TOGGLE_PRE) | ||
221 | break; | ||
222 | #endif | ||
197 | /* toggle the pieces */ | 223 | /* toggle the pieces */ |
198 | if (!flipit_finished()) { | 224 | if (!flipit_finished()) { |
199 | flipit_toggle(); | 225 | flipit_toggle(); |
@@ -221,10 +247,13 @@ static bool flipit_loop(void) { | |||
221 | move_cursor(0, 1); | 247 | move_cursor(0, 1); |
222 | break; | 248 | break; |
223 | 249 | ||
224 | case SYS_USB_CONNECTED: | 250 | default: |
225 | rb->usb_screen(); | 251 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
226 | return PLUGIN_USB_CONNECTED; | 252 | return PLUGIN_USB_CONNECTED; |
253 | break; | ||
227 | } | 254 | } |
255 | if (button != BUTTON_NONE) | ||
256 | lastbutton = button; | ||
228 | } | 257 | } |
229 | } | 258 | } |
230 | 259 | ||
@@ -249,11 +278,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
249 | /* print instructions */ | 278 | /* print instructions */ |
250 | rb->lcd_clear_display(); | 279 | rb->lcd_clear_display(); |
251 | rb->lcd_setfont(FONT_SYSFIXED); | 280 | rb->lcd_setfont(FONT_SYSFIXED); |
281 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
252 | rb->lcd_putsxy(2, 8, "[OFF] to stop"); | 282 | rb->lcd_putsxy(2, 8, "[OFF] to stop"); |
253 | rb->lcd_putsxy(2, 18, "[PLAY] toggle"); | 283 | rb->lcd_putsxy(2, 18, "[PLAY] toggle"); |
254 | rb->lcd_putsxy(2, 28, "[F1] shuffle"); | 284 | rb->lcd_putsxy(2, 28, "[F1] shuffle"); |
255 | rb->lcd_putsxy(2, 38, "[F2] solution"); | 285 | rb->lcd_putsxy(2, 38, "[F2] solution"); |
256 | rb->lcd_putsxy(2, 48, "[F3] step by step"); | 286 | rb->lcd_putsxy(2, 48, "[F3] step by step"); |
287 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
288 | rb->lcd_putsxy(2, 8, "[OFF] to stop"); | ||
289 | rb->lcd_putsxy(2, 18, "[MENU] toggle"); | ||
290 | rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle"); | ||
291 | rb->lcd_putsxy(2, 38, "[M-UP] solution"); | ||
292 | rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step"); | ||
293 | #endif | ||
257 | rb->lcd_update(); | 294 | rb->lcd_update(); |
258 | rb->sleep(HZ*3); | 295 | rb->sleep(HZ*3); |
259 | 296 | ||