Added LED objects to the SDL panel.

Thu, 19 Nov 2015 20:45:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 19 Nov 2015 20:45:09 +0100
changeset 425
c51265b518ce
parent 424
d5e36ca9085f
child 426
e54611453d29

Added LED objects to the SDL panel.

brewpanel/README file | annotate | diff | comparison | revisions
brewpanel/brewpanel.c file | annotate | diff | comparison | revisions
brewpanel/brewpanel.h file | annotate | diff | comparison | revisions
brewpanel/dlgBrew.c file | annotate | diff | comparison | revisions
brewpanel/dlgBrew.h file | annotate | diff | comparison | revisions
brewpanel/sdlgui.c file | annotate | diff | comparison | revisions
brewpanel/sdlgui.h file | annotate | diff | comparison | revisions
brewpanel/sockio.c file | annotate | diff | comparison | revisions
--- a/brewpanel/README	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/README	Thu Nov 19 20:45:09 2015 +0100
@@ -21,10 +21,11 @@
  
 
 LC2 LC1 LC0 are the device index, 0..7
-LEDs:	DB0	Control LED on thermferm panels
-	DB1	HLT heater
-	DB2	MLT heater
-	DB3	MLT pump/mixer
+LEDs:	DB0	LCD backlight
+	DB1	Control LED on thermferm panels
+	DB2	HLT heater
+	DB3	MLT heater
+	DB4	MLT pump/mixer
 	DB7	Buzzer
 
 The thermferm or brewco units are leading, they send data and get a reply.
--- a/brewpanel/brewpanel.c	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/brewpanel.c	Thu Nov 19 20:45:09 2015 +0100
@@ -151,7 +151,7 @@
     SDL_WM_SetCaption(title, NULL);
 
     syslog(LOG_NOTICE, "Starting mainloop");
-    Dialog_BrewDlg();
+    Dialog_BrewDlg(1);
     syslog(LOG_NOTICE, "Out of mainloop, cleanup");
 
     SDLGui_UnInit();
--- a/brewpanel/brewpanel.h	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/brewpanel.h	Thu Nov 19 20:45:09 2015 +0100
@@ -26,6 +26,8 @@
 #include <signal.h>
 #include <getopt.h>
 #include <limits.h>
+#include <math.h>
+
 
 #ifdef HAVE_SDL_SDL_H
 #include <SDL.h>
--- a/brewpanel/dlgBrew.c	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/dlgBrew.c	Thu Nov 19 20:45:09 2015 +0100
@@ -37,11 +37,15 @@
 extern uint16_t		keys;
 
 
-#define	MAINDLG_B1	 2
-#define MAINDLG_B2	 3
-#define MAINDLG_B3	 4
-#define MAINDLG_B4	 5
-#define MAINDLG_QUIT     6
+#define MAINDLG_QUIT	 2
+#define	MAINDLG_B1	 3
+#define MAINDLG_B2	 5
+#define MAINDLG_B3	 7
+#define MAINDLG_B4	 9
+#define	MAINDLG_B12	11
+#define	MAINDLG_B23	12
+#define MAINDLG_B34	13
+#define	MAINDLG_BALL	14
 
 
 /* The main dialog: */
@@ -50,15 +54,19 @@
 /*        type      flags     state   x    y    w    h  txt  */
 	{ SGBOX,    0,           0,   0,   0, 374, 470, NULL },
 	{ SGLCD,    0,           0,  -1,  44,  20,   4, NULL },
+	{ SGBUTTON, 0,           0, 147, 430,  80,  20, (char *)"Quit" },
 	{ SGBUTTON, 0,           0,  80, 135,  30,  30, (char *)"1" },
+	{ SGTTF,    0,           0,  85, 170,  20,  20, (char *)"Up" },
 	{ SGBUTTON, 0,           0, 140, 135,  30,  30, (char *)"2" },
+	{ SGTTF,    0,           0, 135, 170,  20,  20, (char *)"Down" },
 	{ SGBUTTON, 0,           0, 200, 135,  30,  30, (char *)"3" },
+	{ SGTTF,    0,           0, 203, 170,  20,  20, (char *)"Ret" },
 	{ SGBUTTON, 0,           0, 260, 135,  30,  30, (char *)"4" },
-	{ SGBUTTON, 0,           0, 147, 430,  80,  20, (char *)"Quit" },
-	{ SGTTF,    0,           0,  85, 170,  20,  20, (char *)"Up" },
-	{ SGTTF,    0,           0, 135, 170,  20,  20, (char *)"Down" },
-	{ SGTTF,    0,           0, 203, 170,  20,  20, (char *)"Ret" },
 	{ SGTTF,    0,           0, 258, 170,  20,  20, (char *)"Enter" },
