Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison tempctrl.c @ 60:bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 08 Apr 2013 23:11:35 +0930 |
parents | adc9b1555f9d |
children | 9c5db7fee912 |
comparison
equal
deleted
inserted
replaced
59:488085e0c7e1 | 60:bbdf5642a7b7 |
---|---|
237 settings.minheatontime + lastheaton < t) | 237 settings.minheatontime + lastheaton < t) |
238 nextstate = 'i'; | 238 nextstate = 'i'; |
239 break; | 239 break; |
240 | 240 |
241 default: | 241 default: |
242 printf("\r\nUnknown state %c, going to idle\n", currstate); | 242 printf("\nUnknown state %c, going to idle\n", currstate); |
243 nextstate = 'i'; | 243 nextstate = 'i'; |
244 break; | 244 break; |
245 } | 245 } |
246 | 246 |
247 /* Override if we have stale data */ | 247 /* Override if we have stale data */ |
293 p += strftime(p, sizeof(linebuf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm); | 293 p += strftime(p, sizeof(linebuf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm); |
294 p += fmttemp(p, "Tr", settings.target_temp, ", "); | 294 p += fmttemp(p, "Tr", settings.target_temp, ", "); |
295 p += fmttemp(p, "Fm", tempt, ", "); | 295 p += fmttemp(p, "Fm", tempt, ", "); |
296 p += fmttemp(p, "Fr", fridge_temp, ", "); | 296 p += fmttemp(p, "Fr", fridge_temp, ", "); |
297 p += fmttemp(p, "Am", ambient_temp, ", "); | 297 p += fmttemp(p, "Am", ambient_temp, ", "); |
298 sprintf(p, "St: %s, Fl: %s%s\r\n", state2long(currstate), | 298 sprintf(p, "St: %s, Fl: %s%s\n", state2long(currstate), |
299 forced ? "F" : "", | 299 forced ? "F" : "", |
300 stale ? "S" : ""); | 300 stale ? "S" : ""); |
301 fputs(linebuf, stdout); | 301 fputs(linebuf, stdout); |
302 if (settings.logfilefmt[0] != '\0') { | 302 if (settings.logfilefmt[0] != '\0') { |
303 strftime(fbuf, sizeof(fbuf) - 1, settings.logfilefmt, &tm); | 303 strftime(fbuf, sizeof(fbuf) - 1, settings.logfilefmt, &tm); |
337 */ | 337 */ |
338 static void | 338 static void |
339 tempctrl_load_or_init_settings(void) { | 339 tempctrl_load_or_init_settings(void) { |
340 /* XXX: todo */ | 340 /* XXX: todo */ |
341 if (!flashreadblock(0, sizeof(settings), &settings)) { | 341 if (!flashreadblock(0, sizeof(settings), &settings)) { |
342 fputs("CRC fails, loading defaults\r\n", stdout); | 342 fputs("CRC fails, loading defaults\n", stdout); |
343 tempctrl_default_settings(); | 343 tempctrl_default_settings(); |
344 tempctrl_write_settings(); | 344 tempctrl_write_settings(); |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
372 cool = 0; | 372 cool = 0; |
373 heat = 1; | 373 heat = 1; |
374 break; | 374 break; |
375 | 375 |
376 default: | 376 default: |
377 printf("Unknown state %c, setting idle\r\n", state); | 377 printf("Unknown state %c, setting idle\n", state); |
378 /* fallthrough */ | 378 /* fallthrough */ |
379 | 379 |
380 case 'i': | 380 case 'i': |
381 cool = 0; | 381 cool = 0; |
382 heat = 0; | 382 heat = 0; |
401 tempctrl_cmd(int argc, char **argv) { | 401 tempctrl_cmd(int argc, char **argv) { |
402 int16_t data; | 402 int16_t data; |
403 uint8_t ROM[8]; | 403 uint8_t ROM[8]; |
404 | 404 |
405 if (argc < 1) { | 405 if (argc < 1) { |
406 printf("Unable to parse tc subcommand\r\n"); | 406 printf("Unable to parse tc subcommand\n"); |
407 return; | 407 return; |
408 } | 408 } |
409 | 409 |
410 if (!strcasecmp(argv[0], "help")) { | 410 if (!strcasecmp(argv[0], "help")) { |
411 printf("tc help This help\r\n" | 411 printf("tc help This help\n" |
412 "tc save Save settings to EEPROM\r\n" | 412 "tc save Save settings to EEPROM\n" |
413 "tc load Load or default settings from EEPROM\r\n" | 413 "tc load Load or default settings from EEPROM\n" |
414 "tc dflt Load defaults from flash\r\n" | 414 "tc dflt Load defaults from flash\n" |
415 "tc list List current settings\r\n" | 415 "tc list List current settings\n" |
416 "tc mode [achin] Change control mode, must be one of\r\n" | 416 "tc mode [achin] Change control mode, must be one of\n" |
417 " a Auto\r\n" | 417 " a Auto\n" |
418 " c Always cool\r\n" | 418 " c Always cool\n" |
419 " h Always heat\r\n" | 419 " h Always heat\n" |
420 " i Always idle\r\n" | 420 " i Always idle\n" |
421 " n Like idle but don't log anything\r\n" | 421 " n Like idle but don't log anything\n" |
422 "tc X Y Set X to Y where X is one of\r\n" | 422 "tc X Y Set X to Y where X is one of\n" |
423 " targ Target temperature\r\n" | 423 " targ Target temperature\n" |
424 " hys Hysteresis range\r\n" | 424 " hys Hysteresis range\n" |
425 " mhov Minimum heat overshoot\r\n" | 425 " mhov Minimum heat overshoot\n" |
426 " mcov Minimum cool overshoot\r\n" | 426 " mcov Minimum cool overshoot\n" |
427 " mcon Minimum cool on time\r\n" | 427 " mcon Minimum cool on time\n" |
428 " mcoff Minimum cool off time\r\n" | 428 " mcoff Minimum cool off time\n" |
429 " mhin Minimum heat on time\r\n" | 429 " mhin Minimum heat on time\n" |
430 " mhoff Minimum heat off time\r\n" | 430 " mhoff Minimum heat off time\n" |
431 "tc A B Set temperature sensor ID\r\n" | 431 "tc A B Set temperature sensor ID\n" |
432 " Where A is ferm, frg or amb\r\n" | 432 " Where A is ferm, frg or amb\n" |
433 " and B is of the form xx:xx:xx:xx:xx:xx:xx:xx\r\n" | 433 " and B is of the form xx:xx:xx:xx:xx:xx:xx:xx\n" |
434 "\r\n" | 434 "\n" |
435 " Times are in seconds\r\n" | 435 " Times are in seconds\n" |
436 " Temperatures are in hundredths of degrees Celcius\r\n" | 436 " Temperatures are in hundredths of degrees Celcius\n" |
437 ); | 437 ); |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 if (!strcasecmp(argv[0], "save")) { | 441 if (!strcasecmp(argv[0], "save")) { |
449 if (!strcasecmp(argv[0], "dflt")) { | 449 if (!strcasecmp(argv[0], "dflt")) { |
450 tempctrl_default_settings(); | 450 tempctrl_default_settings(); |
451 return; | 451 return; |
452 } | 452 } |
453 if (!strcasecmp(argv[0], "list")) { | 453 if (!strcasecmp(argv[0], "list")) { |
454 printf("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | 454 printf("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
455 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | 455 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
456 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" | 456 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
457 "Mode - %c, Target - %d, Hystersis - %d\r\n" | 457 "Mode - %c, Target - %d, Hystersis - %d\n" |
458 "Min heat overshoot - %d, Min cool overshoot - %d\r\n" | 458 "Min heat overshoot - %d, Min cool overshoot - %d\n" |
459 "Min cool on time - %d, Min cool off time - %d\r\n" | 459 "Min cool on time - %d, Min cool off time - %d\n" |
460 "Min heat on time - %d, Min heat off time - %d\r\n" | 460 "Min heat on time - %d, Min heat off time - %d\n" |
461 "Cool: Port %c Pin %d Inv %d, Heat: Port %c Pin %d Inv %d\r\n" | 461 "Cool: Port %c Pin %d Inv %d, Heat: Port %c Pin %d Inv %d\n" |
462 "Log format: %s\n", | 462 "Log format: %s\n", |
463 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3], | 463 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_ROM[3], |
464 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], | 464 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], |
465 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3], | 465 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_ROM[3], |
466 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], | 466 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], |
476 ); | 476 ); |
477 return; | 477 return; |
478 } | 478 } |
479 if (!strcasecmp(argv[0], "mode")) { | 479 if (!strcasecmp(argv[0], "mode")) { |
480 if (argc < 2) { | 480 if (argc < 2) { |
481 fputs("Incorrect number of arguments\r\n", stdout); | 481 fputs("Incorrect number of arguments\n", stdout); |
482 return; | 482 return; |
483 } | 483 } |
484 | 484 |
485 switch (argv[1][0]) { | 485 switch (argv[1][0]) { |
486 case TC_MODE_AUTO: | 486 case TC_MODE_AUTO: |
490 case TC_MODE_NOTHING: | 490 case TC_MODE_NOTHING: |
491 settings.mode = argv[1][0]; | 491 settings.mode = argv[1][0]; |
492 break; | 492 break; |
493 | 493 |
494 default: | 494 default: |
495 printf("Unknown mode character '%c'\r\n", argv[1][0]); | 495 printf("Unknown mode character '%c'\n", argv[1][0]); |
496 break; | 496 break; |
497 } | 497 } |
498 return; | 498 return; |
499 } | 499 } |
500 if (!strcasecmp(argv[0], "ferm") || | 500 if (!strcasecmp(argv[0], "ferm") || |
501 !strcasecmp(argv[0], "frg") || | 501 !strcasecmp(argv[0], "frg") || |
502 !strcasecmp(argv[0], "amb")) { | 502 !strcasecmp(argv[0], "amb")) { |
503 if (argc < 2) { | 503 if (argc < 2) { |
504 fputs("Incorrect number of arguments\r\n", stdout); | 504 fputs("Incorrect number of arguments\n", stdout); |
505 return; | 505 return; |
506 } | 506 } |
507 | 507 |
508 if (sscanf(argv[1], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", | 508 if (sscanf(argv[1], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
509 &ROM[0], &ROM[1], &ROM[2], &ROM[3], | 509 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
510 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { | 510 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
511 printf("Unable to parse ROM ID\r\n"); | 511 printf("Unable to parse ROM ID\n"); |
512 } else { | 512 } else { |
513 if (!strcasecmp(argv[0], "ferm")) | 513 if (!strcasecmp(argv[0], "ferm")) |
514 memcpy(&settings.fermenter_ROM, ROM, sizeof(ROM)); | 514 memcpy(&settings.fermenter_ROM, ROM, sizeof(ROM)); |
515 if (!strcasecmp(argv[0], "frg")) | 515 if (!strcasecmp(argv[0], "frg")) |
516 memcpy(&settings.fridge_ROM, ROM, sizeof(ROM)); | 516 memcpy(&settings.fridge_ROM, ROM, sizeof(ROM)); |
532 } | 532 } |
533 | 533 |
534 /* Handle setting the multitude of variables | 534 /* Handle setting the multitude of variables |
535 * It's last to simplify things */ | 535 * It's last to simplify things */ |
536 if (argc < 3) { | 536 if (argc < 3) { |
537 fputs("Incorrect number of arguments for variable/value\r\n", stdout); | 537 fputs("Incorrect number of arguments for variable/value\n", stdout); |
538 return; | 538 return; |
539 } | 539 } |
540 | 540 |
541 if (sscanf(argv[2], "%hd", &data) != 1) { | 541 if (sscanf(argv[2], "%hd", &data) != 1) { |
542 printf("Unable to parse value for variable\r\n"); | 542 printf("Unable to parse value for variable\n"); |
543 return; | 543 return; |
544 } | 544 } |
545 | 545 |
546 if (!strcasecmp(argv[1], "targ")) { | 546 if (!strcasecmp(argv[1], "targ")) { |
547 settings.target_temp = data; | 547 settings.target_temp = data; |
558 } else if (!strcasecmp(argv[1], "mhon")) { | 558 } else if (!strcasecmp(argv[1], "mhon")) { |
559 settings.minheatontime = data; | 559 settings.minheatontime = data; |
560 } else if (!strcasecmp(argv[1], "mhoff")) { | 560 } else if (!strcasecmp(argv[1], "mhoff")) { |
561 settings.minheatofftime = data; | 561 settings.minheatofftime = data; |
562 } else { | 562 } else { |
563 printf("Unknown setting\r\n"); | 563 printf("Unknown setting\n"); |
564 } | 564 } |
565 } | 565 } |
566 | 566 |
567 static const char* | 567 static const char* |
568 state2long(char s) { | 568 state2long(char s) { |