summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/cube.c115
1 files changed, 92 insertions, 23 deletions
diff --git a/apps/plugins/cube.c b/apps/plugins/cube.c
index 378e39003c..4279a04ac6 100644
--- a/apps/plugins/cube.c
+++ b/apps/plugins/cube.c
@@ -19,6 +19,7 @@
19* 19*
20***************************************************************************/ 20***************************************************************************/
21#include "plugin.h" 21#include "plugin.h"
22#include "gray.h"
22#include "playergfx.h" 23#include "playergfx.h"
23#include "xlcd.h" 24#include "xlcd.h"
24 25
@@ -122,21 +123,52 @@ PLUGIN_HEADER
122#endif 123#endif
123 124
124#ifdef HAVE_LCD_BITMAP 125#ifdef HAVE_LCD_BITMAP
125#define MYLCD(fn) rb->lcd_ ## fn 126
126#define DIST (10*LCD_HEIGHT/16) 127#define DIST (10*LCD_HEIGHT/16)
127static int x_off = LCD_WIDTH/2; 128static int x_off = LCD_WIDTH/2;
128static int y_off = LCD_HEIGHT/2; 129static int y_off = LCD_HEIGHT/2;
130
131#if LCD_DEPTH == 1 && !defined(SIMULATOR)
132#define USE_GSLIB
133struct my_lcd {
134 void (*update)(void);
135 void (*clear_display)(void);
136 void (*drawline)(int x1, int y1, int x2, int y2);
137 void (*putsxy)(int x, int y, const unsigned char *string);
138};
139
140static struct my_lcd grayfuncs = {
141 gray_update, gray_clear_display, gray_drawline, gray_putsxy
142};
143static struct my_lcd lcdfuncs; /* initialised at runtime */
144static struct my_lcd *mylcd = &grayfuncs;
145
146#define MYLCD(fn) mylcd->fn
147#define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) gray_filltriangle(x1, y1, x2, y2, x3, y3)
148#define MY_SET_FOREGROUND(fg) gray_set_foreground(fg)
149#define MY_BLACK GRAY_BLACK
150
151#else
152#define MYLCD(fn) rb->lcd_ ## fn
153#define MY_FILLTRIANGLE(x1, y1, x2, y2, x3, y3) xlcd_filltriangle(x1, y1, x2, y2, x3, y3)
154#define MY_SET_FOREGROUND(fg) rb->lcd_set_foreground(fg)
155#define MY_BLACK LCD_BLACK
156#endif
157
129#if CONFIG_LCD == LCD_SSD1815 158#if CONFIG_LCD == LCD_SSD1815
130#define ASPECT 320 /* = 1.25 (fixed point 24.8) */ 159#define ASPECT 320 /* = 1.25 (fixed point 24.8) */
131#else 160#else
132#define ASPECT 256 /* = 1.00 */ 161#define ASPECT 256 /* = 1.00 */
133#endif 162#endif
163
134#else /* !LCD_BITMAP */ 164#else /* !LCD_BITMAP */
165
135#define MYLCD(fn) pgfx_ ## fn 166#define MYLCD(fn) pgfx_ ## fn
136#define DIST 9 167#define DIST 9
137static int x_off = 10; 168static int x_off = 10;
138static int y_off = 7; 169static int y_off = 7;
139#define ASPECT 300 /* = 1.175 */ 170#define ASPECT 300 /* = 1.175 */
171
140#endif /* !LCD_BITMAP */ 172#endif /* !LCD_BITMAP */
141 173
142struct point_3D { 174struct point_3D {
@@ -191,21 +223,24 @@ static const struct face faces[6] =
191 {{1, 5, 6, 2}, {9, 6, 10, 1}} 223 {{1, 5, 6, 2}, {9, 6, 10, 1}}
192}; 224};
193 225
194#if LCD_DEPTH > 1 226#if LCD_DEPTH > 1 || defined(USE_GSLIB)
195static const unsigned face_colors[6] = 227static const unsigned face_colors[6] =
196{ 228{
197#ifdef HAVE_LCD_COLOR 229#ifdef HAVE_LCD_COLOR
198 LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 255, 0), 230 LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 255, 0),
199 LCD_RGBPACK(0, 255, 0), LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(0, 0, 255) 231 LCD_RGBPACK(0, 255, 0), LCD_RGBPACK(0, 0, 255), LCD_RGBPACK(0, 0, 255)
232#elif defined(USE_GSLIB)
233 GRAY_LIGHTGRAY, GRAY_LIGHTGRAY, GRAY_DARKGRAY,
234 GRAY_DARKGRAY, GRAY_BLACK, GRAY_BLACK
200#else 235#else
201 LCD_LIGHTGRAY, LCD_LIGHTGRAY, LCD_DARKGRAY, 236 LCD_LIGHTGRAY, LCD_LIGHTGRAY, LCD_DARKGRAY,
202 LCD_DARKGRAY, LCD_BLACK, LCD_BLACK 237 LCD_DARKGRAY, LCD_BLACK, LCD_BLACK
203#endif 238#endif
204}; 239};
205#endif 240#endif
206 241
207enum { 242enum {
208#if LCD_DEPTH > 1 243#if LCD_DEPTH > 1 || defined(USE_GSLIB)
209 SOLID, 244 SOLID,
210#endif 245#endif
211 HIDDEN_LINES, 246 HIDDEN_LINES,
@@ -369,7 +404,7 @@ static void cube_draw(void)
369 404
370 switch (mode) 405 switch (mode)
371 { 406 {
372#if LCD_DEPTH > 1 407#if LCD_DEPTH > 1 || defined(USE_GSLIB)
373 case SOLID: 408 case SOLID:
374 409
375 for (i = 0; i < 6; i++) 410 for (i = 0; i < 6; i++)
@@ -383,24 +418,24 @@ static void cube_draw(void)
383 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x)) 418 * (point2D[faces[i].corner[2]].x - point2D[faces[i].corner[1]].x))
384 continue; 419 continue;
385 420
386 rb->lcd_set_foreground(face_colors[i]); 421 MY_SET_FOREGROUND(face_colors[i]);
387 xlcd_filltriangle(point2D[faces[i].corner[0]].x, 422 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
388 point2D[faces[i].corner[0]].y, 423 point2D[faces[i].corner[0]].y,
389 point2D[faces[i].corner[1]].x, 424 point2D[faces[i].corner[1]].x,
390 point2D[faces[i].corner[1]].y, 425 point2D[faces[i].corner[1]].y,
391 point2D[faces[i].corner[2]].x, 426 point2D[faces[i].corner[2]].x,
392 point2D[faces[i].corner[2]].y); 427 point2D[faces[i].corner[2]].y);
393 xlcd_filltriangle(point2D[faces[i].corner[0]].x, 428 MY_FILLTRIANGLE(point2D[faces[i].corner[0]].x,
394 point2D[faces[i].corner[0]].y, 429 point2D[faces[i].corner[0]].y,
395 point2D[faces[i].corner[2]].x, 430 point2D[faces[i].corner[2]].x,
396 point2D[faces[i].corner[2]].y, 431 point2D[faces[i].corner[2]].y,
397 point2D[faces[i].corner[3]].x, 432 point2D[faces[i].corner[3]].x,
398 point2D[faces[i].corner[3]].y); 433 point2D[faces[i].corner[3]].y);
399 434
400 } 435 }
401 rb->lcd_set_foreground(LCD_BLACK); 436 MY_SET_FOREGROUND(MY_BLACK);
402 break; 437 break;
403#endif /* LCD_DEPTH > 1 */ 438#endif /* (LCD_DEPTH > 1) || GSLIB */
404 439
405 case HIDDEN_LINES: 440 case HIDDEN_LINES:
406 441
@@ -442,11 +477,15 @@ static void cube_draw(void)
442 } 477 }
443} 478}
444 479
445
446enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 480enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
447{ 481{
448 char buffer[30]; 482 char buffer[30];
449 int t_disp = 0; 483 int t_disp = 0;
484#ifdef USE_GSLIB
485 unsigned char *gbuf;
486 unsigned int gbuf_size = 0;
487 bool mode_switch = true;
488#endif
450 489
451 int button; 490 int button;
452 int lastbutton = BUTTON_NONE; 491 int lastbutton = BUTTON_NONE;
@@ -467,9 +506,24 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
467#ifdef HAVE_LCD_BITMAP 506#ifdef HAVE_LCD_BITMAP
468#if LCD_DEPTH > 1 507#if LCD_DEPTH > 1
469 xlcd_init(rb); 508 xlcd_init(rb);
509#elif defined(USE_GSLIB)
510 gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);
511 if (gray_init(rb, gbuf, gbuf_size, true, LCD_WIDTH, LCD_HEIGHT/8, 3, NULL)
512 != 3)
513 {
514 rb->splash(HZ, true, "Couldn't get grayscale buffer");
515 return PLUGIN_ERROR;
516 }
517 /* init lcd_ function pointers */
518 lcdfuncs.update = rb->lcd_update;
519 lcdfuncs.clear_display = rb->lcd_clear_display;
520 lcdfuncs.drawline = rb->lcd_drawline;
521 lcdfuncs.putsxy = rb->lcd_putsxy;
522
523 gray_setfont(FONT_SYSFIXED);
470#endif 524#endif
471 rb->lcd_setfont(FONT_SYSFIXED); 525 rb->lcd_setfont(FONT_SYSFIXED);
472#else 526#else /* LCD_CHARCELLS */
473 if (!pgfx_init(rb, 4, 2)) 527 if (!pgfx_init(rb, 4, 2))
474 { 528 {
475 rb->splash(HZ*2, true, "Old LCD :("); 529 rb->splash(HZ*2, true, "Old LCD :(");
@@ -500,7 +554,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
500 t_disp--; 554 t_disp--;
501 rb->snprintf(buffer, sizeof(buffer), "x:%d y:%d z:%d h:%d", 555 rb->snprintf(buffer, sizeof(buffer), "x:%d y:%d z:%d h:%d",
502 xs, ys, zs, highspeed); 556 xs, ys, zs, highspeed);
503 rb->lcd_putsxy(0, LCD_HEIGHT-8, buffer); 557 MYLCD(putsxy)(0, LCD_HEIGHT-8, buffer);
504 if (t_disp == 0) 558 if (t_disp == 0)
505 redraw = true; 559 redraw = true;
506 } 560 }
@@ -527,6 +581,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
527 } 581 }
528 } 582 }
529#endif 583#endif
584#ifdef USE_GSLIB
585 if (mode_switch)
586 {
587 gray_show(mode == SOLID);
588 mode_switch = false;
589 }
590#endif
530 MYLCD(update)(); 591 MYLCD(update)();
531 592
532 if (!paused) 593 if (!paused)
@@ -663,6 +724,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
663#endif 724#endif
664 if (++mode >= NUM_MODES) 725 if (++mode >= NUM_MODES)
665 mode = 0; 726 mode = 0;
727#ifdef USE_GSLIB
728 mylcd = (mode == SOLID) ? &grayfuncs : &lcdfuncs;
729 mode_switch = true;
730#endif
666 redraw = true; 731 redraw = true;
667 break; 732 break;
668 733
@@ -692,6 +757,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
692 { 757 {
693#ifdef HAVE_LCD_CHARCELLS 758#ifdef HAVE_LCD_CHARCELLS
694 pgfx_release(); 759 pgfx_release();
760#elif defined(USE_GSLIB)
761 gray_release();
695#endif 762#endif
696 return PLUGIN_USB_CONNECTED; 763 return PLUGIN_USB_CONNECTED;
697 } 764 }
@@ -703,6 +770,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
703 770
704#ifdef HAVE_LCD_CHARCELLS 771#ifdef HAVE_LCD_CHARCELLS
705 pgfx_release(); 772 pgfx_release();
773#elif defined(USE_GSLIB)
774 gray_release();
706#endif 775#endif
707 776
708 return PLUGIN_OK; 777 return PLUGIN_OK;