brewpanel/dlgBrew.c

Sat, 25 Apr 2020 20:31:31 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 25 Apr 2020 20:31:31 +0200
changeset 605
e00f8ff4de9a
parent 431
b3895cd6edd3
child 637
21e542c15832
permissions
-rw-r--r--

Version 0.9.8. Added extra path to the fonts for Debian buster. Changed the PID to work on Proportional on Measurement. Added loops so that it looks like the PID is running at 100 mSec intervals.

/*****************************************************************************
 * Copyright (C) 2015
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of the mbsePi-apps
 *
 * The gui code is based on the gui from the emulator ARAnyM,
 * Copyright (c) 2004 Petr Stehlik of ARAnyM dev team
 *
 * mbsePi-apps is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * mbsePi-apps is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with mbsePi-apps; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

#include "brewpanel.h"
#include "dlgBrew.h"
#include "sdlgui.h"
#include "slcd.h"
#include "sockio.h"


#ifdef HAVE_SDL_SDL_H

extern SDL_Surface	*PAN_surface;
extern int		my_shutdown;
extern int		debug;
extern uint16_t		keys;


#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: */
static SGOBJ maindlg[] =
{
/*        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" },
	{ 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" },
	{ SGLEDRED,    0,           0, 100, 350,  12,   0, NULL },
	{ SGTTF,       0,           0,  60, 365,  20,  20, (char *)"HLT heat" },
	{ SGLEDBLUE,   0,           0, 190, 350,  12,   0, NULL },
	{ SGLEDYELLOW, 0,           0, 280, 350,  12,   0, NULL },
	{ SGTTF,       0,           0, 170, 365,  20,  20, (char *)"heat    MLT    pump" },
	{ -1,          0,           0,   0,   0,   0,   0, NULL }
};



int Dialog_LCDinit(int *x, int *y, int *w, int *h, int *cols, int *rows, int index)
{
    int retval = SDLGui_LCDinit(maindlg, x, y, w, h, cols, rows, index);

    return retval;
}



/*
 * This functions sets up the actual font and then displays the brew panel dialog.
 */
int Dialog_BrewDlg(int fermenter)
{
    int retbut;
    int bOldMouseVisibility;
    int nOldMouseX, nOldMouseY;
    int x, y, w, h, cols, rows, fd;

    if (SDLGui_SetScreen(PAN_surface)) {
	syslog(LOG_NOTICE, "SDLGui_SetScreen(PAN_surface) failed: %s", SDL_GetError());
	return FALSE;
    }

    SDL_GetMouseState(&nOldMouseX, &nOldMouseY);
    bOldMouseVisibility = SDL_ShowCursor(SDL_QUERY);
    SDL_ShowCursor(SDL_ENABLE);

    /*
     * Patch the main dialog if the fermenter panel should be shown.
     */
    if (fermenter == 1) {
    	maindlg[1].w = 16;
    	maindlg[1].h = 2;
	maindlg[7].type = SGLEDGREEN;
	maindlg[7].x = 218;
	maindlg[7].y = 153;
	maindlg[7].w = 12;
	maindlg[8].txt = (char *)"";
	maindlg[12].type = -1;
    }

    SDLGui_CenterDlg(maindlg);
    SDLGui_DoDialogInit(maindlg);
    fd = Dialog_LCDinit(&x, &y, &w, &h, &cols, &rows, 0);
    if (debug)
	fprintf(stdout, "Dialog_LCDinit(%d, %d, %d, %d, %d, %d, 0) = %d\n", x, y, w, h, cols, rows, fd);
    socket_connect();
    slcdInit(maindlg, fd, x, y, w, h, cols, rows);

    do {
	retbut = SDLGui_DoDialogLoop(maindlg);

	switch (retbut) {
	    case MAINDLG_B1 + 1000:
		    		keys |= 0x0008;
				break;
	    case MAINDLG_B1:	
				keys &= ~0x0008;
		    		break;
	    case MAINDLG_B2 + 1000:
				keys |= 0x0004;
				break;
	    case MAINDLG_B2:	
				keys &= ~0x0004;
				break;
	    case MAINDLG_B3 + 1000:
				keys |= 0x0002;
				break;
	    case MAINDLG_B3:
				keys &= ~0x0002;
				break;
	    case MAINDLG_B4 + 1000:
				keys |= 0x0001;
				break;
	    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;
	}

    } while (retbut != SDLGUI_QUIT && retbut != SDLGUI_ERROR && !my_shutdown);

    SDLGui_DoDialogEnd();
    SDL_ShowCursor(bOldMouseVisibility);

    return TRUE;
}

#endif

mercurial