Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit 91d75b0

Browse files
committed
Add Inside temperature to display
1 parent 8c9cfcc commit 91d75b0

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/main.cpp

+21-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ bool otaInitialDrawDone = false;
55
uint8_t otaState = 0;
66
uint8_t otaProgress = 0;
77

8+
float insideTemp = 0;
89
uint32_t currTempRotateTime = 0;
910

1011
bool initialUpdate = false;
@@ -31,9 +32,9 @@ void initialize() {
3132
void temperatureLoop() {
3233
if (millis() - lastTemperatureSent >= TEMPERATURE_UPDATE * 1000 || lastTemperatureSent == 0) {
3334
sensors.requestTemperatures();
34-
float temp = sensors.getTempCByIndex(0);
35-
Homie.getLogger() << F("Temperature: ") << temp << endl;
36-
temperatureNode.setProperty("degrees").send(String(temp));
35+
insideTemp = sensors.getTempCByIndex(0);
36+
Homie.getLogger() << F("Temperature: ") << insideTemp << endl;
37+
temperatureNode.setProperty("degrees").send(String(insideTemp));
3738
lastTemperatureSent = millis();
3839
}
3940
}
@@ -64,7 +65,7 @@ void setup() {
6465
uint8_t allowedHours[] = {12, 0};
6566
forecastClient.setAllowedHours(allowedHours, sizeof(allowedHours));
6667

67-
Homie_setFirmware("weather-station", "0.0.1");
68+
Homie_setFirmware("weather-station", "0.0.2");
6869
Homie_setBrand("IoT");
6970
Homie.onEvent(onHomieEvent);
7071
Homie.setSetupFunction(initialize);
@@ -78,6 +79,9 @@ void onHomieEvent(const HomieEvent &event) {
7879
bootMode = HomieBootMode::NORMAL;
7980
break;
8081
case HomieEventType::OTA_STARTED:
82+
updateCurrentTicker.detach();
83+
updateForecastTicker.detach();
84+
updateAstronomyTicker.detach();
8185
otaState = 1;
8286
break;
8387
case HomieEventType::OTA_SUCCESSFUL:
@@ -218,26 +222,31 @@ void drawProgress(uint8_t percentage, String text) {
218222
}
219223

220224
void drawCurrentWeather() {
225+
// Rotate every 10 seconds
226+
bool displayCurrent = millis() - currTempRotateTime < 10 * 1000;
227+
if (millis() - currTempRotateTime > 20 * 1000) currTempRotateTime = millis();
228+
221229
gfx.setTransparentColor(MINI_BLACK);
222230
gfx.drawPalettedBitmapFromPgm(
223-
0, 55, getMeteoconIconFromProgmem(currentWeather.icon));
231+
0, 55, getMeteoconIconFromProgmem(displayCurrent ? currentWeather.icon : "01n"));
224232

225233
gfx.setFont(ArialRoundedMTBold_14);
226234
gfx.setColor(MINI_BLUE);
227235
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
228-
gfx.drawString(220, 65, OPEN_WEATHER_DISPLAYED_CITY_NAME);
236+
gfx.drawString(220, 65, displayCurrent ? OPEN_WEATHER_DISPLAYED_CITY_NAME : "Inside");
229237

230238
gfx.setFont(ArialRoundedMTBold_36);
231239
gfx.setColor(MINI_WHITE);
232240
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
233241

234-
gfx.drawString(220, 78,
235-
String(currentWeather.temp, 1) + (IS_METRIC ? "°C" : "°F"));
242+
gfx.drawString(220, 78, String(displayCurrent ? currentWeather.temp : insideTemp, 1) + (IS_METRIC ? "°C" : "°F"));
236243

237-
gfx.setFont(ArialRoundedMTBold_14);
238-
gfx.setColor(MINI_YELLOW);
239-
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
240-
gfx.drawString(220, 118, currentWeather.description);
244+
if (displayCurrent) {
245+
gfx.setFont(ArialRoundedMTBold_14);
246+
gfx.setColor(MINI_YELLOW);
247+
gfx.setTextAlignment(TEXT_ALIGN_RIGHT);
248+
gfx.drawString(220, 118, currentWeather.description);
249+
}
241250
}
242251

243252
void drawForecast1(MiniGrafx *display, CarouselState *state, int16_t x,

0 commit comments

Comments
 (0)