--- a/brewco/brewco.c Sun Dec 06 20:23:31 2015 +0100 +++ b/brewco/brewco.c Thu Dec 10 15:58:01 2015 +0100 @@ -48,6 +48,13 @@ #endif +#define MANUAL_NONE 0 +#define MANUAL_SELHLT 1 +#define MANUAL_SELMLT 2 +#define MANUAL_HLT 11 +#define MANUAL_MLT 12 + + /* * CGRAM characters */ @@ -100,7 +107,8 @@ int server(void); int server(void) { - int rc = 0, run = 1, key; + int rc = 0, run = 1, key, manual = MANUAL_NONE; + int man_hlt_heat = 0, man_mlt_heat = 0, man_mlt_pump = 0; units_list *unit; brew_session *brew = NULL; #ifndef HAVE_WIRINGPI_H @@ -182,26 +190,12 @@ } #endif - /* - * Initialize units for processing - */ - for (unit = Config.units; unit; unit = unit->next) { - /* - * Safety, turn everything off - */ - if (unit->active) { - unit->hlt_heater.value = 0; - unit->mlt_heater.value = 0; - unit->mlt_pump.value = 0; - } - } - if (! Config.units) { /* * No brewsystems defined, add the first */ prompt(218, NULL); /* Add Brewsystem? */ - prompt(407, NULL); /* --- --- Ok --- */ + prompt(407, NULL); /* --- --- Ok --- */ do { key = keywait(); @@ -213,6 +207,31 @@ } /* + * Initialize units for processing + */ + for (unit = Config.units; unit; unit = unit->next) { + if (unit->active) + break; + } + + if (! unit->active) { + fprintf(stdout, "No active units found\n"); + } + + /* + * Safety, turn everything off + */ + if (unit->active) { + if (debug) + fprintf(stdout, "Starting brewsystem %d `%s'\n", unit->number, unit->name); + syslog(LOG_NOTICE, "Starting brewsystem %d `%s'", unit->number, unit->name); + + unit->hlt_heater.value = 0; + unit->mlt_heater.value = 0; + unit->mlt_pump.value = 0; + } + + /* * During automation there will be a state file: * ~/.brewco/var/brewing.xml * If this file is present, there has been a crash. @@ -233,11 +252,85 @@ break; } + /* run_pause code here */ + if (brew) { /* * Automate mode */ + } else if (manual != MANUAL_NONE) { + /* + * Manual mode + */ + switch (manual) { + case MANUAL_SELHLT: prompt(0, NULL); + prompt(104, NULL); + prompt(219, NULL); + prompt(402, NULL); + key = keywait(); + if (key == KEY_DOWN) + manual = MANUAL_SELMLT; + if (key == KEY_RETURN) + manual = MANUAL_NONE; + if (key == KEY_ENTER) + manual = MANUAL_HLT; + break; + case MANUAL_SELMLT: prompt(0, NULL); + prompt(104, NULL); + prompt(220, NULL); + prompt(404, NULL); + key = keywait(); + if (key == KEY_UP) + manual = MANUAL_SELHLT; + if (key == KEY_RETURN) + manual = MANUAL_NONE; + if (key == KEY_ENTER) + manual = MANUAL_MLT; + break; + case MANUAL_HLT: prompt(0, NULL); + prompt(104, NULL); + prompt(413, NULL); + + key = keywait(); + if (key == KEY_RETURN) { + if (man_hlt_heat) + man_hlt_heat = 0; + else + man_hlt_heat = 1; + } + if (key == KEY_ESCAPE) { + manual = MANUAL_SELHLT; + man_hlt_heat = 0; + } + device_out(unit->hlt_heater.uuid, man_hlt_heat); + if (debug) + fprintf(stdout, "device_out(%s, %d) HLT heater\n", unit->hlt_heater.uuid, man_hlt_heat); + break; + case MANUAL_MLT: prompt(0, NULL); + prompt(104, NULL); + prompt(406, NULL); + key = keywait(); + if (key == KEY_RETURN) { + if (man_mlt_heat) + man_mlt_heat = 0; + else + man_mlt_heat = 1; + } + if (key == KEY_ENTER) { + if (man_mlt_pump) + man_mlt_pump = 0; + else + man_mlt_pump = 1; + } + if (key == KEY_ESCAPE) { + manual = MANUAL_SELMLT; + man_mlt_heat = man_mlt_pump = 0; + } + device_out(unit->mlt_heater.uuid, man_mlt_heat); + device_out(unit->mlt_pump.uuid, man_mlt_pump); + break; + } } else { /* * Not running. @@ -248,6 +341,9 @@ key = keywait(); if (key == KEY_ENTER) setup(); + else if (key == KEY_DOWN) { + manual = MANUAL_SELHLT; + } } usleep(100000);