brewco/setup.c

Wed, 02 Dec 2015 17:16:41 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 02 Dec 2015 17:16:41 +0100
changeset 443
6b80a37fdf8d
parent 442
1193bd7d460f
child 445
3ec477cda546
permissions
-rw-r--r--

Added programming display CGRAM. Added display of characters from CGRAM. Changed prompts to allow free prompt strings. More code for the brewsystem unit editor.

/*****************************************************************************
 * Copyright (C) 2015
 *   
 * Michiel Broek <mbroek at mbse dot eu>
 *
 * This file is part of the mbsePi-apps
 *
 * This 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 ThermFerm; see the file COPYING.  If not, write to the Free
 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 *****************************************************************************/

#include "brewco.h"
#include "slcd.h"
#include "setup.h"
#include "prompt.h"
#include "xutil.h"
#include "keyboard.h"


extern int		my_shutdown;
extern int              debug;
extern sys_config       Config;
extern int              lcdHandle;
extern int		slcdHandle;



int toggleYesNo(int value, char *text)
{
    int		key, new = value;
    char	pmpt[81];

    prompt(0, NULL);
    prompt(132, NULL);

    for (;;) {

        snprintf(pmpt, Config.lcd_cols + 1, "%s: %s", text, new ? (char *)"Yes":(char *)"No ");
	prompt(200, pmpt);
	if (new) {
	    prompt(404, NULL);
	} else {
	    prompt(402, NULL);
	}

	key = keywait();
	if ((key == KEY_RETURN) || my_shutdown)
	    return value;
	if ((key == KEY_UP) && new)
	    new = 0;
	else if ((key == KEY_DOWN) && (new == 0))
	    new = 1;
	if (key == KEY_ENTER)
	    return new;
    }
}



