Display.ino 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // LCD
  2. byte customCharSun[8] = {0b00100, 0b10001, 0b01110, 0b11111, 0b11111, 0b01110, 0b10001, 0b00100};
  3. byte customCharMoon[8] = {0b11000, 0b01110, 0b00110, 0b00111, 0b00111, 0b00110, 0b01110, 0b11000};
  4. byte customCharArrowRight[8] = {0b00000, 0b00100, 0b00110, 0b11111, 0b11111, 0b00110, 0b00100, 0b00000};
  5. byte customCharDegC[8] = {0b01000, 0b10100, 0b01000, 0b00011, 0b00100, 0b00100, 0b00011, 0b00000};
  6. //bool displayActive = false;
  7. unsigned long displayLastOnMillis = 0;
  8. void enableDisplay() {
  9. lcd.backlight();
  10. displayActive = true;
  11. displayLastOnMillis = millis();
  12. }
  13. void disableDisplay() {
  14. lcd.noBacklight();
  15. displayActive = false;
  16. }
  17. void extendDisplayTimeout() {
  18. displayLastOnMillis = millis();
  19. }
  20. void handleDisplayTimeout() {
  21. if (displayActive && (millis() - displayLastOnMillis) > (displayTimeout * 1000)) {
  22. disableDisplay();
  23. }
  24. }
  25. void initDisplay() {
  26. lcd.init();
  27. lcd.createChar(0, customCharMoon);
  28. lcd.createChar(1, customCharSun);
  29. lcd.createChar(2, customCharArrowRight);
  30. lcd.createChar(3, customCharDegC);
  31. lcd.setCursor(0, 0);
  32. lcd.print("WiFiThermostat ");
  33. lcd.setCursor(0, 1);
  34. lcd.print(" (c) 2018 FloKra");
  35. // for ( int i = 0; i < 3; i++) {
  36. // lcd.backlight();
  37. // delay(200);
  38. // lcd.noBacklight();
  39. // delay(200);
  40. // }
  41. lcd.backlight();
  42. delay(1000);
  43. ///lcd.clear();
  44. displayActive = true;
  45. displayLastOnMillis = millis();
  46. }
  47. void updateDisplay() {
  48. long now = millis();
  49. if ( ((now - outTempHumLastUpdate) < 300000) && outTempHumLastUpdate != 0 && whichTempToDisplay == 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
  50. // outside temp has been updated < 5 min ago, last displayed temp was "I" and display interval is overdue
  51. whichTempToDisplay = 2; // 1= I, 2= A
  52. lastDisplayToggle = now;
  53. }
  54. else if ( whichTempToDisplay != 1 && ((now - lastDisplayToggle) > (displayInterval * 1000)) ) {
  55. whichTempToDisplay = 1; // 1= I, 2= A
  56. lastDisplayToggle = now;
  57. }
  58. lastDisplayUpdate = now;
  59. boolean showTemp = false;
  60. char temp_chararr[6];
  61. char hum_chararr[4];
  62. char tempLabel[2];
  63. if (whichTempToDisplay == 2) {
  64. if ( outTempHumLastUpdate != 0 && (now - outTempHumLastUpdate) < 120000 ) {
  65. showTemp = true;
  66. dtostrf(outTemp, 5, 1, temp_chararr );
  67. sprintf(hum_chararr, "%2i", outHum);
  68. strcpy(tempLabel, "A");
  69. }
  70. }
  71. else {
  72. if ( lastTempUpdate != 0 && (now - lastTempUpdate) < 120000 ) {
  73. showTemp = true;
  74. dtostrf(currTemp, 5, 1, temp_chararr );
  75. sprintf(hum_chararr, "%2i", currHum);
  76. strcpy(tempLabel, "I");
  77. }
  78. }
  79. // LCD line 1
  80. // print temperature incl = and ° symbol + humidity to lcd, line 1, first 11 chars
  81. lcd.setCursor(0, 0);
  82. if (showTemp) {
  83. //lcd.write(0x3D); // = Zeichen
  84. lcd.print(tempLabel);
  85. lcd.print(" ");
  86. lcd.print(temp_chararr);
  87. //lcd.write(0xDF); // degree symbol
  88. lcd.write((uint8_t)3); // °C symbol
  89. lcd.print(" ");
  90. if (currHum == 0) lcd.print("--");
  91. else if (currHum < 10) {
  92. lcd.print(" ");
  93. lcd.print(hum_chararr);
  94. }
  95. else {
  96. lcd.print(hum_chararr);
  97. }
  98. lcd.print("%");
  99. lcd.print(" ");
  100. }
  101. else {
  102. lcd.print(" ");
  103. }
  104. // display current mode on LCD
  105. lcd.setCursor(13, 0);
  106. if (heatingMode > 0) {
  107. if ( heatingMode == 1 ) { // day/normal mode
  108. lcd.print(" ");
  109. lcd.write((uint8_t)1); // sun symbol if mode is day/normal
  110. lcd.print(" ");
  111. }
  112. else if ( heatingMode == 2 ) { // night/reduction mode
  113. lcd.print(" ");
  114. lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
  115. lcd.print(" ");
  116. }
  117. }
  118. else lcd.print(" "); // mode is heating off
  119. float curr_setTemp;
  120. if (heatingMode == 1) curr_setTemp = setTemp;
  121. else if (heatingMode == 2) curr_setTemp = setTempLow;
  122. char currSetTemp_chararr[6];
  123. dtostrf(curr_setTemp, 5, 1, currSetTemp_chararr );
  124. // LCD line 2
  125. // display target temperature to line 2, 8 chars length incl space at the end
  126. lcd.setCursor(0, 1);
  127. // when the heating mode is OFF, do not display target temp - instead show "Heating off" info in line 2
  128. if ( heatingMode == 0 ) {
  129. // 1234567890123456
  130. lcd.print(" Heizung aus ");
  131. }
  132. else {
  133. lcd.write((uint8_t)2); // Pfeil rechts
  134. lcd.print(" ");
  135. lcd.print(currSetTemp_chararr);
  136. //lcd.write(0xDF); // degree symbol
  137. lcd.write((uint8_t)3); // °C symbol
  138. lcd.print(" ");
  139. // display status info to line 2 from char 9 -> 8 chars length
  140. lcd.setCursor(8, 1);
  141. lcd.print(" ");
  142. if (turnHeatingOn) {
  143. // 1234567
  144. lcd.print("heizen ");
  145. }
  146. else if ( heatingMode == 1 ) { // day/normal mode
  147. // 1234567
  148. lcd.print(" ");
  149. }
  150. else if ( heatingMode == 2 ) { // night/reduction mode
  151. // 1234567
  152. lcd.print("Absenk.");
  153. }
  154. else lcd.print(" ");
  155. }
  156. }