282 } |
282 } |
283 } |
283 } |
284 |
284 |
285 |
285 |
286 |
286 |
|
287 void editSensor(char *uuid, char *text) |
|
288 { |
|
289 char pmpt[81]; |
|
290 int i, old, choices, index = 1, key; |
|
291 devices_list *device; |
|
292 |
|
293 if (debug) |
|
294 fprintf(stdout, "editSensor(%s, %s)\n", uuid, text); |
|
295 |
|
296 old = 1; // 1d0e5bb8-7408-48b9-abb4-e9041d7b99fe |
|
297 if ((i = strcmp((char *)"00000000-0000-0000-0000-000000000000", uuid))) { |
|
298 for (device = Config.devices; device; device = device->next) { |
|
299 if (device->direction == DEVDIR_IN_ANALOG) { |
|
300 old++; |
|
301 if (strcmp(device->uuid, uuid) == 0) |
|
302 break; |
|
303 } |
|
304 } |
|
305 } |
|
306 |
|
307 if (debug) |
|
308 fprintf(stdout, "editSensor(%s) old sensor index=%d\n", text, old); |
|
309 |
|
310 for (;;) { |
|
311 prompt(0, NULL); |
|
312 snprintf(pmpt, Config.lcd_cols + 1, "Edit %s", text); |
|
313 prompt(100, pmpt); |
|
314 |
|
315 /* |
|
316 * Count valid sensors |
|
317 */ |
|
318 choices = 1; |
|
319 if (old == 1) { |
|
320 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
|
321 } |
|
322 for (device = Config.devices; device; device = device->next) { |
|
323 if (device->direction == DEVDIR_IN_ANALOG) { |
|
324 choices++; |
|
325 if (choices == old) { |
|
326 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
|
327 } |
|
328 } |
|
329 } |
|
330 prompt(200, pmpt); /* Display current sensor */ |
|
331 i = 1; |
|
332 if (index == 1) { |
|
333 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
|
334 } else { |
|
335 for (device = Config.devices; device; device = device->next) { |
|
336 if (device->direction == DEVDIR_IN_ANALOG) { |
|
337 i++; |
|
338 if (i == index) { |
|
339 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
|
340 } |
|
341 } |
|
342 } |
|
343 } |
|
344 prompt(300, pmpt); /* Display possible new sensor */ |
|
345 |
|
346 |
|
347 if (choices == 1) |
|
348 prompt(405, NULL); |
|
349 else if (index == 1) |
|
350 prompt(402, NULL); |
|
351 else if (index == choices) |
|
352 prompt(404, NULL); |
|
353 else |
|
354 prompt(403, NULL); |
|
355 |
|
356 key = keywait(); |
|
357 if ((key == KEY_RETURN) || my_shutdown) { |
|
358 if (debug) |
|
359 fprintf(stdout, "End editSensor\n"); |
|
360 return; |
|
361 } |
|
362 |
|
363 if ((key == KEY_UP) && (index > 1)) |
|
364 index--; |
|
365 if ((key == KEY_DOWN) && (index < choices)) |
|
366 index++; |
|
367 |
|
368 if ((key == KEY_ENTER) && (index != old)) { |
|
369 /* |
|
370 * Select new sensor. |
|
371 */ |
|
372 if (index == 1) { |
|
373 /* |
|
374 * Disable the sensor |
|
375 */ |
|
376 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); |
|
377 old = index; |
|
378 } else { |
|
379 i = 1; |
|
380 for (device = Config.devices; device; device = device->next) { |
|
381 if (device->direction == DEVDIR_IN_ANALOG) { |
|
382 i++; |
|
383 if (i == index) { |
|
384 strncpy(uuid, device->uuid, 36); |
|
385 break; |
|
386 } |
|
387 } |
|
388 } |
|
389 old = index; |
|
390 } |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 |
|
396 |
|
397 void editRelay(switch_var *relay, char *text) |
|
398 { |
|
399 } |
|
400 |
|
401 |
|
402 |
287 /* |
403 /* |
288 * Edit a single unit |
404 * Edit a single unit |
289 */ |
405 */ |
290 void editUnit(units_list *unit) |
406 void editUnit(units_list *unit) |
291 { |
407 { |
292 int index = 1, key; |
408 int index = 1, key; |
293 char pmpt[81]; |
409 char pmpt[81], *uuid; |
294 uLong ocrc, ncrc; |
410 uLong ocrc, ncrc; |
295 |
411 |
296 if (debug) |
412 if (debug) |
297 fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid); |
413 fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid); |
298 |
414 |
397 |
513 |
398 if (key == KEY_ENTER) { |
514 if (key == KEY_ENTER) { |
399 switch(index) { |
515 switch(index) { |
400 case 1: // name |
516 case 1: // name |
401 break; |
517 break; |
402 case 2: // HLT sensor |
518 case 2: uuid = xstrcpy(unit->hlt_sensor.uuid); |
403 break; |
519 editSensor(uuid, (char *)"HLT sensor"); |
404 case 3: // HLT heater |
520 strncpy(unit->hlt_sensor.uuid, uuid, 36); |
405 break; |
521 free(uuid); |
406 case 4: // MLT sensor |
522 break; |
407 break; |
523 case 3: editRelay(unit->hlt_heater, (char *)"HLT heater"); |
408 case 5: // MLT heater |
524 break; |
409 break; |
525 case 4: uuid = xstrcpy(unit->mlt_sensor.uuid); |
410 case 6: // MLT pump |
526 editSensor(uuid, (char *)"MLT sensor"); |
|
527 strncpy(unit->mlt_sensor.uuid, uuid, 36); |
|
528 free(uuid); |
|
529 break; |
|
530 case 5: editRelay(unit->mlt_heater, (char *)"MLT heater"); |
|
531 break; |
|
532 case 6: editRelay(unit->mlt_pump, (char *)"MLT pump"); |
411 break; |
533 break; |
412 case 7: toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT"); |
534 case 7: toggleYesNo(&unit->hlt_heater_mltfirst, (char *)"MLT heat b4 HLT"); |
413 break; |
535 break; |
414 case 8: editInteger(&unit->pump_cycle, 5, 15, 1, (char *)"Pump cycle", (char *)"mins"); |
536 case 8: editInteger(&unit->pump_cycle, 5, 15, 1, (char *)"Pump cycle", (char *)"mins"); |
415 break; |
537 break; |
465 unit->number = number; |
587 unit->number = number; |
466 if (number == 1) |
588 if (number == 1) |
467 unit->active = 1; |
589 unit->active = 1; |
468 else |
590 else |
469 unit->active = 0; |
591 unit->active = 0; |
470 unit->hlt_sensor = unit->mlt_sensor = NULL; |
592 unit->hlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000"); |
|
593 unit->hlt_sensor.state = DEVPRESENT_UNDEF; |
|
594 unit->hlt_sensor.value = 0; |
|
595 unit->mlt_sensor.uuid = xstrcpy((char *)"00000000-0000-0000-0000-000000000000"); |
|
596 unit->mlt_sensor.state = DEVPRESENT_UNDEF; |
|
597 unit->mlt_sensor.value = 0; |
471 unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL; |
598 unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL; |
472 unit->hlt_heater_mltfirst = 1; |
599 unit->hlt_heater_mltfirst = 1; |
473 unit->pump_cycle = 7; |
600 unit->pump_cycle = 7; |
474 unit->pump_rest = 2; |
601 unit->pump_rest = 2; |
475 unit->pump_premash = 1; |
602 unit->pump_premash = 1; |