void editUnit(units_list *unit)
{
    int		index = 1, key;
    char	pmpt[81];

    if (debug)
    	fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid);

    prompt(0, NULL);

    for (;;) {

	prompt(0, NULL);
	prompt(131, NULL);

	if (index == 1)
	    prompt(402, NULL);
	else if (index == 21)
	    prompt(404, NULL);
	else
	    prompt(403, NULL);

	switch (index) {				//   12345678901234567890
	    case 1:	snprintf(pmpt, Config.lcd_cols + 1, "Unit name:");
			prompt(200, pmpt);
			snprintf(pmpt, Config.lcd_cols + 1, "%s", unit->name);
			prompt(300, pmpt);
			break;
	    case 2:	snprintf(pmpt, Config.lcd_cols + 1, "  HLT sensor setup");
			prompt(200, pmpt);
			break;
	    case 3:	snprintf(pmpt, Config.lcd_cols + 1, "  HLT heater setup");
			prompt(200, pmpt);
			break;
	    case 4:	snprintf(pmpt, Config.lcd_cols + 1, "  MLT sensor setup");
			prompt(200, pmpt);
			break;
	    case 5:	snprintf(pmpt, Config.lcd_cols + 1, "  MLT heater setup");
			prompt(200, pmpt);
			break;
	    case 6:	snprintf(pmpt, Config.lcd_cols + 1, "   MLT pump setup");
			prompt(200, pmpt);
			break;
	    case 7:	snprintf(pmpt, Config.lcd_cols + 1, "MLT heat b4 HLT: %s", unit->hlt_heater_mltfirst ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 8:	snprintf(pmpt, Config.lcd_cols + 1, "Pump cycle: %2d mins", unit->pump_cycle);
			prompt(200, pmpt);
			break;
	    case 9:	snprintf(pmpt, Config.lcd_cols + 1, "Pump rest : %2d mins", unit->pump_rest);
			prompt(200, pmpt);
			break;
	    case 10:	snprintf(pmpt, Config.lcd_cols + 1, " Pump pre-mash: %s", unit->pump_premash ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 11:	snprintf(pmpt, Config.lcd_cols + 1, " Pump on-mash: %s", unit->pump_onmash ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 12:	snprintf(pmpt, Config.lcd_cols + 1, " Pump mashout: %s", unit->pump_mashout ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 13:	snprintf(pmpt, Config.lcd_cols + 1, " Pump on-boil: %s", unit->pump_onboil ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 14:	snprintf(pmpt, Config.lcd_cols + 1, "  Pump stop: %3d\337C", unit->pump_stop);
			prompt(200, pmpt);
			break;
	    case 15:	snprintf(pmpt, Config.lcd_cols + 1, "    Skip Add: %s", unit->skip_add ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 16:	snprintf(pmpt, Config.lcd_cols + 1, "  Skip Remove: %s", unit->skip_remove ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 17:	snprintf(pmpt, Config.lcd_cols + 1, "  Skip Iodine: %s", unit->skip_iodine ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 18:	snprintf(pmpt, Config.lcd_cols + 1, "Iodine time: %3d min", unit->iodine_time);
			prompt(200, pmpt);
			break;
	    case 19:	snprintf(pmpt, Config.lcd_cols + 1, "   Whirlpool: %s", unit->whirlpool ? (char *)"Yes":(char *)"No");
			prompt(200, pmpt);
			break;
	    case 20:	snprintf(pmpt, Config.lcd_cols + 1, "   HLT PID setup");
			prompt(200, pmpt);
			break;
	    case 21:	snprintf(pmpt, Config.lcd_cols + 1, "   MLT PID setup");
			prompt(200, pmpt);
			break;
	}

	key = keywait();
	if ((key == KEY_RETURN) || my_shutdown)
	    return;

	if ((key == KEY_UP) && (index > 1))
	    index--;
	if ((key == KEY_DOWN) && (index < 21))
	    index++;

	if (key == KEY_ENTER) {
	    switch(index) {
		case 7:	unit->hlt_heater_mltfirst = toggleYesNo(unit->hlt_heater_mltfirst , (char *)"MLT heat b4 HLT");
			break;
	    }
	}
    // name
    // hlt_sensor  picklist
    // hlt_heater  picklist + value range
    // mlt_sensor  picklist
    // mlt_heater  picklist + value range
    // mlt_pump    picklist + value range
    // hlt_heater_mltfirst  0/1
    // pump_cycle 5..15
    // pump_rest  1..5
    // pump_premash 0/1
    // pump_onmash  0/1
    // pump_mashout 0/1
    // pump_onboil  0/1
    // pump_stop   80..110
    // skip_add     0/1
    // skip_remove  0/1
    // skip_iodine  0/1
    // iodine_time  0..90
    // whirlpool    0/1
    // PID_hlt
    // PID_mlt
    }

    if (debug)
	fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid);
}



void addUnit(int number)
{
    units_list	*tmpu, *unit = (units_list *)malloc(sizeof(units_list));
    char	name[81];
    uuid_t	uu;

    if (debug)
	fprintf(stdout, "Adding new brewsystem %d\n", number);
    unit->next = NULL;
    unit->version = 1;
    unit->uuid = malloc(37);
    uuid_generate(uu);
    uuid_unparse(uu, unit->uuid);
    snprintf(name, 20, "System %d", number);
    unit->name = xstrcpy(name);
    unit->number = number;
    if (number == 1)
	unit->active = 1;
    else
	unit->active = 0;
    unit->hlt_sensor = unit->mlt_sensor = NULL;
    unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL;
    unit->hlt_heater_mltfirst = 1;
    unit->pump_cycle = 7;
    unit->pump_rest = 2;
    unit->pump_premash = 1;
    unit->pump_onmash = 1;
    unit->pump_mashout = 0;
    unit->pump_onboil = 0;
    unit->pump_stop = 90;
    unit->skip_add = 0;
    unit->skip_remove = 0;
    unit->skip_iodine = 0;
    unit->iodine_time = 90;
    unit->whirlpool = 1;
    unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var));
    unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var));
    InitPID(unit->PID_hlt);
    InitPID(unit->PID_mlt);

    editUnit(unit);

    if (Config.units == NULL) {
	Config.units = unit;
    } else {
	for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
	    if (tmpu->next == NULL) {
		tmpu->next = unit;
		break;
	    }
	}
    }
    syslog(LOG_NOTICE, "Brewsystem %d added to the configuration", number);
    if (debug)
	fprintf(stdout, "Brewsystem %d added to the configuration\n", number);
}



void setup(void)
{
    int		key, option = 202;

    for (;;) {
	if (debug)
	    fprintf(stdout, "setup() option=%d\n", option);
	prompt(0, NULL);
	prompt(102, NULL);
	prompt(option, NULL);
	if (option == 202)
	    prompt(402, NULL);
#ifdef USE_SIMULATOR
	else if (option == 205)
#else
	else if (option == 204)
#endif
	    prompt(404, NULL);
	else
	    prompt(403, NULL);

	key = keywait();

	if ((key == KEY_RETURN) || my_shutdown)
	    return;
	if ((key == KEY_UP) && (option > 202)) {
	    option--;
	}
#ifdef USE_SIMULATOR
	if ((key == KEY_DOWN) && (option < 205)) {
#else
	if ((key == KEY_DOWN) && (option < 204)) {
#endif
	    option++;
	}

	if (key == KEY_ENTER) {
	    switch(option) {
		case 202:	// recipes
				break;
		case 203:	editUnit(Config.units);	/* If more units, via a selector */
				break;
		case 204:	// devices
				break;
#ifdef USE_SIMULATOR
		case 205:	// simulator
				break;
#endif
	    }
	    if (my_shutdown)
		return;
	}
    }
}

mercurial