Index: apps/plugins/CATEGORIES =================================================================== --- apps/plugins/CATEGORIES (Revision 16213) +++ apps/plugins/CATEGORIES (Arbeitskopie) @@ -95,3 +95,4 @@ wormlet,games xobox,games zxbox,viewers +flashlight,apps Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (Revision 16213) +++ apps/plugins/SOURCES (Arbeitskopie) @@ -21,6 +21,9 @@ stopwatch.c vbrfix.c viewer.c +#ifdef HAVE_BACKLIGHT +flashlight.c +#endif /* HAVE_BACKLIGHT */ #ifdef OLYMPUS_MROBE_500 /* remove these once the plugins before it are compileable */ Index: apps/plugins/flashlight.c =================================================================== --- apps/plugins/flashlight.c (revision 0) +++ apps/plugins/flashlight.c (revision 0) @@ -0,0 +1,199 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2007 Vuong Minh Hiep (vmh) + * Copyright (C) 2008 Thomas Martitz (kugel.) + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" +#include "helper.h" + +PLUGIN_HEADER + +/* variable button definitions - only targets with a colour display */ +#if (CONFIG_KEYPAD == IRIVER_H300_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT + +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT +# define FLASHLIGHT_NEXT BUTTON_SCROLL_FWD +# define FLASHLIGHT_PREV BUTTON_SCROLL_BACK + +#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT + +#elif (CONFIG_KEYPAD == GIGABEAT_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT + +#elif (CONFIG_KEYPAD == SANSA_E200_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT +# define FLASHLIGHT_NEXT BUTTON_SCROLL_FWD +# define FLASHLIGHT_PREV BUTTON_SCROLL_BACK + +#elif (CONFIG_KEYPAD == SANSA_C200_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT + +#elif (CONFIG_KEYPAD == IRIVER_H10_PAD) +# define FLASHLIGHT_LEFT BUTTON_LEFT +# define FLASHLIGHT_RIGHT BUTTON_RIGHT +# define FLASHLIGHT_NEXT BUTTON_SCROLL_UP +# define FLASHLIGHT_PREV BUTTON_SCROLL_DOWN + +#else +# warning Missing key definitions for this keypad +#endif + + +static struct plugin_api* rb; /* global api struct pointer */ + +#ifdef HAVE_LCD_COLOR +void HSVToRGB(float hue, float sat, float V, float *R, float *G, float *B) +{ + float r, g, b; + + if (hue > 0.17 && hue <= 0.33) /* green/red */ + { + g = 1.0; + r = ((float)0.33 - hue) / (float)0.16; + b = 0.0; + } else if (hue > 0.33 && hue <= 0.5) /* green/blue */ + { + g = 1.0; + b = (hue - (float)0.33) / (float)0.17; + r = 0.0; + } else if (hue > 0.5 && hue <= 0.67) /* blue/green */ + { + b = 1.0; + g = ((float)0.67 - hue) / (float)0.17; + r = 0.0; + } else if (hue > 0.67 && hue <= 0.83) /* blue/red */ + { + b = 1.0; + r = (hue - (float)0.67) / (float)0.16; + g = 0.0; + } else if (hue > 0.83 && hue <= 1.0) /* red/blue */ + { + r = 1.0; + b = ((float)1.0 - hue) / (float)0.17; + g = 0.0; + } else /* red/green */ + { + r = 1.0; + g = hue / (float)0.17; + b = 0.0; + } + + *R = (sat * r + ((float)1.0 - sat)) * V; + *G = (sat * g + ((float)1.0 - sat)) * V; + *B = (sat * b + ((float)1.0 - sat)) * V; +} +#endif + +/* this is the plugin entry point */ +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) +{ + (void)parameter; + rb = api; + +#ifdef HAVE_LCD_COLOR + int h = 0; + float var_r, var_g, var_b; + bool quit = false; +#endif /* HAVE_LCD_COLOR */ + +#ifdef HAVE_BACKLIGHT_BRIGHTNESS + short old_brightness = rb->global_settings->brightness; +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + +#if LCD_DEPTH > 1 + rb->lcd_set_backdrop(NULL); + unsigned bg_color=rb->lcd_get_background(); + rb->lcd_set_background(LCD_WHITE); +#endif +#ifdef HAVE_BACKLIGHT_BRIGHTNESS + rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING); +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + + backlight_force_on(rb); + + +#ifdef HAVE_LCD_COLOR + do { + if (h != 0) { + HSVToRGB(((float)h/360.0), 1, 1, &var_r, &var_g, &var_b); + rb->lcd_set_background( LCD_RGBPACK( ((int)(var_r * 255)), ((int)(var_g * 255)), ((int)(var_b * 255)) ) ); + } else { /* Whilte screen */ + rb->lcd_set_background(LCD_WHITE); + } + rb->lcd_clear_display(); + rb->lcd_update(); + + switch(rb->button_get(true)) { + case FLASHLIGHT_RIGHT: + case (FLASHLIGHT_RIGHT|BUTTON_REPEAT): + case (FLASHLIGHT_RIGHT|BUTTON_REL): +#ifdef FLASHLIGHT_NEXT + case FLASHLIGHT_NEXT: + case (FLASHLIGHT_NEXT|BUTTON_REPEAT): + case (FLASHLIGHT_NEXT|BUTTON_REL): +#endif /* FLASHLIGHT_NEXT */ + h = (h + 5) % 360; + break; + case FLASHLIGHT_LEFT: + case (FLASHLIGHT_LEFT|BUTTON_REPEAT): + case (FLASHLIGHT_LEFT|BUTTON_REL): +#ifdef FLASHLIGHT_PREV + case FLASHLIGHT_PREV: + case (FLASHLIGHT_PREV|BUTTON_REPEAT): + case (FLASHLIGHT_PREV|BUTTON_REL): +#endif /* FLASHLIGHT_PREV */ + h = (h + 355) % 360; + break; + + default: + quit = true; + } + } while (!quit); + +#else /* HAVE_LCD_COLOR */ + rb->lcd_clear_display(); + rb->lcd_update(); + /* wait */ + while( rb->button_get(false)==BUTTON_NONE ) { + rb->yield(); + } + +#endif /*HAVE_LCD_COLOR */ + + /* restore */ + backlight_use_settings(rb); + +#ifdef HAVE_BACKLIGHT_BRIGHTNESS + rb->backlight_set_brightness(old_brightness); +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + +#if LCD_DEPTH > 1 + rb->lcd_set_background(bg_color); +#endif + return PLUGIN_OK; +} Property changes on: apps/plugins/flashlight.c ___________________________________________________________________ Name: svn:executable + * Index: apps/plugin.c =================================================================== --- apps/plugin.c (Revision 16213) +++ apps/plugin.c (Arbeitskopie) @@ -133,6 +133,7 @@ backlight_on, backlight_off, backlight_set_timeout, + #if CONFIG_CHARGING backlight_set_timeout_plugged, #endif @@ -592,6 +593,10 @@ dsp_configure, dsp_process, #endif /* CONFIG_CODEC == SWCODEC */ + +#ifdef HAVE_BACKLIGHT_BRIGHTNESS + backlight_set_brightness, +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ }; int plugin_load(const char* plugin, void* parameter) Index: apps/plugin.h =================================================================== --- apps/plugin.h (Revision 16213) +++ apps/plugin.h (Arbeitskopie) @@ -119,11 +119,15 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 99 +#define PLUGIN_API_VERSION 100 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any - new function which are "waiting" at the end of the function table) */ + new function which are "waiting" at the end of the function table) + + backlight_set_brightness + + */ #define PLUGIN_MIN_API_VERSION 98 /* plugin return codes */ @@ -217,6 +221,7 @@ void (*backlight_on)(void); void (*backlight_off)(void); void (*backlight_set_timeout)(int index); + #if CONFIG_CHARGING void (*backlight_set_timeout_plugged)(int index); #endif @@ -731,6 +736,10 @@ int (*dsp_process)(struct dsp_config *dsp, char *dest, const char *src[], int count); #endif /* CONFIG_CODEC == SWCODEC */ + +#ifdef HAVE_BACKLIGHT_BRIGHTNESS + void (*backlight_set_brightness)(int val); /* Move this up on the next change to PLUGIN_MIN_API_VERSION */ +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ }; /* plugin header */