Download the file
  1. #include "ui.h"
  2. #include "heater_controller_master.h"
  3.  
  4. UI::UI(Protocol* protocol):
  5. protocol(protocol)
  6. {
  7. protocol->set_ui(this);
  8. }
  9.  
  10. bool UI::canRun(uint32_t now) {
  11. return Serial.available();
  12. }
  13.  
  14. void UI::run(uint32_t now) {
  15. char c = Serial.read();
  16. //Serial.println(c);
  17. switch(c) {
  18. case 'S':
  19. protocol->status_request();
  20. break;
  21. case 'C':
  22. protocol->relay_close_request();
  23. break;
  24. case 'O':
  25. protocol->relay_open_request();
  26. break;
  27. default:
  28. break;
  29. }
  30. }
  31.  
  32. void UI::write_status(uint8_t relay_state, float temperature, float current) {
  33. Serial.print("S");
  34. Serial.print(relay_state, DEC);
  35. Serial.print(" ");
  36. Serial.print(temperature);
  37. Serial.print(" ");
  38. Serial.print(current);
  39. Serial.println();
  40. }
  41.  
  42. void UI::write_error(uint8_t code) {
  43. Serial.print("E");
  44. Serial.println(code, DEC);
  45. }
  46.  
  47. void UI::write_OK() {
  48. Serial.println("OK");
  49. }
  50. // vim:ft=arduino
  51.