diff --git a/server/client_functions.c b/server/client_functions.c index e25f894..4dc632f 100644 --- a/server/client_functions.c +++ b/server/client_functions.c @@ -711,7 +711,44 @@ screen_set_func (client * c, int argc, char **argv) sock_send_string (c->sock, "huh? -timeout requires a parameter\n"); } } - else sock_send_string (c->sock, "huh? invalid parameter\n"); + + // Handle the backlight parameter + else if (strcmp (argv[i], "backlight") == 0) { + if (argc > i + 1) { + i++; + debug ("screen_set: backlight=\"%s\"\n", argv[i]); + // set the backlight status based on what the client has set + switch(c->backlight_state) { + case BACKLIGHT_OPEN: + if (strcmp ("on", argv[i]) == 0) + s->backlight_state = BACKLIGHT_ON; + + if (strcmp ("off", argv[i]) == 0) + s->backlight_state = BACKLIGHT_OFF; + + if (strcmp ("toggle", argv[i]) == 0) { + if (s->backlight_state == BACKLIGHT_ON) + s->backlight_state = BACKLIGHT_OFF; + else if (s-backlight_state == BACKLIGHT_OFF) + s->backlight_state = BACKLIGHT_ON; + } + + if (strcmp ("blink", argv[i]) == 0) + s->backlight_state |= BACKLIGHT_BLINK; + + if (strcmp ("flash", argv[i]) == 0) + s->backlight_state |= BACKLIGHT_FLASH; + break; + default: + //If the backlight is not OPEN then inherit its state + s->backlight_state = c->backlight_state; + break; + } + sock_send_string(c->sock, "success\n"); + } else { + sock_send_string (c->sock, "huh? -backlight requires a parameter\n"); + } + } else sock_send_string (c->sock, "huh? invalid parameter\n"); }// done checking argv return 0; } @@ -1259,35 +1296,26 @@ backlight_func (client * c, int argc, char **argv) debug ("backlight(%s)\n", argv[1]); - // TODO: The following don't seem to be used; - // either use them or lose them: - // - // #define BACKLIGHT_LOAD 3 - // #define BACKLIGHT_VIS 4 - // - // TODO: The meaning of this one isn't clear; make it so... - // - // #define BACKLIGHT_OPEN 2 - + backlight = (backlight && 1); // only preserves ON/OFF bit if (strcmp ("on", argv[1]) == 0) { - backlight_state = BACKLIGHT_ON; + c->backlight_state = BACKLIGHT_ON; } else if (strcmp ("off", argv[1]) == 0) { - backlight_state = BACKLIGHT_OFF; + c->backlight_state = BACKLIGHT_OFF; } else if (strcmp ("toggle", argv[1]) == 0) { - if (backlight_state == BACKLIGHT_ON) - backlight_state = BACKLIGHT_OFF; - else if (backlight_state == BACKLIGHT_OFF) - backlight_state = BACKLIGHT_ON; + if (c->backlight_state == BACKLIGHT_ON) + c->backlight_state = BACKLIGHT_OFF; + else if (c->backlight_state == BACKLIGHT_OFF) + c->backlight_state = BACKLIGHT_ON; } else if (strcmp ("blink", argv[1]) == 0) { - backlight_state |= BACKLIGHT_BLINK; + c->backlight_state |= BACKLIGHT_BLINK; - } else if (0 == strcmp ("flash", argv[1])) { - backlight_state |= BACKLIGHT_FLASH; + } else if (strcmp ("flash", argv[1]) == 0) { + c->backlight_state |= BACKLIGHT_FLASH; } sock_send_string(c->sock, "success\n"); diff --git a/server/clients.c b/server/clients.c index 774f957..f33e171 100644 --- a/server/clients.c +++ b/server/clients.c @@ -21,6 +21,7 @@ #include "clients.h" #include "client_data.h" #include "shared/debug.h" +#include "render.h" LinkedList *clients; @@ -94,6 +95,7 @@ client_create (int sock) c->messages = NULL; c->sock = sock; + c->backlight_state = backlight; //By default we get the server setting // Set up message list... c->messages = LL_new (); diff --git a/server/clients.h b/server/clients.h index 9e7b535..5612e41 100644 --- a/server/clients.h +++ b/server/clients.h @@ -7,6 +7,7 @@ typedef struct client { int sock; char addr[64]; + int backlight_state; LinkedList *messages; client_data *data; diff --git a/server/render.c b/server/render.c index 5912f94..6c60765 100644 --- a/server/render.c +++ b/server/render.c @@ -47,7 +47,7 @@ int draw_screen (screen * s, int timer) { static screen *old_s = NULL; - int tmp = 0; + int tmp = 0, tmp_state = 0; //debug("Render...\n"); //return 0; @@ -66,16 +66,24 @@ draw_screen (screen * s, int timer) // Clear the LCD screen... lcd_ptr->clear (); - // lcd_ptr->backlight -- + // FIXME lcd_ptr->backlight -- // // This should be in a separate function altogether. // Perhaps several: lcd_ptr->backlight_off, lcd_ptr->backlight_on, // lcd_ptr->backlight_brightness, lcd_ptr->backlight_flash ... - // + + // If the screen's backlight_state isn't set (default) then we + // inherit the backlight state from the parent client. This allows + // the client to override it's childrens settings. + if (s->backlight_state == BACKLIGHT_NOTSET) { + if (s->parent) tmp_state = s->parent->backlight_state; + } else { + tmp_state = s->backlight_state; + } + // Set up backlight to the correct state... // NOTE: dirty stripping of other options... - switch (backlight_state & 1) { - // Backlight off (easy) + switch (tmp_state & 1) { case BACKLIGHT_OFF: lcd_ptr->backlight (BACKLIGHT_OFF); break; @@ -85,9 +93,9 @@ draw_screen (screen * s, int timer) break; default: // Backlight flash: check timer and flip backlight as appropriate - if (backlight_state & BACKLIGHT_FLASH) { + if (tmp_state & BACKLIGHT_FLASH) { tmp = (!((timer & 7) == 7)); - if (backlight_state & 1) + if (tmp_state & 1) lcd_ptr->backlight (tmp ? backlight_brightness : backlight_off_brightness); //lcd_ptr->backlight(backlight_brightness * (!((timer&7) == 7))); else @@ -95,9 +103,9 @@ draw_screen (screen * s, int timer) //lcd_ptr->backlight(backlight_brightness * ((timer&7) == 7)); // Backlight blink: check timer and flip backlight as appropriate - } else if (backlight_state & BACKLIGHT_BLINK) { + } else if (tmp_state & BACKLIGHT_BLINK) { tmp = (!((timer & 14) == 14)); - if (backlight_state & 1) + if (tmp_state & 1) lcd_ptr->backlight (tmp ? backlight_brightness : backlight_off_brightness); //lcd_ptr->backlight(backlight_brightness * (!((timer&14) == 14))); else diff --git a/server/render.h b/server/render.h index 09befcc..5e4cafe 100644 --- a/server/render.h +++ b/server/render.h @@ -14,8 +14,7 @@ #define BACKLIGHT_OFF 0 #define BACKLIGHT_ON 1 #define BACKLIGHT_OPEN 2 -#define BACKLIGHT_LOAD 3 -#define BACKLIGHT_VIS 4 +#define BACKLIGHT_NOTSET 3 #define BACKLIGHT_BLINK 0x100 #define BACKLIGHT_FLASH 0x200 diff --git a/server/screen.c b/server/screen.c index a17771c..84a339b 100644 --- a/server/screen.c +++ b/server/screen.c @@ -12,6 +12,7 @@ #include "screenlist.h" #include "screen.h" #include "main.h" +#include "render.h" int default_duration = 0; int default_timeout = -1; @@ -38,7 +39,9 @@ screen_create () s->parent = NULL; s->widgets = NULL; s->timeout = default_timeout; //ignored unless greater than 0. - + s->backlight_state = BACKLIGHT_NOTSET; //Lets the screen do it's own + //or do what the client says. + s->widgets = LL_new (); if (!s->widgets) { fprintf (stderr, "screen_create: Error allocating widget list\n"); diff --git a/server/screen.h b/server/screen.h index 0d24305..e4eabf1 100644 --- a/server/screen.h +++ b/server/screen.h @@ -12,6 +12,7 @@ typedef struct screen { int duration; int heartbeat; int timeout; + int backlight_state; char *keys; LinkedList *widgets; client *parent;