Skip to content

Commit ac4c4ce

Browse files
committed
Add support for daylight saving time
1 parent a0941e8 commit ac4c4ce

10 files changed

Lines changed: 57 additions & 12 deletions

File tree

doc/feDesign.jpg

53.9 KB
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"offset":0}
1+
{"offset":0,"isDst":0}

firmware/data/web_server/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ <h2>Time configuration</h2>
5858
<option value="46800">UTC+13:00</option>
5959
</select>
6060
</div>
61+
<div class="field-container">
62+
<label for="dst">Daylight saving time:</label>
63+
<div class="choice-container">
64+
<div class="choice" onclick="selectDstChoice(event)" name="dstChoice" value="0">
65+
<input id="dstOff" type="radio"/>
66+
<label for="dstOff">Off</label>
67+
</div>
68+
<div class="choice" onclick="selectDstChoice(event)" name="dstChoice" value="1">
69+
<input id="dstOn" type="radio"/>
70+
<label for="dstOn">On</label>
71+
</div>
72+
</div>
73+
</div>
6174
<h2>Sleep configuration</h2>
6275
<h3>Sleep before</h3>
6376
<div class="field-container">

firmware/data/web_server/server.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ class HSV {
1313
}
1414

1515
class TimeInfo {
16-
constructor(offset) {
16+
constructor(offset, isDst) {
1717
this.offset = offset;
18+
this.isDst = isDst;
1819
}
1920
toJson() {
2021
return {
21-
"offset": this.offset
22+
"offset": this.offset,
23+
"isDst": this.isDst
2224
};
2325
}
2426
static Builder = class {
2527
fromJson(message) {
26-
return new TimeInfo(message.offset);
28+
return new TimeInfo(message.offset, message.isDst);
2729
}
2830
}
2931
}
@@ -184,6 +186,7 @@ function getTimeInfo() {
184186
.then(data => {
185187
timeInfo = new TimeInfo.Builder().fromJson(data);
186188
document.getElementById("selectTimeZone").value = timeInfo.offset;
189+
selectRadioChoiceByName("dstChoice", timeInfo.isDst);
187190
})
188191
.catch(error => {
189192
console.error('There was a problem with the getting time info:', error);
@@ -387,6 +390,10 @@ function selectBacklightChoice(evt) {
387390
ledInfo.state = selectRadioChoiceByEvent(evt);
388391
}
389392

393+
function selectDstChoice(evt) {
394+
timeInfo.isDst = selectRadioChoiceByEvent(evt);
395+
}
396+
390397
function updateSleepBefore() {
391398
document.getElementById("inputSleepBeforeHour").value = document.getElementById("sliderSleepBeforeHour").value
392399
document.getElementById("inputSleepBeforeMinute").value = document.getElementById("sliderSleepBeforeMinute").value

firmware/include/TimeInfo.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class TimeInfo {
1111
private:
1212
int offset;
13+
bool isDst;
1314

1415
public:
1516
/**
@@ -21,8 +22,9 @@ class TimeInfo {
2122
* @brief Construct a new Time Info object
2223
*
2324
* @param offset offset in seconds
25+
* @param isDst flag indicating is daylight saving time enabled
2426
*/
25-
TimeInfo(int offset);
27+
TimeInfo(int offset, bool isDst);
2628

2729
/**
2830
* @brief Default destructor
@@ -49,6 +51,20 @@ class TimeInfo {
4951
*/
5052
void SetOffset(int value);
5153

54+
/**
55+
* @brief Getter for isDst
56+
*
57+
* @return isDst Flag indicating is daylight saving enabled
58+
*/
59+
bool IsDst() const;
60+
61+
/**
62+
* @brief Setter for isDst
63+
*
64+
* @param value Flag indicating is daylight saving enabled
65+
*/
66+
void SetDst(bool value);
67+
5268
/**
5369
* @brief Convert TimeInfo to JSON format
5470
*

firmware/src/ConfigStore.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void ConfigStore::LoadTimeInfo(TimeInfo& timeInfo) {
8989
Serial.printf("Failed to read %s file.\n", TIME_INFO_FILE);
9090
file.close();
9191
timeInfo.SetOffset(doc["offset"]);
92+
timeInfo.SetDst(doc["isDst"]);
9293
}
9394

9495
void ConfigStore::SaveTimeInfo(const TimeInfo& timeInfo) {

firmware/src/NixieClock.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ TimeInfo NixieClock::OnGetTimeInfo() const {
210210

211211
void NixieClock::OnSetTimeInfo(const TimeInfo& timeInfo) {
212212
ConfigStore::SaveTimeInfo(timeInfo);
213-
timeManager.SetOffset(timeInfo.GetOffset());
213+
int offset = timeInfo.GetOffset() + (timeInfo.IsDst() ? 3600 : 0);
214+
timeManager.SetOffset(offset);
214215
}
215216

216217
bool NixieClock::IsInSleepMode() {

firmware/src/TimeInfo.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
#include "TimeInfo.h"
22

3-
TimeInfo::TimeInfo(int offset) : offset(offset) {}
3+
TimeInfo::TimeInfo(int offset, bool isDst) : offset(offset), isDst(isDst) {}
44

55
int TimeInfo::GetOffset() const { return offset; }
66

77
void TimeInfo::SetOffset(int value) { offset = value; }
88

9+
bool TimeInfo::IsDst() const { return isDst; }
10+
11+
void TimeInfo::SetDst(bool value) { isDst = value; }
12+
913
JsonDocument TimeInfo::ToJson() const {
1014
JsonDocument doc;
1115
doc["offset"] = offset;
16+
doc["isDst"] = static_cast<uint8_t>(isDst);
1217
return doc;
1318
}

firmware/src/WebServer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,15 @@ void WebServer::HandleSetTimeInfo(AsyncWebServerRequest* request,
219219
return;
220220
}
221221
JsonDocument requestBody = json.as<JsonObject>();
222-
if (!requestBody.containsKey("offset")) {
222+
if (!requestBody.containsKey("offset") ||
223+
!requestBody.containsKey("isDst")) {
223224
request->send(HTTP_400_BAD_REQUEST,
224225
"Error HandleSetTimeInfo: missing argument(s)!");
225226
return;
226227
}
227228
int offset = requestBody["offset"];
228-
TimeInfo ti(offset);
229+
uint8_t isDst = requestBody["isDst"];
230+
TimeInfo ti(offset, isDst);
229231
callback.OnSetTimeInfo(ti);
230232
request->send(HTTP_200_OK, "");
231233
}

firmware/src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <ArduinoJson.h>
2-
#include <base64.hpp>
32
#include <DNSServer.h>
4-
#include <ESP8266mDNS.h>
53
#include <ESP8266WiFi.h>
4+
#include <ESP8266mDNS.h>
65
#include <LittleFS.h>
76
#include <RtcDS3231.h>
87
#include <Ticker.h>
98
#include <WiFiClient.h>
109
#include <Wire.h>
10+
#include <base64.hpp>
1111

1212
#include "ConfigStore.h"
1313
#include "In14NixieTube.h"
@@ -187,7 +187,7 @@ void setup() {
187187

188188
TimeInfo ti;
189189
ConfigStore::LoadTimeInfo(ti);
190-
timeManager.Initialize(ti.GetOffset());
190+
timeManager.Initialize(ti.GetOffset() + (ti.IsDst() ? 3600 : 0));
191191
SynchroniseTime();
192192

193193
Serial.printf("Initializing timer(s)... ");

0 commit comments

Comments
 (0)