diff -r 7fe45f6e4f48 -r 1277fb94999f brewco/setup.c --- a/brewco/setup.c Sun Dec 06 14:29:37 2015 +0100 +++ b/brewco/setup.c Sun Dec 06 19:34:39 2015 +0100 @@ -284,13 +284,129 @@ +void editSensor(char *uuid, char *text) +{ + char pmpt[81]; + int i, old, choices, index = 1, key; + devices_list *device; + + if (debug) + fprintf(stdout, "editSensor(%s, %s)\n", uuid, text); + + old = 1; // 1d0e5bb8-7408-48b9-abb4-e9041d7b99fe + if ((i = strcmp((char *)"00000000-0000-0000-0000-000000000000", uuid))) { + for (device = Config.devices; device; device = device->next) { + if (device->direction == DEVDIR_IN_ANALOG) { + old++; + if (strcmp(device->uuid, uuid) == 0) + break; + } + } + } + + if (debug) + fprintf(stdout, "editSensor(%s) old sensor index=%d\n", text, old); + + for (;;) { + prompt(0, NULL); + snprintf(pmpt, Config.lcd_cols + 1, "Edit %s", text); + prompt(100, pmpt); + + /* + * Count valid sensors + */ + choices = 1; + if (old == 1) { + snprintf(pmpt, Config.lcd_cols + 1, "N/A"); + } + for (device = Config.devices; device; device = device->next) { + if (device->direction == DEVDIR_IN_ANALOG) { + choices++; + if (choices == old) { + snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); + } + } + } + prompt(200, pmpt); /* Display current sensor */ + i = 1; + if (index == 1) { + snprintf(pmpt, Config.lcd_cols + 1, "N/A"); + } else { + for (device = Config.devices; device; device = device->next) { + if (device->direction == DEVDIR_IN_ANALOG) { + i++; + if (i == index) { + snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); + } + } + } + } + prompt(300, pmpt); /* Display possible new sensor */ + + + if (choices == 1) + prompt(405, NULL); + else if (index == 1) + prompt(402, NULL); + else if (index == choices) + prompt(404, NULL); + else + prompt(403, NULL); + + key = keywait(); + if ((key == KEY_RETURN) || my_shutdown) { + if (debug) + fprintf(stdout, "End editSensor\n"); + return; + } + + if ((key == KEY_UP) && (index > 1)) + index--; + if ((key == KEY_DOWN) && (index < choices)) + index++; + + if ((key == KEY_ENTER) && (index != old)) { + /* + * Select new sensor. + */ + if (index == 1) { + /* + * Disable the sensor + */ + strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); + old = index; + } else { + i = 1; + for (device = Config.devices; device; device = device->next) { + if (device->direction == DEVDIR_IN_ANALOG) { + i++; + if (i == index) { + strncpy(uuid, device->uuid, 36); + break; + } + } + } + old = index; + } + } + } +} + + + +void editRelay(switch_var *relay, char *text) +{ +} + + + /* * Edit a single unit */ void editUnit(units_list *unit) { int index = 1, key; - char pmpt[81]; + char pmpt[81], *uuid; uLong ocrc, ncrc; if (debug) @@ -399,15 +515,21 @@ switch(index) { case 1: // name break; - case 2: // HLT sensor + case 2: uuid = xstrcpy(unit->hlt_sensor.uuid); + editSensor(uuid, (char *)"HLT sensor"); + strncpy(unit->hlt_sensor.uuid, uuid, 36); + free(uuid); break; - case 3: // HLT heater + case 3: editRelay(unit->hlt_heater, (char *)"HLT heater"); break; - case 4: // MLT sensor + case 4: uuid = xstrcpy(unit->mlt_sensor.uuid); + editSensor(uuid, (char *)"MLT sensor"); + strncpy(unit->mlt_sensor.uuid, uuid, 36); + free(uuid); break; - case 5: // MLT heater + case 5: editRelay(unit->mlt_heater, (char *)"MLT heater"); break; - case 6: // MLT pump + case 6: editRelay(unit->mlt_pump, (char *)"MLT pump"); break; case 7: toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT"); break; @@ -467,7 +589,12 @@ unit->active = 1; else unit->active = 0; - unit->hlt_sensor = unit->mlt_sensor = NULL; + unit->hlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000"); + unit->hlt_sensor.state = DEVPRESENT_UNDEF; + unit->hlt_sensor.value = 0; + unit->mlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000"); + unit->mlt_sensor.state = DEVPRESENT_UNDEF; + unit->mlt_sensor.value = 0; unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL; unit->hlt_heater_mltfirst = 1; unit->pump_cycle = 7;