diff --git a/Makefile.common b/Makefile.common index 3d177bc151..80dc89e373 100644 --- a/Makefile.common +++ b/Makefile.common @@ -200,6 +200,7 @@ OBJ += frontend/frontend.o \ input/input_driver.o \ led/led_driver.o \ led/null_led_driver.o \ + led/overlay_led_driver.o \ gfx/video_coord_array.o \ gfx/video_display_server.o \ gfx/video_driver.o \ diff --git a/configuration.c b/configuration.c index 39415013b0..9e7eacc246 100644 --- a/configuration.c +++ b/configuration.c @@ -2508,6 +2508,7 @@ static bool config_load_file(const char *path, bool set_defaults, buf[0] = '\0'; snprintf(buf, sizeof(buf), "led%u_map", i + 1); + settings->uints.led_map[i]=-1; CONFIG_GET_INT_BASE(conf, settings, uints.led_map[i], buf); } diff --git a/input/input_overlay.c b/input/input_overlay.c index c88f052faf..6592906e29 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -37,6 +37,9 @@ #define OVERLAY_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1) #define OVERLAY_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32) +#define MAX_VISIBILITY 32 +static enum overlay_visibility* visibility = NULL; + typedef struct input_overlay_state { /* Left X, Left Y, Right X, Right Y */ @@ -528,6 +531,39 @@ abort_load: free(data); } +void input_overlay_set_visibility(int overlay_idx,enum overlay_visibility vis) +{ + int i; + input_overlay_t *ol = overlay_ptr; + + if(visibility == NULL) + { + visibility = (enum overlay_visibility *)calloc(MAX_VISIBILITY,sizeof(enum overlay_visibility)); + for(i=0;iiface->set_alpha(ol->iface_data, overlay_idx, 0.0); +} + +static enum overlay_visibility input_overlay_get_visibility(int overlay_idx) +{ + if(visibility == NULL) return OVERLAY_VISIBILITY_DEFAULT; + if((overlay_idx < 0) || (overlay_idx >= MAX_VISIBILITY)) return OVERLAY_VISIBILITY_DEFAULT; + return visibility[overlay_idx]; +} + +static bool input_overlay_is_hidden(int overlay_idx) +{ + return (input_overlay_get_visibility(overlay_idx) == OVERLAY_VISIBILITY_HIDDEN); +} + /** * input_overlay_set_alpha_mod: * @ol : Overlay handle. @@ -544,7 +580,12 @@ void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod) return; for (i = 0; i < ol->active->load_images_size; i++) - ol->iface->set_alpha(ol->iface_data, i, mod); + { + if(input_overlay_is_hidden(i)) + ol->iface->set_alpha(ol->iface_data, i, 0.0); + else + ol->iface->set_alpha(ol->iface_data, i, mod); + } } bool input_overlay_is_alive(input_overlay_t *ol) diff --git a/input/input_overlay.h b/input/input_overlay.h index 921a905548..16d4774d42 100644 --- a/input/input_overlay.h +++ b/input/input_overlay.h @@ -94,6 +94,13 @@ enum overlay_image_transfer_status OVERLAY_IMAGE_TRANSFER_ERROR }; +enum overlay_visibility +{ + OVERLAY_VISIBILITY_DEFAULT = 0, + OVERLAY_VISIBILITY_VISIBLE, + OVERLAY_VISIBILITY_HIDDEN +}; + struct overlay { bool full_screen; @@ -257,6 +264,8 @@ bool input_overlay_is_alive(input_overlay_t *ol); void input_overlay_loaded(void *task_data, void *user_data, const char *err); +void input_overlay_set_visibility(int overlay_idx,enum overlay_visibility vis); + /* FIXME - temporary. Globals are bad */ extern input_overlay_t *overlay_ptr; diff --git a/led/led_driver.c b/led/led_driver.c index e7a784331e..c8a98d2a63 100644 --- a/led/led_driver.c +++ b/led/led_driver.c @@ -20,6 +20,11 @@ #include "../verbosity.h" static led_driver_t *current_led_driver = NULL; +extern led_driver_t *null_led_driver; +extern led_driver_t *overlay_led_driver; +#if HAVE_RPILED +extern led_driver_t *rpi_led_driver; +#endif bool led_driver_init(void) { @@ -31,10 +36,16 @@ bool led_driver_init(void) current_led_driver = null_led_driver; -#if HAVE_RPILED - if(string_is_equal("rpi", drivername)) + if(string_is_equal("overlay",drivername)) + current_led_driver = overlay_led_driver; +#if HAVE_RPILED + else if(string_is_equal("rpi", drivername)) current_led_driver = rpi_led_driver; #endif + else + { + current_led_driver = null_led_driver; + } RARCH_LOG("[LED]: LED driver = '%s' %p\n", drivername,current_led_driver); diff --git a/led/overlay_led_driver.c b/led/overlay_led_driver.c new file mode 100644 index 0000000000..271d42c31b --- /dev/null +++ b/led/overlay_led_driver.c @@ -0,0 +1,59 @@ +#include +#include "led_driver.h" +#include "led_defines.h" + +#include "configuration.h" +#include "verbosity.h" + +#include "../gfx/video_driver.h" +#include "../input/input_overlay.h" + +typedef struct +{ + int setup[MAX_LEDS]; + int map[MAX_LEDS]; +} overlayled_t; + +static overlayled_t curins; +static overlayled_t *cur = &curins; + +static void overlay_init(void) +{ + int i; + settings_t *settings = config_get_ptr(); + RARCH_LOG("[LED]: overlay LED driver init\n"); + for(i=0;isetup[i] = 0; + cur->map[i] = settings->uints.led_map[i]; + RARCH_LOG("[LED]: overlay map[%d]=%d\n",i,cur->map[i]); + + if(cur->map[i] >= 0) + { + input_overlay_set_visibility(cur->map[i],OVERLAY_VISIBILITY_HIDDEN); + } + } +} + +static void overlay_free(void) +{ + RARCH_LOG("[LED]: overlay LED driver free\n"); +} + +static void overlay_set(int led,int state) +{ + int gpio = 0; + if((led < 0) || (led >= MAX_LEDS)) + { + RARCH_WARN("[LED]: invalid led %d\n",led); + return; + } + + gpio = cur->map[led]; + + if(gpio < 0) return; + input_overlay_set_visibility(gpio,state?OVERLAY_VISIBILITY_VISIBLE:OVERLAY_VISIBILITY_HIDDEN); + RARCH_LOG("[LED]: set visibility %d %d\n",gpio,state); +} + +static led_driver_t overlay_led_driver_ins = { overlay_init, overlay_free, overlay_set }; +led_driver_t *overlay_led_driver = &overlay_led_driver_ins; diff --git a/led/rpi_led_driver.c b/led/rpi_led_driver.c index ae39bb2769..b17600d5f5 100644 --- a/led/rpi_led_driver.c +++ b/led/rpi_led_driver.c @@ -53,7 +53,7 @@ static int set_gpio(int gpio,int value) { FILE *fp; char buf[256]; - snprintf(buf, sizeof(buf), "/sys/class/gpio/%d/value", gpio); + snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/value", gpio); fp = fopen(buf,"w"); if(!fp) @@ -71,7 +71,7 @@ static int setup_gpio(int gpio) { FILE *fp; char buf[256]; - snprintf(buf, sizeof(buf), "/sys/class/gpio/%d/direction", gpio); + snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction", gpio); fp = fopen(buf,"w"); if(!fp) @@ -88,7 +88,7 @@ static int setup_gpio(int gpio) fprintf(fp,"%d\n",gpio); fclose(fp); - snprintf(buf, sizeof(buf), "/sys/class/gpio/%d/direction",gpio); + snprintf(buf, sizeof(buf), "/sys/class/gpio/gpio%d/direction",gpio); fp = fopen(buf,"w"); } @@ -102,8 +102,8 @@ static int setup_gpio(int gpio) fprintf(fp,"out\n"); fclose(fp); return 1; - } + static void rpi_set(int led,int state) { int gpio = 0;