Initial part of LEDs and backlight implemented.

Thu, 19 Nov 2015 22:50:17 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 19 Nov 2015 22:50:17 +0100
changeset 427
e8e548922e31
parent 426
e54611453d29
child 428
d64c4c1edd78

Initial part of LEDs and backlight implemented.

brewpanel/dlgBrew.c file | annotate | diff | comparison | revisions
brewpanel/sdlgui.c file | annotate | diff | comparison | revisions
brewpanel/slcd.c file | annotate | diff | comparison | revisions
brewpanel/slcd.h file | annotate | diff | comparison | revisions
brewpanel/sockio.c file | annotate | diff | comparison | revisions
thermferm/panel.c file | annotate | diff | comparison | revisions
thermferm/slcd.c file | annotate | diff | comparison | revisions
--- a/brewpanel/dlgBrew.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/brewpanel/dlgBrew.c	Thu Nov 19 22:50:17 2015 +0100
@@ -111,7 +111,7 @@
 	maindlg[7].y = 153;
 	maindlg[7].w = 12;
 	maindlg[8].txt = (char *)"";
-	maindlg[11].type = -1;
+	maindlg[12].type = -1;
     }
 
     SDLGui_CenterDlg(maindlg);
--- a/brewpanel/sdlgui.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/brewpanel/sdlgui.c	Thu Nov 19 22:50:17 2015 +0100
@@ -38,6 +38,8 @@
 static SDL_Rect		dlgrect, bgrect;
 static int		fontwidth, fontheight;		/* Width & height of the actual font 			*/
 TTF_Font                *pFont = NULL;			/* TTF font for buttons etc.				*/
+static Uint32		LCDbg0 = 0;			/* LCD background dark					*/
+static Uint32		LCDbg1 = 0;			/* LCD background light					*/
 
 extern int		my_shutdown;
 
@@ -251,9 +253,9 @@
     Uint32	bg;
 
     if (bLight)
-	bg = SDL_MapRGB(pSdlGuiScrn->format,156,235,  4);
+	bg = LCDbg1;
     else
-	bg = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69);
+	bg = LCDbg0;
 
     sr.x=fontwidth*(c%16);
     sr.y=fontheight*(c/16);
@@ -317,11 +319,11 @@
 {
     SDL_Rect    rect;
     int         x, y, w, h, offset, border = 4;
-    Uint32      bg0 = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69);
-    Uint32	bg1 = SDL_MapRGB(pSdlGuiScrn->format,156,235,  4);
     Uint32	bc  = SDL_MapRGB(pSdlGuiScrn->format, 32, 32, 32);
     Uint32      bg;
 
+    LCDbg0 = SDL_MapRGB(pSdlGuiScrn->format, 94,147, 69);
+    LCDbg1 = SDL_MapRGB(pSdlGuiScrn->format,156,235,  4);
     /*
      * Width and height are given in character columns and rows,
      * so calculate the display size in pixels.
@@ -345,9 +347,9 @@
     }
 
     if (bdlg[objnum].state & SG_SELECTED) {
-	bg = bg1;
+	bg = LCDbg1;
     } else {
-	bg = bg0;
+	bg = LCDbg0;
     }
 
     /* The root box should be bigger than the screen, so we disable the offset there: */
--- a/brewpanel/slcd.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/brewpanel/slcd.c	Thu Nov 19 22:50:17 2015 +0100
@@ -50,6 +50,7 @@
     int		cy;		/* Cursor y position		*/
     Uint8	cgram[8][8];	/* Characters in CGRAM		*/
     int		control;	/* Control register		*/
+    int		backlight;	/* Backlight			*/
 };
 struct slcdDataStruct *slcds [MAX_SLCDS] ;
 