+	{ SGBUTTON, 0,           0, 110, 195,  30,  30, (char *)"12" },
+	{ SGBUTTON, 0,           0, 170, 195,  30,  30, (char *)"23" },
+	{ SGBUTTON, 0,           0, 230, 195,  30,  30, (char *)"34" },
+	{ SGBUTTON, 0,           0, 170, 255,  30,  30, (char *)"All" },
 	{ -1,       0,           0,   0,   0,   0,   0, NULL }
 };
 
@@ -79,7 +87,7 @@
 /*
  * This functions sets up the actual font and then displays the brew panel dialog.
  */
-int Dialog_BrewDlg(void)
+int Dialog_BrewDlg(int fermenter)
 {
     int retbut;
     int bOldMouseVisibility;
@@ -95,6 +103,17 @@
     bOldMouseVisibility = SDL_ShowCursor(SDL_QUERY);
     SDL_ShowCursor(SDL_ENABLE);
 
+    if (fermenter == 1) {
+    	maindlg[1].w = 16;
+    	maindlg[1].h = 2;
+	maindlg[7].type = SGLEDRED;
+	maindlg[7].x = 218;
+	maindlg[7].y = 153;
+	maindlg[7].w = 12;
+	maindlg[8].txt = (char *)"";
+	maindlg[11].type = -1;
+    }
+
     SDLGui_CenterDlg(maindlg);
     SDLGui_DoDialogInit(maindlg);
     fd = Dialog_LCDinit(&x, &y, &w, &h, &cols, &rows, 0);
@@ -131,6 +150,30 @@
 	    case MAINDLG_B4:
 				keys &= ~0x0001;
 				break;
+	    case MAINDLG_B12 + 1000:
+				keys |= 0x000c;
+				break;
+	    case MAINDLG_B12:
+				keys &= ~0x000c;
+				break;
+	    case MAINDLG_B23 + 1000:
+				keys |= 0x0006;
+				break;
+	    case MAINDLG_B23:
+				keys &= ~0x0006;
+				break;
+	    case MAINDLG_B34 + 1000:
+				keys |= 0x0003;
+				break;
+	    case MAINDLG_B34:
+				keys &= ~0x0003;
+				break;
+	    case MAINDLG_BALL + 1000:
+				keys |= 0x000f;
+				break;
+	    case MAINDLG_BALL:
+				keys &= ~0x000f;
+				break;
 	    case MAINDLG_QUIT:	my_shutdown = TRUE;
 				break;
 	}
--- a/brewpanel/dlgBrew.h	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/dlgBrew.h	Thu Nov 19 20:45:09 2015 +0100
@@ -4,7 +4,7 @@
 #ifdef HAVE_SDL_SDL_H
 
 int  Dialog_LCDinit(int *x, int *y, int *w, int *h, int *cols, int *rows, int index);
-int  Dialog_BrewDlg(void);
+int  Dialog_BrewDlg(int fermenter);
 
 #endif
 #endif
