brewco/setup.c

Sat, 28 Nov 2015 21:00:29 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 28 Nov 2015 21:00:29 +0100
changeset 442
1193bd7d460f
child 443
6b80a37fdf8d
permissions
-rw-r--r--

Split some sources

/*****************************************************************************
 * 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;



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

    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);
	prompt(102);
	prompt(option);
	if (option == 202)
	    prompt(402);
#ifdef USE_SIMULATOR
	else if (option == 205)
#else
	else if (option == 204)
#endif
	    prompt(404);
	else
	    prompt(403);

	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++;
	}

    }
}

mercurial