@@ -150,7 +151,7 @@
 {
     struct slcdDataStruct *lcd = slcds [fd];
 
-    SDLGui_Char(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data, 0);
+    SDLGui_Char(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, data, lcd->backlight);
 
     if (++lcd->cx == lcd->cols) {
 	lcd->cx = 0;
@@ -183,6 +184,15 @@
 
 
 
+void slcdBacklight(int fd, int bl)
+{
+    struct slcdDataStruct *lcd = slcds [fd];
+
+    lcd->backlight = bl;
+}
+
+
+
 int slcdInit(int fd, int x, int y, int w, int h, int cols, int rows)
 {
     static int			initialised = 0;
@@ -224,6 +234,7 @@
 	for (j = 0; j < 8; j++)
 	    lcd->cgram[i][j] = 0;
     lcd->control = 0;
+    lcd->backlight = 0;
 
     slcds[fd] = lcd;
 
--- a/brewpanel/slcd.h	Thu Nov 19 21:17:26 2015 +0100
+++ b/brewpanel/slcd.h	Thu Nov 19 22:50:17 2015 +0100
@@ -15,6 +15,7 @@
 void slcdPutchar     (int fd, unsigned char data) ;
 void slcdPuts        (int fd, const char *string) ;
 void slcdPrintf      (int fd, const char *message, ...) ;
+void slcdBacklight   (int fd, int bl);
 
 int  slcdInit        (int fd, int x, int y, int w, int h, int cols, int rows) ;
 
--- a/brewpanel/sockio.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/brewpanel/sockio.c	Thu Nov 19 22:50:17 2015 +0100
@@ -57,6 +57,12 @@
 	    slcdPosition(fd, data & 0x001f, (data & 0x0060) >> 5);
 	} else if ((data & 0xfe00) == SLCD_DATA) {
 	    slcdPutchar(fd, data & 0x00ff);
+	} else if ((data & SLCD_MLEDS) == SLCD_LEDS) {
+	    fprintf(stdout, "socket_recv leds fd=%d bits=%02x\n", fd, (data & 0x00ff));
+	    // SLED_LCD backlight
+	    // SLED_TFLED red led
+	    slcdBacklight(fd, data & SLED_LCD);
+
 	} else if (data != 0x0000) {
 	    fprintf(stdout, "socket_recv got %04x\n", data);
 	}
--- a/thermferm/panel.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/thermferm/panel.c	Thu Nov 19 22:50:17 2015 +0100
@@ -49,6 +49,8 @@
 extern int		debug;
 extern int		setupmenu;
 extern uint16_t		keys;
+extern uint16_t		leds;
+extern int		slcdHandle;
 
 int			Key_Enter = FALSE;
 int			Key_Enter_Long = FALSE;
@@ -137,12 +139,20 @@
 		Key_Enter = TRUE;
 	    if (Enter > PRESS_LONG)
 		Key_Enter_Long = TRUE;
+	    if (Enter == PRESS_LONG) {
 #ifdef HAVE_WIRINGPI_H
-	    if (Enter == PRESS_LONG)
 		digitalWrite(PANEL_LED, 1);
-	    if (Enter == (PRESS_LONG + 10))
+#endif
+		leds |= SLED_TFLED;
+		slcdLEDs(slcdHandle);
+	    }
+	    if (Enter == (PRESS_LONG + 10)) {
+#ifdef HAVE_WIRINGPI_H
 		digitalWrite(PANEL_LED, 0);
 #endif
+		leds &= ~SLED_TFLED;
+		slcdLEDs(slcdHandle);
+	    }
 	}
 
 #ifdef HAVE_WIRINGPI_H
--- a/thermferm/slcd.c	Thu Nov 19 21:17:26 2015 +0100
+++ b/thermferm/slcd.c	Thu Nov 19 22:50:17 2015 +0100
@@ -31,6 +31,7 @@
 int			sock = -1;
 uint16_t		keys = 0x0000;
 uint16_t		leds = 0x0400;	/* LED's, buzzer, LCD backlight	*/
+uint16_t		oleds = 0x0400;
 
 extern int		debug;
 
@@ -81,7 +82,9 @@
 
 void slcdLEDs(int fd)
 {
-    putLCDsocket(fd, leds);
+    if (leds != oleds)
+	putLCDsocket(fd, leds);
+    oleds = leds;
 }
 
 

mercurial