brewco/setup.c

changeset 450
8fe99759c27f
parent 449
1277fb94999f
child 458
43a8ecb53637
equal deleted inserted replaced
449:1277fb94999f 450:8fe99759c27f
392 } 392 }
393 } 393 }
394 394
395 395
396 396
397 void editRelay(switch_var *relay, char *text) 397 void editRelay(char *uuid, char *text)
398 { 398 {
399 char pmpt[81];
400 int i, old, choices, index = 1, key;
401 devices_list *device;
402
403 if (debug)
404 fprintf(stdout, "editRelay(%s, %s)\n", uuid, text);
405
406 old = 1; // 1d0e5bb8-7408-48b9-abb4-e9041d7b99fe
407 if ((i = strcmp((char *)"00000000-0000-0000-0000-000000000000", uuid))) {
408 for (device = Config.devices; device; device = device->next) {
409 if (device->direction == DEVDIR_OUT_ANALOG) {
410 old++;
411 if (strcmp(device->uuid, uuid) == 0)
412 break;
413 }
414 }
415 }
416
417 if (debug)
418 fprintf(stdout, "editRelay(%s) old sensor index=%d\n", text, old);
419
420 for (;;) {
421 prompt(0, NULL);
422 snprintf(pmpt, Config.lcd_cols + 1, "Edit %s", text);
423 prompt(100, pmpt);
424
425 /*
426 * Count valid sensors
427 */
428 choices = 1;
429 if (old == 1) {
430 snprintf(pmpt, Config.lcd_cols + 1, "N/A");
431 }
432 for (device = Config.devices; device; device = device->next) {
433 if (device->direction == DEVDIR_OUT_ANALOG) {
434 choices++;
435 if (choices == old) {
436 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description);
437 }
438 }
439 }
440 prompt(200, pmpt); /* Display current relay */
441 i = 1;
442 if (index == 1) {
443 snprintf(pmpt, Config.lcd_cols + 1, "N/A");
444 } else {
445 for (device = Config.devices; device; device = device->next) {
446 if (device->direction == DEVDIR_OUT_ANALOG) {
447 i++;
448 if (i == index) {
449 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description);
450 }
451 }
452 }
453 }
454 prompt(300, pmpt); /* Display possible new relay */
455
456 if (choices == 1)
457 prompt(405, NULL);
458 else if (index == 1)
459 prompt(402, NULL);
460 else if (index == choices)
461 prompt(404, NULL);
462 else
463 prompt(403, NULL);
464
465 key = keywait();
466 if ((key == KEY_RETURN) || my_shutdown) {
467 if (debug)
468 fprintf(stdout, "End editRelay\n");
469 return;
470 }
471
472 if ((key == KEY_UP) && (index > 1))
473 index--;
474 if ((key == KEY_DOWN) && (index < choices))
475 index++;
476
477 if ((key == KEY_ENTER) && (index != old)) {
478 /*
479 * Select new output.
480 */
481 if (index == 1) {
482 /*
483 * Disable the output
484 */
485 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36);
486 old = index;
487 } else {
488 i = 1;
489 for (device = Config.devices; device; device = device->next) {
490 if (device->direction == DEVDIR_OUT_ANALOG) {
491 i++;
492 if (i == index) {
493 strncpy(uuid, device->uuid, 36);
494 break;
495 }
496 }
497 }
498 old = index;
499 }
500 }
501 }
399 } 502 }
400 503
401 504
402 505
403 /* 506 /*
518 case 2: uuid = xstrcpy(unit->hlt_sensor.uuid); 621 case 2: uuid = xstrcpy(unit->hlt_sensor.uuid);
519 editSensor(uuid, (char *)"HLT sensor"); 622 editSensor(uuid, (char *)"HLT sensor");
520 strncpy(unit->hlt_sensor.uuid, uuid, 36); 623 strncpy(unit->hlt_sensor.uuid, uuid, 36);
521 free(uuid); 624 free(uuid);
522 break; 625 break;
523 case 3: editRelay(unit->hlt_heater, (char *)"HLT heater"); 626 case 3: uuid = xstrcpy(unit->hlt_heater.uuid);
627 editRelay(uuid, (char *)"HLT heater");
628 strncpy(unit->hlt_heater.uuid, uuid, 36);
629 free(uuid);
524 break; 630 break;
525 case 4: uuid = xstrcpy(unit->mlt_sensor.uuid); 631 case 4: uuid = xstrcpy(unit->mlt_sensor.uuid);
526 editSensor(uuid, (char *)"MLT sensor"); 632 editSensor(uuid, (char *)"MLT sensor");
527 strncpy(unit->mlt_sensor.uuid, uuid, 36); 633 strncpy(unit->mlt_sensor.uuid, uuid, 36);
528 free(uuid); 634 free(uuid);
529 break; 635 break;
530 case 5: editRelay(unit->mlt_heater, (char *)"MLT heater"); 636 case 5: uuid = xstrcpy(unit->mlt_heater.uuid);
531 break; 637 editRelay(uuid, (char *)"MLT heater");
532 case 6: editRelay(unit->mlt_pump, (char *)"MLT pump"); 638 strncpy(unit->mlt_heater.uuid, uuid, 36);
639 free(uuid);
640 break;
641 case 6: uuid = xstrcpy(unit->mlt_pump.uuid);
642 editRelay(uuid, (char *)"MLT pump");
643 strncpy(unit->mlt_pump.uuid, uuid, 36);
644 free(uuid);
533 break; 645 break;
534 case 7: toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT"); 646 case 7: toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT");
535 break; 647 break;
536 case 8: editInteger(&unit->pump_cycle, 5, 15, 1, (char *)"Pump cycle", (char *)"mins"); 648 case 8: editInteger(&unit->pump_cycle, 5, 15, 1, (char *)"Pump cycle", (char *)"mins");
537 break; 649 break;
593 unit->hlt_sensor.state = DEVPRESENT_UNDEF; 705 unit->hlt_sensor.state = DEVPRESENT_UNDEF;
594 unit->hlt_sensor.value = 0; 706 unit->hlt_sensor.value = 0;
595 unit->mlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000"); 707 unit->mlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000");
596 unit->mlt_sensor.state = DEVPRESENT_UNDEF; 708 unit->mlt_sensor.state = DEVPRESENT_UNDEF;
597 unit->mlt_sensor.value = 0; 709 unit->mlt_sensor.value = 0;
598 unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL; 710 unit->hlt_heater.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000");
711 unit->hlt_heater.value = 0;
712 unit->hlt_heater.delay = 0;
713 unit->mlt_heater.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000");
714 unit->mlt_heater.value = 0;
715 unit->mlt_heater.delay = 0;
716 unit->mlt_pump.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000");
717 unit->mlt_pump.value = 0;
718 unit->mlt_pump.delay = 0;
599 unit->hlt_heater_mltfirst = 1; 719 unit->hlt_heater_mltfirst = 1;
600 unit->pump_cycle = 7; 720 unit->pump_cycle = 7;
601 unit->pump_rest = 2; 721 unit->pump_rest = 2;
602 unit->pump_premash = 1; 722 unit->pump_premash = 1;
603 unit->pump_onmash = 1; 723 unit->pump_onmash = 1;

mercurial