From ebe5acfb9dd80bfce2c915a568e2c86244b67510 Mon Sep 17 00:00:00 2001 From: Kevin Ferrare Date: Wed, 23 Jan 2008 08:25:04 +0000 Subject: [PATCH] Fixed the problems on the new version of the fire plugin (so repush it), added new actions to the pluginlib_actions to fix the keymaps on the Sansa e200 for the clock and fire plugins. Also slightly simplified the metronome plugin's key mapping with those new actions. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16148 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/clock/clock.c | 13 +- apps/plugins/fire.c | 468 +++++++++++---------------- apps/plugins/lib/fixedpoint.h | 8 + apps/plugins/lib/pluginlib_actions.c | 48 +++ apps/plugins/lib/pluginlib_actions.h | 8 +- apps/plugins/metronome.c | 27 +- 6 files changed, 265 insertions(+), 307 deletions(-) diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c index f9da5bd09c..d0b8f90847 100644 --- a/apps/plugins/clock/clock.c +++ b/apps/plugins/clock/clock.c @@ -33,13 +33,14 @@ PLUGIN_HEADER /* Keymaps */ const struct button_mapping* plugin_contexts[]={ generic_actions, + generic_increase_decrease, generic_directions, #if NB_SCREENS == 2 remote_directions #endif }; +#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) -#define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) #define ACTION_COUNTER_TOGGLE PLA_FIRE #define ACTION_COUNTER_RESET PLA_FIRE_REPEAT #define ACTION_MENU PLA_MENU @@ -48,10 +49,10 @@ const struct button_mapping* plugin_contexts[]={ #define ACTION_MODE_NEXT_REPEAT PLA_RIGHT_REPEAT #define ACTION_MODE_PREV PLA_LEFT #define ACTION_MODE_PREV_REPEAT PLA_LEFT_REPEAT -#define ACTION_SKIN_NEXT PLA_UP -#define ACTION_SKIN_NEXT_REPEAT PLA_UP_REPEAT -#define ACTION_SKIN_PREV PLA_DOWN -#define ACTION_SKIN_PREV_REPEAT PLA_DOWN_REPEAT +#define ACTION_SKIN_NEXT PLA_INC +#define ACTION_SKIN_NEXT_REPEAT PLA_INC_REPEAT +#define ACTION_SKIN_PREV PLA_DEC +#define ACTION_SKIN_PREV_REPEAT PLA_DEC_REPEAT extern struct plugin_api* rb; @@ -139,7 +140,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ /************************* * Scan for button presses ************************/ - button = pluginlib_getaction(rb, HZ/10, plugin_contexts, NB_ACTION_CONTEXTS); + button = pluginlib_getaction(rb, HZ/10, plugin_contexts, PLA_ARRAY_COUNT); redraw=true;/* we'll set it to false afterwards if there was no action */ switch (button){ case ACTION_COUNTER_TOGGLE: /* start/stop counter */ diff --git a/apps/plugins/fire.c b/apps/plugins/fire.c index ed3509c168..7b03e12441 100644 --- a/apps/plugins/fire.c +++ b/apps/plugins/fire.c @@ -21,8 +21,11 @@ #include "plugin.h" #include "helper.h" +#ifdef HAVE_LCD_BITMAP + +#include "pluginlib_actions.h" +#include "fixedpoint.h" -#ifdef HAVE_LCD_BITMAP /* and also not for the Player */ #ifndef HAVE_LCD_COLOR #include "grey.h" #endif @@ -38,191 +41,82 @@ PLUGIN_HEADER -/******************************* Globals ***********************************/ - static struct plugin_api* rb; /* global api struct pointer */ -static unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH]; -static unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH]; - #ifndef HAVE_LCD_COLOR GREY_INFO_STRUCT -static unsigned char *gbuf; -static size_t gbuf_size = 0; -static unsigned char draw_buffer[FIRE_WIDTH]; + static unsigned char draw_buffer[FIRE_WIDTH]; + #endif /* Key assignement */ - -#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) -#define FIRE_QUIT BUTTON_OFF -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MODE -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_REC -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#define FIRE_RC_QUIT BUTTON_RC_STOP - -#elif CONFIG_KEYPAD == RECORDER_PAD -#define FIRE_QUIT BUTTON_OFF -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_ON -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_PLAY -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD -#define FIRE_QUIT BUTTON_OFF -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_ON -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_SELECT -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif CONFIG_KEYPAD == ONDIO_PAD -#define FIRE_QUIT BUTTON_OFF -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MENU -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ - (CONFIG_KEYPAD == IPOD_1G2G_PAD) -#define FIRE_QUIT BUTTON_MENU -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_SELECT -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_SCROLL_FWD -#define FIRE_DECREASE_MULT BUTTON_SCROLL_BACK - -#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) -#define FIRE_QUIT BUTTON_POWER -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif (CONFIG_KEYPAD == GIGABEAT_PAD) -#define FIRE_QUIT BUTTON_POWER -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ -(CONFIG_KEYPAD == SANSA_C200_PAD) -#define FIRE_QUIT BUTTON_POWER -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - -#elif (CONFIG_KEYPAD == IRIVER_H10_PAD) -#define FIRE_QUIT BUTTON_POWER -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_LEFT -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_RIGHT -#define FIRE_INCREASE_MULT BUTTON_SCROLL_UP -#define FIRE_DECREASE_MULT BUTTON_SCROLL_DOWN - -#elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) -#define FIRE_QUIT BUTTON_PLAY -#define FIRE_SWITCH_FLAMES_TYPE BUTTON_MODE -#define FIRE_SWITCH_FLAMES_MOVING BUTTON_EQ -#define FIRE_INCREASE_MULT BUTTON_UP -#define FIRE_DECREASE_MULT BUTTON_DOWN - +const struct button_mapping* plugin_contexts[]= { + generic_increase_decrease, + generic_directions, +#if defined(HAVE_REMOTE_LCD) + remote_directions, #endif + generic_actions +}; +#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) + +#define FIRE_QUIT PLA_QUIT +#define FIRE_SWITCH_FLAMES_TYPE PLA_LEFT +#define FIRE_SWITCH_FLAMES_MOVING PLA_RIGHT +#define FIRE_INCREASE_MULT PLA_INC +#define FIRE_DECREASE_MULT PLA_DEC #define MIN_FLAME_VALUE 0 #define COOL_MAX (440/LCD_HEIGHT+2) -/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit, - * whichever is faster for the architecture) */ -#ifdef CPU_ARM -#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b)))) -#else /* SH1, coldfire */ -#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b)))) -#endif - #ifndef HAVE_LCD_COLOR -static const unsigned char palette[256] = { - 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, 19, 21, 22, - 24, 25, 27, 28, 30, 31, 33, 34, 36, 37, 39, 40, 42, 43, 45, 46, - 48, 49, 51, 52, 54, 55, 57, 59, 60, 61, 63, 64, 66, 67, 69, 70, - 72, 73, 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91, 93, 94, - 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 117, 118, - 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 141, 142, - 144, 145, 147, 148, 150, 151, 153, 154, 156, 157, 159, 160, 162, 163, 165, 166, - 168, 169, 171, 172, 174, 175, 177, 178, 180, 181, 183, 184, 186, 187, 189, 190, - 192, 193, 195, 196, 198, 199, 201, 202, 204, 205, 207, 208, 210, 211, 213, 214, - 216, 217, 219, 220, 222, 223, 225, 226, 228, 229, 231, 232, 234, 235, 237, 238, - /* 'regular' fire doesn't exceed this value */ - 240, 240, 240, 240, 240, 240, 241, 241, 241, 241, 241, 241, 242, 242, 242, 242, - 242, 242, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 245, 245, - 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 247, 247, 247, 247, 247, 247, - 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 249, 250, 250, 250, 250, - 250, 250, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252, 252, 252, 253, 253, - 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255 -}; -#else -#define L(r,g,b) LCD_RGBPACK(r,g,b) +static unsigned char palette[256]; + +void color_palette_init(unsigned char* palette) +{ + int i; + for(i=0;i<=160;i++)//palette[i]=(3/2)*i + palette[i]=(i*3)/2; -static const fb_data colorpalette[256] = { - L( 0, 0, 0), L( 5, 0, 0), L( 10, 0, 0), L( 15, 0, 0), L( 20, 0, 0), - L( 25, 0, 0), L( 30, 0, 0), L( 35, 0, 0), L( 40, 0, 0), L( 45, 0, 0), - L( 50, 0, 0), L( 55, 0, 0), L( 60, 0, 0), L( 65, 0, 0), L( 70, 0, 0), - L( 75, 0, 0), L( 80, 0, 0), L( 85, 0, 0), L( 90, 0, 0), L( 95, 0, 0), - L(100, 0, 0), L(105, 0, 0), L(110, 0, 0), L(115, 0, 0), L(120, 0, 0), - L(125, 0, 0), L(130, 0, 0), L(135, 0, 0), L(140, 0, 0), L(145, 0, 0), - L(150, 0, 0), L(155, 0, 0), L(160, 0, 0), L(165, 0, 0), L(170, 0, 0), - L(175, 0, 0), L(180, 0, 0), L(185, 0, 0), L(186, 2, 0), L(187, 5, 1), - L(188, 6, 2), L(189, 8, 3), L(190, 10, 4), L(191, 12, 4), L(192, 14, 5), - L(193, 15, 6), L(194, 17, 7), L(195, 19, 8), L(196, 21, 8), L(197, 22, 9), - L(198, 24, 10), L(198, 26, 10), L(199, 28, 10), L(200, 29, 11), L(201, 32, 11), - L(202, 34, 12), L(203, 36, 13), L(204, 39, 13), L(205, 40, 14), L(206, 42, 14), - L(207, 43, 15), L(208, 46, 16), L(208, 48, 17), L(209, 50, 18), L(210, 51, 18), - L(212, 53, 19), L(213, 55, 20), L(214, 57, 21), L(215, 59, 22), L(216, 61, 22), - L(217, 63, 23), L(217, 65, 24), L(218, 67, 24), L(219, 69, 25), L(220, 70, 25), - L(222, 72, 26), L(223, 74, 27), L(224, 76, 28), L(225, 78, 28), L(225, 80, 29), - L(226, 82, 29), L(227, 84, 30), L(228, 86, 31), L(228, 88, 32), L(229, 90, 32), - L(230, 92, 32), L(231, 94, 33), L(232, 96, 34), L(233, 98, 35), L(234, 99, 36), - L(235,101, 37), L(236,103, 37), L(237,105, 38), L(238,107, 39), L(240,109, 39), - L(240,111, 40), L(241,113, 40), L(242,114, 41), L(242,116, 42), L(243,119, 43), - L(245,120, 43), L(246,122, 44), L(247,124, 44), L(248,126, 46), L(248,128, 47), - L(249,130, 47), L(251,131, 47), L(252,133, 48), L(253,135, 49), L(253,138, 49), - L(253,140, 50), L(254,143, 49), L(254,145, 48), L(253,148, 47), L(253,151, 46), - L(253,154, 45), L(253,156, 44), L(253,158, 44), L(252,162, 42), L(252,165, 41), - L(252,167, 41), L(252,170, 40), L(251,173, 40), L(252,175, 38), L(252,178, 37), - L(251,181, 37), L(251,183, 36), L(251,186, 35), L(250,189, 34), L(250,192, 33), - L(250,194, 33), L(249,198, 31), L(249,200, 31), L(249,203, 30), L(249,206, 29), - L(249,209, 28), L(249,211, 27), L(249,214, 26), L(248,216, 25), L(248,219, 25), - L(248,222, 24), L(248,224, 23), L(248,227, 22), L(248,230, 21), L(248,232, 21), - L(247,236, 19), L(247,238, 23), L(247,239, 31), L(247,239, 45), L(247,240, 55), - L(248,240, 68), L(247,241, 78), L(248,241, 90), L(247,242,102), L(248,242,114), - L(247,243,125), L(248,243,138), L(248,243,153), L(248,244,162), L(248,245,174), /* 'regular' fire doesn't exceed this value */ - L(247,245,182), L(247,245,182), L(247,245,183), L(247,245,183), L(247,245,184), - L(247,245,184), L(247,245,185), L(247,245,185), L(247,245,186), L(247,245,186), - L(247,245,187), L(247,245,187), L(247,245,188), L(247,245,188), L(247,245,189), - L(247,245,189), L(248,245,190), L(248,245,190), L(248,245,191), L(248,245,191), - L(248,245,192), L(248,245,192), L(248,245,193), L(248,245,193), L(248,245,194), - L(248,245,194), L(248,245,195), L(248,245,195), L(248,245,196), L(248,245,196), - L(248,245,197), L(248,245,197), L(248,245,198), L(248,245,198), L(248,245,199), - L(248,245,199), L(248,245,200), L(248,245,200), L(248,245,201), L(248,245,201), - L(248,245,202), L(248,245,202), L(248,245,203), L(248,245,203), L(248,245,204), - L(248,245,204), L(248,245,205), L(248,245,205), L(248,246,206), L(248,246,206), - L(248,246,207), L(248,246,207), L(248,246,208), L(248,246,208), L(248,246,209), - L(248,246,209), L(248,246,210), L(248,246,210), L(248,246,211), L(248,246,211), - L(248,246,212), L(248,246,212), L(248,246,213), L(248,246,213), L(248,246,214), - L(248,246,214), L(248,246,215), L(248,246,215), L(248,246,216), L(248,246,216), - L(248,246,217), L(248,246,217), L(248,246,218), L(248,246,218), L(248,246,219), - L(248,246,219), L(248,246,220), L(248,246,220), L(248,246,221), L(248,246,221), - L(248,246,222), L(248,246,222), L(248,246,223), L(248,246,223), L(248,246,224), - L(248,246,224), L(248,246,225), L(248,246,225), L(248,246,226), L(248,246,226), - L(248,246,227), L(248,246,227), L(248,246,228), L(248,246,228), L(248,246,229), - L(248,246,229) -}; + for(;i<=255;i++)//palette[i]=(3/20)*i+216 + palette[i]=(i*3+20*217)/20; +} +#else + +static fb_data palette[256]; + +/* + * Color palette generation algorithm taken from + * the "The Demo Effects Collection" GPL project + * Copyright (C) 2002 W.P. van Paassen + */ +void color_palette_init(fb_data* palette) +{ + int i; + for (i = 0; i < 32; i++){ + /* black to blue, 32 values*/ + palette[i]=LCD_RGBPACK(0, 0, 2*i); + + /* blue to red, 32 values*/ + palette[i + 32]=LCD_RGBPACK(8*i, 0, 64 - 2*i); + + /* red to yellow, 32 values*/ + palette[i + 64]=LCD_RGBPACK(255, 8*i, 0); + + /* yellow to white, 162 values */ + palette[i + 96]=LCD_RGBPACK(255, 255, 0 + 4*i); + palette[i + 128]=LCD_RGBPACK(255, 255, 64 + 4*i); + palette[i + 160]=LCD_RGBPACK(255, 255, 128 + 4*i); + palette[i + 192]=LCD_RGBPACK(255, 255, 192 + i); + palette[i + 224]=LCD_RGBPACK(255, 255, 224 + i); + } +} + #endif -static inline void tab_init_rand(unsigned char *tab, unsigned int tab_size, - int rand_max) +static void tab_init_rand(unsigned char *tab, unsigned int tab_size, + int rand_max) { unsigned char *end = tab + tab_size; @@ -230,114 +124,133 @@ static inline void tab_init_rand(unsigned char *tab, unsigned int tab_size, *tab++ = (unsigned char)rb->rand() % rand_max; } -static inline void fire_generate(int mult, int flames_type, bool moving) +struct fire { + unsigned char fire[LCD_HEIGHT+3][FIRE_WIDTH]; + unsigned char cooling_map[LCD_HEIGHT][FIRE_WIDTH]; + int flames_type; + bool moving; + unsigned int mult; +}; +/* makes the instance a global variable since it's too big to fit on the target's stack */ +static struct fire fire; + +static inline void fire_convolve(struct fire* fire) { - unsigned int pixel_value = 0; /* stop the compiler complaining */ + unsigned int pixel_value; unsigned int cooling_value; unsigned char *ptr, *end, *cool; + unsigned int mult=fire->mult; - /* Randomize the bottom line */ - if(moving) - {/* moving must be true the first time the function is called */ - ptr = &fire[LCD_HEIGHT][0]; - end = ptr + FIRE_WIDTH; - - do - { - *ptr++ = (MIN_FLAME_VALUE + rb->rand() % (256-MIN_FLAME_VALUE)); - } - while (ptr < end); - } rb->yield(); - /* Convolve the pixels and handle cooling (to add nice shapes effects later) */ - cool = &cooling_map[0][0]; - ptr = &fire[0][0]; + cool = &fire->cooling_map[0][0]; + ptr = &fire->fire[0][0]; end = ptr + LCD_HEIGHT*FIRE_WIDTH; - switch (flames_type) - { - case 0: - do - { - pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ + switch (fire->flames_type){ + case 0: + do{ + pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ + ptr[2*FIRE_WIDTH] /* fire[y+2][x] */ + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */ + ptr[3*FIRE_WIDTH]; /* fire[y+3][x] */ - pixel_value = FMULU(pixel_value, mult) >> 10; + pixel_value = FMULU(pixel_value, mult) >> 10; - cooling_value = *cool++; - if (cooling_value <= pixel_value) - pixel_value -= cooling_value; - /* else it's too cold, don't frost the pixels !!! */ + cooling_value = *cool++; + if (cooling_value <= pixel_value) + pixel_value -= cooling_value; + /* else it's too cold, don't frost the pixels !!! */ - if (pixel_value > 255) - pixel_value = 255; + if (pixel_value > 255) + pixel_value = 255; - *ptr++ = pixel_value; - } - while (ptr < end); - break; + *ptr++ = pixel_value; + }while (ptr < end); + break; - case 1: - mult -= 2; - do - { - pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ + case 1: + mult -= 2; + do{ + pixel_value = ptr[FIRE_WIDTH-1] /* fire[y+1][x-1] */ + ptr[FIRE_WIDTH] /* fire[y+1][x] */ + ptr[FIRE_WIDTH+1] /* fire[y+1][x+1] */ + ptr[2*FIRE_WIDTH]; /* fire[y+2][x] */ - pixel_value = FMULU(pixel_value, mult) >> 10; + pixel_value = FMULU(pixel_value, mult) >> 10; - cooling_value = *cool++; - if (cooling_value <= pixel_value) - pixel_value -= cooling_value; - /* else it's too cold, don't frost the pixels !!! */ + cooling_value = *cool++; + if (cooling_value <= pixel_value) + pixel_value -= cooling_value; + /* else it's too cold, don't frost the pixels !!! */ - if (pixel_value > 255) - pixel_value = 255; + if (pixel_value > 255) + pixel_value = 255; - *ptr++ = pixel_value; - } - while (ptr < end); - break; + *ptr++ = pixel_value; + }while (ptr < end); + break; - default: /* We should never reach this */ - break; + default: /* We should never reach this */ + break; } rb->yield(); } -static inline void fire_draw(void) +static void fire_generate_bottom_seed(struct fire* fire) +{ + unsigned char *ptr, *end; + ptr = &fire->fire[LCD_HEIGHT][0]; + end = ptr + FIRE_WIDTH; + do{ + *ptr++ = (MIN_FLAME_VALUE + rb->rand() % (256-MIN_FLAME_VALUE)); + }while (ptr < end); +} + +static inline void fire_step(struct fire* fire) +{ + if(fire->moving){ + /* Randomize the bottom line */ + fire_generate_bottom_seed(fire); + /* Add here further effects like fire letters, ball ... */ + } + fire_convolve(fire); +} + +static void fire_init(struct fire* fire) +{ + fire->mult = 261; + fire->flames_type=0; + fire->moving=true; + rb->memset(&fire->fire[0][0], 0, sizeof(fire->fire)); + tab_init_rand(&fire->cooling_map[0][0], LCD_HEIGHT*FIRE_WIDTH, COOL_MAX); + fire_generate_bottom_seed(fire); +} + +static inline void fire_draw(struct fire* fire) { int y; - unsigned char *src = &fire[0][0]; + unsigned char *src = &fire->fire[0][0]; #ifndef HAVE_LCD_COLOR unsigned char *dest, *end; +#else + fb_data *dest, *end; +#endif - for (y = 0; y < LCD_HEIGHT; y++) - { + for (y = 0; y < LCD_HEIGHT; y++){ +#ifndef HAVE_LCD_COLOR dest = draw_buffer; +#else + dest = rb->lcd_framebuffer + LCD_WIDTH * y + FIRE_XPOS; +#endif end = dest + FIRE_WIDTH; do *dest++ = palette[*src++]; while (dest < end); - +#ifndef HAVE_LCD_COLOR grey_ub_gray_bitmap(draw_buffer, 0, y, FIRE_WIDTH, 1); +#endif } -#else - fb_data *dest, *end; - - for (y = 0; y < LCD_HEIGHT; y++) - { - dest = rb->lcd_framebuffer + LCD_WIDTH * y + FIRE_XPOS; - end = dest + FIRE_WIDTH; - - do - *dest++ = colorpalette[*src++]; - while (dest < end); - } +#ifdef HAVE_LCD_COLOR rb->lcd_update(); #endif } @@ -345,7 +258,6 @@ static inline void fire_draw(void) void cleanup(void *parameter) { (void)parameter; - #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); #endif @@ -356,77 +268,75 @@ void cleanup(void *parameter) backlight_use_settings(rb); /* backlight control in lib/helper.c */ } -/* - * Main function that also contain the main plasma - * algorithm. - */ - -int main(void) -{ - int button; - int mult = 261; - int flames_type=0; - bool moving=true; #ifndef HAVE_LCD_COLOR +int init_grey(void) +{ + unsigned char *gbuf; + size_t gbuf_size = 0; + /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); - if (!grey_init(rb, gbuf, gbuf_size, false, FIRE_WIDTH, LCD_HEIGHT, NULL)) - { + if (!grey_init(rb, gbuf, gbuf_size, false, FIRE_WIDTH, LCD_HEIGHT, NULL)){ rb->splash(HZ, "not enough memory"); return PLUGIN_ERROR; } /* switch on greyscale overlay */ grey_set_position(FIRE_XPOS, 0); grey_show(true); + return PLUGIN_OK; +} #endif +int main(void) +{ + int action; + +#ifndef HAVE_LCD_COLOR + if(init_grey()!=PLUGIN_OK) + return(PLUGIN_ERROR); +#endif + color_palette_init(palette); + #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(true); #endif - rb->memset(&fire[0][0], 0, sizeof(fire)); - tab_init_rand(&cooling_map[0][0], LCD_HEIGHT*FIRE_WIDTH, COOL_MAX); - while (true) - { - fire_generate(mult, flames_type, moving); - fire_draw(); + + fire_init(&fire); + while (true){ + fire_step(&fire); + fire_draw(&fire); rb->yield(); - button = rb->button_get(false); + action = pluginlib_getaction(rb, 0, plugin_contexts, PLA_ARRAY_COUNT); - switch(button) - { -#ifdef FIRE_RC_QUIT - case FIRE_RC_QUIT : -#endif - case (FIRE_QUIT): + switch(action){ + case FIRE_QUIT: cleanup(NULL); return PLUGIN_OK; + + case FIRE_INCREASE_MULT: + ++fire.mult; break; - case (FIRE_INCREASE_MULT): - ++mult; + case FIRE_DECREASE_MULT: + if (fire.mult > 0) + --fire.mult; break; - case (FIRE_DECREASE_MULT): - if (mult > 0) - --mult; + case FIRE_SWITCH_FLAMES_TYPE: + fire.flames_type = (fire.flames_type + 1) % 2; break; - case (FIRE_SWITCH_FLAMES_TYPE): - flames_type = (flames_type + 1) % 2; - break; - - case (FIRE_SWITCH_FLAMES_MOVING): - moving = !moving; + case FIRE_SWITCH_FLAMES_MOVING: + fire.moving = !fire.moving; break; default: - if (rb->default_event_handler_ex(button, cleanup, NULL) + if (rb->default_event_handler_ex(action, cleanup, NULL) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; - break; } } } @@ -437,7 +347,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { int ret; - rb = api; // copy to global api pointer + rb = api; //copy to global api pointer (void)parameter; #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); diff --git a/apps/plugins/lib/fixedpoint.h b/apps/plugins/lib/fixedpoint.h index 719915709a..a9650e7977 100644 --- a/apps/plugins/lib/fixedpoint.h +++ b/apps/plugins/lib/fixedpoint.h @@ -24,3 +24,11 @@ long fsqrt(long a, unsigned int fracbits); long cos_int(int val); long sin_int(int val); long flog(int x); + +/* fast unsigned multiplication (16x16bit->32bit or 32x32bit->32bit, + * whichever is faster for the architecture) */ +#ifdef CPU_ARM +#define FMULU(a, b) ((uint32_t) (((uint32_t) (a)) * ((uint32_t) (b)))) +#else /* SH1, coldfire */ +#define FMULU(a, b) ((uint32_t) (((uint16_t) (a)) * ((uint16_t) (b)))) +#endif diff --git a/apps/plugins/lib/pluginlib_actions.c b/apps/plugins/lib/pluginlib_actions.c index e74ffc0315..f358bb59f6 100644 --- a/apps/plugins/lib/pluginlib_actions.c +++ b/apps/plugins/lib/pluginlib_actions.c @@ -335,6 +335,54 @@ const struct button_mapping generic_actions[] = {CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE} }; +const struct button_mapping generic_increase_decrease[] = +{ +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) \ + || (CONFIG_KEYPAD == IRIVER_H300_PAD) \ + || (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) \ + || (CONFIG_KEYPAD == GIGABEAT_PAD) \ + || (CONFIG_KEYPAD == RECORDER_PAD) \ + || (CONFIG_KEYPAD == ARCHOS_AV300_PAD) \ + || (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) \ + || (CONFIG_KEYPAD == ONDIO_PAD) \ + || (CONFIG_KEYPAD == COWOND2_PAD) + {PLA_INC, BUTTON_UP, BUTTON_NONE}, + {PLA_DEC, BUTTON_DOWN, BUTTON_NONE}, + {PLA_INC_REPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DEC_REPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == SANSA_C200_PAD) + {PLA_INC, BUTTON_VOL_UP, BUTTON_NONE}, + {PLA_DEC, BUTTON_VOL_DOWN, BUTTON_NONE}, + {PLA_INC_REPEAT, BUTTON_VOL_UP|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DEC_REPEAT, BUTTON_VOL_DOWN|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ + || (CONFIG_KEYPAD == IPOD_3G_PAD) \ + || (CONFIG_KEYPAD == SANSA_E200_PAD) \ + || (CONFIG_KEYPAD == IPOD_4G_PAD) + {PLA_INC, BUTTON_SCROLL_FWD, BUTTON_NONE}, + {PLA_DEC, BUTTON_SCROLL_BACK, BUTTON_NONE}, + {PLA_INC_REPEAT, BUTTON_SCROLL_FWD|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DEC_REPEAT, BUTTON_SCROLL_BACK|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == PLAYER_PAD + {PLA_INC, BUTTON_STOP, BUTTON_NONE}, + {PLA_DEC, BUTTON_PLAY, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == IRIVER_H10_PAD) \ + || (CONFIG_KEYPAD == MROBE100_PAD) + {PLA_INC, BUTTON_SCROLL_UP, BUTTON_NONE}, + {PLA_DEC, BUTTON_SCROLL_DOWN, BUTTON_NONE}, + {PLA_INC_REPEAT, BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DEC_REPEAT, BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == MROBE500_PAD) + {PLA_INC, BUTTON_RC_PLAY, BUTTON_NONE}, + {PLA_DEC, BUTTON_RC_DOWN, BUTTON_NONE}, + {PLA_INC_REPEAT, BUTTON_RC_PLAY|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DEC_REPEAT, BUTTON_RC_DOWN|BUTTON_REPEAT, BUTTON_NONE}, +#else +#error pluginlib_actions: Unsupported keypad +#endif + {CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE} +}; + static struct button_mapping **plugin_context_order; static int plugin_context_count = 0; static int last_context = 0; /* index into plugin_context_order diff --git a/apps/plugins/lib/pluginlib_actions.h b/apps/plugins/lib/pluginlib_actions.h index b0b9871de8..c11a087904 100644 --- a/apps/plugins/lib/pluginlib_actions.h +++ b/apps/plugins/lib/pluginlib_actions.h @@ -35,7 +35,12 @@ enum { PLA_DOWN_REPEAT, PLA_LEFT_REPEAT, PLA_RIGHT_REPEAT, - + + PLA_INC, + PLA_DEC, + PLA_INC_REPEAT, + PLA_DEC_REPEAT, + PLA_QUIT, PLA_START, PLA_MENU, @@ -51,6 +56,7 @@ extern const struct button_mapping remote_directions[]; extern const struct button_mapping generic_directions[]; extern const struct button_mapping generic_left_right_fire[]; extern const struct button_mapping generic_actions[]; +extern const struct button_mapping generic_increase_decrease[]; int pluginlib_getaction(struct plugin_api *api,int timeout, const struct button_mapping *plugin_contexts[], diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index 4b345df460..402f4ac3fc 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -21,20 +21,10 @@ PLUGIN_HEADER #define METRONOME_QUIT PLA_QUIT - -/* for volume changes, PLA with scrollwheel isn't proper */ - -#ifdef HAVE_SCROLLWHEEL -#define METRONOME_VOL_UP PLA_DOWN -#define METRONOME_VOL_DOWN PLA_UP -#define METRONOME_VOL_UP_REP PLA_DOWN_REPEAT -#define METRONOME_VOL_DOWN_REP PLA_UP_REPEAT -#else -#define METRONOME_VOL_UP PLA_UP -#define METRONOME_VOL_DOWN PLA_DOWN -#define METRONOME_VOL_UP_REP PLA_UP_REPEAT -#define METRONOME_VOL_DOWN_REP PLA_DOWN_REPEAT -#endif +#define METRONOME_VOL_UP PLA_INC +#define METRONOME_VOL_DOWN PLA_DEC +#define METRONOME_VOL_UP_REP PLA_INC_REPEAT +#define METRONOME_VOL_DOWN_REP PLA_DEC_REPEAT #define METRONOME_LEFT PLA_LEFT #define METRONOME_RIGHT PLA_RIGHT #define METRONOME_LEFT_REP PLA_LEFT_REPEAT @@ -77,6 +67,7 @@ static const struct button_mapping iriver_syncaction[] = #endif /* #if CONFIG_KEYPAD == ONDIO_PAD */ const struct button_mapping *plugin_contexts[]={ + generic_increase_decrease, generic_directions, #if CONFIG_KEYPAD == ONDIO_PAD ondio_action, @@ -85,6 +76,7 @@ const struct button_mapping *plugin_contexts[]={ #endif generic_actions }; +#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) static struct plugin_api* rb; @@ -308,13 +300,6 @@ void tap(void) enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ int button; -#if (CONFIG_KEYPAD == ONDIO_PAD) \ - || (CONFIG_KEYPAD == IRIVER_H100_PAD) \ - || (CONFIG_KEYPAD == IRIVER_H300_PAD) -#define PLA_ARRAY_COUNT 3 -#else -#define PLA_ARRAY_COUNT 2 -#endif enum plugin_status status; (void)parameter;