207 |
207 |
208 |
208 |
209 |
209 |
210 void editPID(pid_var *pid) |
210 void editPID(pid_var *pid) |
211 { |
211 { |
212 int index = 1, key, val; |
212 int idx = 1, key, val; |
213 char pmpt[81]; |
213 char pmpt[81]; |
214 double Kp, Ki, Kd; |
214 double Kp, Ki, Kd; |
215 |
215 |
216 if (debug) |
216 if (debug) |
217 fprintf(stdout, "editPID()\n"); |
217 fprintf(stdout, "editPID()\n"); |
218 |
218 |
219 for (;;) { |
219 for (;;) { |
220 prompt(0, NULL); |
220 prompt(0, NULL); |
221 prompt(135, NULL); |
221 prompt(135, NULL); |
222 |
222 |
223 if (index == 1) |
223 if (idx == 1) |
224 prompt(402, NULL); |
224 prompt(402, NULL); |
225 else if (index == 5) |
225 else if (idx == 5) |
226 prompt(404, NULL); |
226 prompt(404, NULL); |
227 else |
227 else |
228 prompt(403, NULL); |
228 prompt(403, NULL); |
229 |
229 |
230 switch (index) { |
230 switch (idx) { |
231 case 1: snprintf(pmpt, Config.lcd_cols + 1, "PID Kp: %5.2f", PID_getKp(pid)); |
231 case 1: snprintf(pmpt, Config.lcd_cols + 1, "PID Kp: %5.2f", PID_getKp(pid)); |
232 break; |
232 break; |
233 case 2: snprintf(pmpt, Config.lcd_cols + 1, "PID Ki: %5.2f", PID_getKi(pid)); |
233 case 2: snprintf(pmpt, Config.lcd_cols + 1, "PID Ki: %5.2f", PID_getKi(pid)); |
234 break; |
234 break; |
235 case 3: snprintf(pmpt, Config.lcd_cols + 1, "PID Kd: %5.2f", PID_getKd(pid)); |
235 case 3: snprintf(pmpt, Config.lcd_cols + 1, "PID Kd: %5.2f", PID_getKd(pid)); |
246 if (debug) |
246 if (debug) |
247 fprintf(stdout, "End editPID\n"); |
247 fprintf(stdout, "End editPID\n"); |
248 return; |
248 return; |
249 } |
249 } |
250 |
250 |
251 if ((key == KEY_UP) && (index > 1)) |
251 if ((key == KEY_UP) && (idx > 1)) |
252 index--; |
252 idx--; |
253 if ((key == KEY_DOWN) && (index < 5)) |
253 if ((key == KEY_DOWN) && (idx < 5)) |
254 index++; |
254 idx++; |
255 |
255 |
256 if (key == KEY_ENTER) { |
256 if (key == KEY_ENTER) { |
257 |
257 |
258 Kp = PID_getKp(pid); |
258 Kp = PID_getKp(pid); |
259 Ki = PID_getKi(pid); |
259 Ki = PID_getKi(pid); |
260 Kd = PID_getKd(pid); |
260 Kd = PID_getKd(pid); |
261 |
261 |
262 switch(index) { |
262 switch(idx) { |
263 case 1: editDouble(&Kp, 0.5, 50, (char *)"PID Kp"); |
263 case 1: editDouble(&Kp, 0.5, 50, (char *)"PID Kp"); |
264 PID_setTunings(pid, Kp, Ki, Kd); |
264 PID_setTunings(pid, Kp, Ki, Kd); |
265 break; |
265 break; |
266 case 2: editDouble(&Ki, 0.5, 50, (char *)"PID Ki"); |
266 case 2: editDouble(&Ki, 0.5, 50, (char *)"PID Ki"); |
267 PID_setTunings(pid, Kp, Ki, Kd); |
267 PID_setTunings(pid, Kp, Ki, Kd); |
285 |
285 |
286 |
286 |
287 void editSensor(char *uuid, char *text) |
287 void editSensor(char *uuid, char *text) |
288 { |
288 { |
289 char pmpt[81]; |
289 char pmpt[81]; |
290 int i, old, choices, index = 1, key; |
290 int i, old, choices, idx = 1, key; |
291 devices_list *device; |
291 devices_list *device; |
292 |
292 |
293 if (debug) |
293 if (debug) |
294 fprintf(stdout, "editSensor(%s, %s)\n", uuid, text); |
294 fprintf(stdout, "editSensor(%s, %s)\n", uuid, text); |
295 |
295 |
327 } |
327 } |
328 } |
328 } |
329 } |
329 } |
330 prompt(200, pmpt); /* Display current sensor */ |
330 prompt(200, pmpt); /* Display current sensor */ |
331 i = 1; |
331 i = 1; |
332 if (index == 1) { |
332 if (idx == 1) { |
333 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
333 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
334 } else { |
334 } else { |
335 for (device = Config.devices; device; device = device->next) { |
335 for (device = Config.devices; device; device = device->next) { |
336 if (device->direction == DEVDIR_IN_ANALOG) { |
336 if (device->direction == DEVDIR_IN_ANALOG) { |
337 i++; |
337 i++; |
338 if (i == index) { |
338 if (i == idx) { |
339 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
339 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
340 } |
340 } |
341 } |
341 } |
342 } |
342 } |
343 } |
343 } |
344 prompt(300, pmpt); /* Display possible new sensor */ |
344 prompt(300, pmpt); /* Display possible new sensor */ |
345 |
345 |
346 |
346 |
347 if (choices == 1) |
347 if (choices == 1) |
348 prompt(405, NULL); |
348 prompt(405, NULL); |
349 else if (index == 1) |
349 else if (idx == 1) |
350 prompt(402, NULL); |
350 prompt(402, NULL); |
351 else if (index == choices) |
351 else if (idx == choices) |
352 prompt(404, NULL); |
352 prompt(404, NULL); |
353 else |
353 else |
354 prompt(403, NULL); |
354 prompt(403, NULL); |
355 |
355 |
356 key = keywait(); |
356 key = keywait(); |
358 if (debug) |
358 if (debug) |
359 fprintf(stdout, "End editSensor\n"); |
359 fprintf(stdout, "End editSensor\n"); |
360 return; |
360 return; |
361 } |
361 } |
362 |
362 |
363 if ((key == KEY_UP) && (index > 1)) |
363 if ((key == KEY_UP) && (idx > 1)) |
364 index--; |
364 idx--; |
365 if ((key == KEY_DOWN) && (index < choices)) |
365 if ((key == KEY_DOWN) && (idx < choices)) |
366 index++; |
366 idx++; |
367 |
367 |
368 if ((key == KEY_ENTER) && (index != old)) { |
368 if ((key == KEY_ENTER) && (idx != old)) { |
369 /* |
369 /* |
370 * Select new sensor. |
370 * Select new sensor. |
371 */ |
371 */ |
372 if (index == 1) { |
372 if (idx == 1) { |
373 /* |
373 /* |
374 * Disable the sensor |
374 * Disable the sensor |
375 */ |
375 */ |
376 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); |
376 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); |
377 old = index; |
377 old = idx; |
378 } else { |
378 } else { |
379 i = 1; |
379 i = 1; |
380 for (device = Config.devices; device; device = device->next) { |
380 for (device = Config.devices; device; device = device->next) { |
381 if (device->direction == DEVDIR_IN_ANALOG) { |
381 if (device->direction == DEVDIR_IN_ANALOG) { |
382 i++; |
382 i++; |
383 if (i == index) { |
383 if (i == idx) { |
384 strncpy(uuid, device->uuid, 36); |
384 strncpy(uuid, device->uuid, 36); |
385 break; |
385 break; |
386 } |
386 } |
387 } |
387 } |
388 } |
388 } |
389 old = index; |
389 old = idx; |
390 } |
390 } |
391 } |
391 } |
392 } |
392 } |
393 } |
393 } |
394 |
394 |
395 |
395 |
396 |
396 |
397 void editRelay(char *uuid, char *text) |
397 void editRelay(char *uuid, char *text) |
398 { |
398 { |
399 char pmpt[81]; |
399 char pmpt[81]; |
400 int i, old, choices, index = 1, key; |
400 int i, old, choices, idx = 1, key; |
401 devices_list *device; |
401 devices_list *device; |
402 |
402 |
403 if (debug) |
403 if (debug) |
404 fprintf(stdout, "editRelay(%s, %s)\n", uuid, text); |
404 fprintf(stdout, "editRelay(%s, %s)\n", uuid, text); |
405 |
405 |
437 } |
437 } |
438 } |
438 } |
439 } |
439 } |
440 prompt(200, pmpt); /* Display current relay */ |
440 prompt(200, pmpt); /* Display current relay */ |
441 i = 1; |
441 i = 1; |
442 if (index == 1) { |
442 if (idx == 1) { |
443 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
443 snprintf(pmpt, Config.lcd_cols + 1, "N/A"); |
444 } else { |
444 } else { |
445 for (device = Config.devices; device; device = device->next) { |
445 for (device = Config.devices; device; device = device->next) { |
446 if (device->direction == DEVDIR_OUT_ANALOG) { |
446 if (device->direction == DEVDIR_OUT_ANALOG) { |
447 i++; |
447 i++; |
448 if (i == index) { |
448 if (i == idx) { |
449 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
449 snprintf(pmpt, Config.lcd_cols + 1, "%s", device->description); |
450 } |
450 } |
451 } |
451 } |
452 } |
452 } |
453 } |
453 } |
454 prompt(300, pmpt); /* Display possible new relay */ |
454 prompt(300, pmpt); /* Display possible new relay */ |
455 |
455 |
456 if (choices == 1) |
456 if (choices == 1) |
457 prompt(405, NULL); |
457 prompt(405, NULL); |
458 else if (index == 1) |
458 else if (idx == 1) |
459 prompt(402, NULL); |
459 prompt(402, NULL); |
460 else if (index == choices) |
460 else if (idx == choices) |
461 prompt(404, NULL); |
461 prompt(404, NULL); |
462 else |
462 else |
463 prompt(403, NULL); |
463 prompt(403, NULL); |
464 |
464 |
465 key = keywait(); |
465 key = keywait(); |
467 if (debug) |
467 if (debug) |
468 fprintf(stdout, "End editRelay\n"); |
468 fprintf(stdout, "End editRelay\n"); |
469 return; |
469 return; |
470 } |
470 } |
471 |
471 |
472 if ((key == KEY_UP) && (index > 1)) |
472 if ((key == KEY_UP) && (idx > 1)) |
473 index--; |
473 idx--; |
474 if ((key == KEY_DOWN) && (index < choices)) |
474 if ((key == KEY_DOWN) && (idx < choices)) |
475 index++; |
475 idx++; |
476 |
476 |
477 if ((key == KEY_ENTER) && (index != old)) { |
477 if ((key == KEY_ENTER) && (idx != old)) { |
478 /* |
478 /* |
479 * Select new output. |
479 * Select new output. |
480 */ |
480 */ |
481 if (index == 1) { |
481 if (idx == 1) { |
482 /* |
482 /* |
483 * Disable the output |
483 * Disable the output |
484 */ |
484 */ |
485 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); |
485 strncpy(uuid, (char *)"00000000-0000-0000-0000-000000000000", 36); |
486 old = index; |
486 old = idx; |
487 } else { |
487 } else { |
488 i = 1; |
488 i = 1; |
489 for (device = Config.devices; device; device = device->next) { |
489 for (device = Config.devices; device; device = device->next) { |
490 if (device->direction == DEVDIR_OUT_ANALOG) { |
490 if (device->direction == DEVDIR_OUT_ANALOG) { |
491 i++; |
491 i++; |
492 if (i == index) { |
492 if (i == idx) { |
493 strncpy(uuid, device->uuid, 36); |
493 strncpy(uuid, device->uuid, 36); |
494 break; |
494 break; |
495 } |
495 } |
496 } |
496 } |
497 } |
497 } |
498 old = index; |
498 old = idx; |
499 } |
499 } |
500 } |
500 } |
501 } |
501 } |
502 } |
502 } |
503 |
503 |
522 for (;;) { |
522 for (;;) { |
523 |
523 |
524 prompt(0, NULL); |
524 prompt(0, NULL); |
525 prompt(131, NULL); |
525 prompt(131, NULL); |
526 |
526 |
527 if (index == 1) |
527 if (idx == 1) |
528 prompt(402, NULL); |
528 prompt(402, NULL); |
529 else if (index == 21) |
529 else if (idx == 21) |
530 prompt(404, NULL); |
530 prompt(404, NULL); |
531 else |
531 else |
532 prompt(403, NULL); |
532 prompt(403, NULL); |
533 |
533 |
534 switch (index) { // 12345678901234567890 |
534 switch (idx) { // 12345678901234567890 |
535 case 1: snprintf(pmpt, Config.lcd_cols + 1, "Unit name:"); |
535 case 1: snprintf(pmpt, Config.lcd_cols + 1, "Unit name:"); |
536 prompt(200, pmpt); |
536 prompt(200, pmpt); |
537 snprintf(pmpt, Config.lcd_cols + 1, "%s", unit->name); |
537 snprintf(pmpt, Config.lcd_cols + 1, "%s", unit->name); |
538 prompt(300, pmpt); |
538 prompt(300, pmpt); |
539 break; |
539 break; |
607 if (debug) |
607 if (debug) |
608 fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid); |
608 fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid); |
609 return; |
609 return; |
610 } |
610 } |
611 |
611 |
612 if ((key == KEY_UP) && (index > 1)) |
612 if ((key == KEY_UP) && (idx > 1)) |
613 index--; |
613 idx--; |
614 if ((key == KEY_DOWN) && (index < 21)) |
614 if ((key == KEY_DOWN) && (idx < 21)) |
615 index++; |
615 idx++; |
616 |
616 |
617 if (key == KEY_ENTER) { |
617 if (key == KEY_ENTER) { |
618 switch(index) { |
618 switch(idx) { |
619 case 1: // name |
619 case 1: // name |
620 break; |
620 break; |
621 case 2: uuid = xstrcpy(unit->hlt_sensor.uuid); |
621 case 2: uuid = xstrcpy(unit->hlt_sensor.uuid); |
622 editSensor(uuid, (char *)"HLT sensor"); |
622 editSensor(uuid, (char *)"HLT sensor"); |
623 strncpy(unit->hlt_sensor.uuid, uuid, 36); |
623 strncpy(unit->hlt_sensor.uuid, uuid, 36); |