Display.ino 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // 12345667890123456
  80. // =20.0° 35% >22.5°
  81. // A -10.2° 95% N
  82. // A 22.2° 95% N
  83. // A 5.2° 95% N
  84. // LCD line 1
  85. // print temperature incl = and ° symbol + humidity to lcd, line 1, first 11 chars
  86. lcd.setCursor(0, 0);
  87. if (showTemp) {
  88. //lcd.write(0x3D); // = Zeichen
  89. lcd.print(tempLabel);
  90. lcd.print(" ");
  91. lcd.print(temp_chararr);
  92. //lcd.write(0xDF); // degree symbol
  93. lcd.write((uint8_t)3); // °C symbol
  94. lcd.print(" ");
  95. if (currHum == 0) lcd.print("--");
  96. else if (currHum < 10) {
  97. lcd.print(" ");
  98. lcd.print(hum_chararr);
  99. }
  100. else {
  101. lcd.print(hum_chararr);
  102. }
  103. lcd.print("%");
  104. lcd.print(" ");
  105. }
  106. else {
  107. lcd.print(" ");
  108. }
  109. // display current mode on LCD
  110. lcd.setCursor(13, 0);
  111. if (heatingMode > 0) {
  112. if ( heatingMode == 1 ) { // day/normal mode
  113. lcd.print(" ");
  114. lcd.write((uint8_t)1); // sun symbol if mode is day/normal
  115. lcd.print(" ");
  116. }
  117. else if ( heatingMode == 2 ) { // night/reduction mode
  118. lcd.print(" ");
  119. lcd.write((uint8_t)0); // moon symbol if mode is night/reduction
  120. lcd.print(" ");
  121. }
  122. }
  123. else lcd.print(" "); // mode is heating off
  124. float curr_setTemp;
  125. if (heatingMode == 1) curr_setTemp = setTemp;
  126. else if (heatingMode == 2) curr_setTemp = setTempLow;
  127. char currSetTemp_chararr[6];
  128. dtostrf(curr_setTemp, 5, 1, currSetTemp_chararr );
  129. // LCD line 2
  130. // display target temperature to line 2, 8 chars length incl space at the end
  131. lcd.setCursor(0, 1);
  132. // when the heating mode is OFF, do not display target temp - instead show "Heating off" info in line 2
  133. if ( heatingMode == 0 ) {
  134. // 1234567890123456
  135. lcd.print(" Heizung aus ");
  136. }
  137. else {
  138. lcd.write((uint8_t)2); // Pfeil rechts
  139. lcd.print(" ");
  140. lcd.print(currSetTemp_chararr);
  141. //lcd.write(0xDF); // degree symbol
  142. lcd.write((uint8_t)3); // °C symbol
  143. lcd.print(" ");
  144. // display status info to line 2 from char 9 -> 8 chars length
  145. lcd.setCursor(8, 1);
  146. lcd.print(" ");
  147. if (turnHeatingOn) {
  148. // 1234567
  149. lcd.print("heizen ");
  150. }
  151. else if ( heatingMode == 1 ) { // day/normal mode
  152. // 1234567
  153. lcd.print(" ");
  154. }
  155. else if ( heatingMode == 2 ) { // night/reduction mode
  156. // 1234567
  157. lcd.print("Absenk.");
  158. }
  159. else lcd.print(" ");
  160. }
  161. }