--- a/brewpanel/sdlgui.c	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/sdlgui.c	Thu Nov 19 20:45:09 2015 +0100
@@ -495,6 +495,116 @@
 
 
 /*
+ * SDL_Surface 32-bit circle-fill algorithm without using trig
+ *
+ * While I humbly call this "Celdecea's Method", odds are that the 
+ * procedure has already been documented somewhere long ago.  All of
+ * the circle-fill examples I came across utilized trig functions or
+ * scanning neighbor pixels.  This algorithm identifies the width of
+ * a semi-circle at each pixel height and draws a scan-line covering
+ * that width.  
+ *
+ * The code is not optimized but very fast, owing to the fact that it
+ * alters pixels in the provided surface directly rather than through
+ * function calls.
+ */
+void SDLGui_fill_circle(SDL_Surface *surface, int cx, int cy, int radius, Uint32 pixel)
+{
+    /*
+     * Note that there is more to altering the bitrate of this 
+     * method than just changing this value.  See how pixels are
+     * altered at the following web page for tips:
+     * http://www.libsdl.org/intro.en/usingvideo.html
+     */
+    static const int	BPP = 4;
+    double 		r = (double)radius;
+    double		dy;
+
+    for (dy = 1; dy <= r; dy += 1.0) {
+	/*
+	 * This loop is unrolled a bit, only iterating through half of the
+	 * height of the circle.  The result is used to draw a scan line and
+	 * its mirror image below it.
+	 *
+	 * The following formula has been simplified from our original.  We
+	 * are using half of the width of the circle because we are provided
+	 * with a center and we need left/right coordinates.
+	 */
+	double dx = floor(sqrt((2.0 * r * dy) - (dy * dy)));
+	int x = cx - dx;
+
+	// Grab a pointer to the left-most pixel for each half of the circle
+	Uint8 *target_pixel_a = (Uint8 *)surface->pixels + ((int)(cy + r - dy)) * surface->pitch + x * BPP;
+	Uint8 *target_pixel_b = (Uint8 *)surface->pixels + ((int)(cy - r + dy)) * surface->pitch + x * BPP;
+
+	for (; x <= cx + dx; x++) {
+	    *(Uint32 *)target_pixel_a = pixel;
+	    *(Uint32 *)target_pixel_b = pixel;
+	    target_pixel_a += BPP;
+	    target_pixel_b += BPP;
+	}
+    }
+}
+
+
+
+static void SDLGUI_DrawLEDRed(const SGOBJ *bdlg, int objnum)
+{
+    Uint32	color;
+
+    if (bdlg[objnum].state & SG_SELECTED) {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 255, 64, 0);
+    } else {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 128, 16, 0);
+    }
+    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+}
+
+
+
+static void SDLGUI_DrawLEDBlue(const SGOBJ *bdlg, int objnum)
+{
+    Uint32      color;
+
+    if (bdlg[objnum].state & SG_SELECTED) {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 64, 160, 255);
+    } else {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 16, 48, 112);
+    }
+    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+}
+
+
+
+static void SDLGUI_DrawLEDGreen(const SGOBJ *bdlg, int objnum)
+{
+    Uint32      color;
+
+    if (bdlg[objnum].state & SG_SELECTED) {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 80, 240, 0);
+    } else {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 32, 112, 0);
+    }
+    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+}
+
+
+
+static void SDLGUI_DrawLEDYellow(const SGOBJ *bdlg, int objnum)
+{
+    Uint32      color;
+
+    if (bdlg[objnum].state & SG_SELECTED) {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 255, 255, 0);
+    } else {
+	color = SDL_MapRGB(pSdlGuiScrn->format, 160, 144, 0);
+    }
+    SDLGui_fill_circle(pSdlGuiScrn, bdlg[objnum].x, bdlg[objnum].y, bdlg[objnum].w, color);
+}
+
+
+
+/*
  * Draw a whole dialog.
  */
 void SDLGui_DrawDialog(const SGOBJ *dlg)
@@ -518,6 +628,18 @@
 	    case SGBUTTON:
 			SDLGui_DrawButton(dlg, i);
 			break;
+	    case SGLEDRED:
+			SDLGUI_DrawLEDRed(dlg, i);
+			break;
+	    case SGLEDBLUE:
+			SDLGUI_DrawLEDBlue(dlg, i);
+			break;
+	    case SGLEDGREEN:
+			SDLGUI_DrawLEDGreen(dlg, i);
+			break;
+	    case SGLEDYELLOW:
+			SDLGUI_DrawLEDYellow(dlg, i);
+			break;
 	}
     }
 
--- a/brewpanel/sdlgui.h	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/sdlgui.h	Thu Nov 19 20:45:09 2015 +0100
@@ -9,7 +9,11 @@
   SGTEXT,
   SGTTF,
   SGBUTTON,
-  SGLCD
+  SGLCD,
+  SGLEDRED,
+  SGLEDGREEN,
+  SGLEDBLUE,
+  SGLEDYELLOW
 };
 
 
--- a/brewpanel/sockio.c	Thu Nov 19 15:05:19 2015 +0100
+++ b/brewpanel/sockio.c	Thu Nov 19 20:45:09 2015 +0100
@@ -69,7 +69,6 @@
 	} else if ((data & SLCD_MHOME) == SLCD_HOME) {
 	    slcdHome(fd);
 	} else if ((data & SLCD_MDGRAM) == SLCD_DGRAM) {
-	    fprintf(stdout, "slcdPosition(%d, %d, %d)\n", fd, data & 0x001f, (data & 0x0060) >> 5);
 	    slcdPosition(fd, data & 0x001f, (data & 0x0060) >> 5);
 	} else if ((data & 0xfe00) == SLCD_DATA) {
 	    slcdPutchar(fd, data & 0x00ff);

mercurial