Skip to content

Commit f929048

Browse files
committed
Merge branch 'master' into hdzero-osd
2 parents 7454692 + 0a10cb4 commit f929048

File tree

11 files changed

+106
-10
lines changed

11 files changed

+106
-10
lines changed

html/scan.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function get_mode() {
1313
var data = JSON.parse(this.responseText);
1414
if (data.mode==="STA") {
1515
_('stamode').style.display = 'block';
16+
_('rtctab').style.display = 'block';
1617
_('ssid').textContent = data.ssid;
1718
} else {
1819
_('apmode').style.display = 'block';
@@ -347,6 +348,9 @@ _('forget').addEventListener('click', callback("Forget Home Network", "An error
347348
if (_('modelmatch') != undefined) {
348349
_('modelmatch').addEventListener('submit', callback("Set Model Match", "An error occurred updating the model match number", "/model", null));
349350
}
351+
_('setrtc').addEventListener('submit', callback("Set RTC Time", "An error occured setting the RTC time", "/setrtc", function() {
352+
return new FormData(_('setrtc'));
353+
}));
350354

351355
//=========================================================
352356

html/vrx_index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ <h1>Welcome to your <b>ExpressLRS</b><br /> update page<br />
2727
<ul class="mui-tabs__bar mui-tabs__bar--justified">
2828
<li class="mui--is-active"><a data-mui-toggle="tab" data-mui-controls="pane-justified-1">Update</a></li>
2929
<li><a data-mui-toggle="tab" data-mui-controls="pane-justified-2">Network</a></li>
30+
<li id="rtctab" style="display:none;"><a data-mui-toggle="tab" data-mui-controls="pane-justified-3">RTC Time</a></li>
3031
</ul>
3132

3233
<div class="mui-tabs__pane mui--is-active" id="pane-justified-1">
@@ -81,6 +82,29 @@ <h2>Home Network: <span id="ssid"></span></h2>
8182
<a id="access" href="#" class="mui-btn mui-btn--primary">Disconnect</a>
8283
</div>
8384
</div>
85+
86+
<div class="mui-tabs__pane" id="pane-justified-3">
87+
<div class="mui-panel">
88+
<h2>RTC Update via NTP</h2>
89+
Here you can update your goggle RTC clock time using any available NTP server.
90+
Make sure that the home network you're connected to has access to the Internet in order to connect to the NTP server.
91+
<form action="/setrtc" id="setrtc" method="POST" class="mui-form">
92+
<div class="mui-textfield" style="width: 50%;">
93+
<input id="server" type="text" name="server" value="pool.ntp.org"/>
94+
</div>
95+
<div class="mui-textfield" style="width: 50%;">
96+
<input id="offset" type="number" name="offset" min="-12" max="12" placeholder="UTC Offset"/>
97+
</div>
98+
<div class="mui-checkbox">
99+
<label>
100+
<input id="dst" type="checkbox" name="dst" checked>
101+
Daylight Saving
102+
</label>
103+
</div>
104+
<input type="submit" value="Set Time" class="mui-btn mui-btn--primary">
105+
</form>
106+
</div>
107+
</div>
84108
</div>
85109
</div>
86110
<footer>

lib/MSP/msptypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define MSP_ELRS_BACKPACK_SET_BUZZER 0x030B
4444
#define MSP_ELRS_BACKPACK_SET_OSD_ELEMENT 0x030C
4545
#define MSP_ELRS_BACKPACK_SET_HEAD_TRACKING 0x030D // enable/disable head-tracking forwarding packets to the TX
46+
#define MSP_ELRS_BACKPACK_SET_RTC 0x030E
4647

4748
// incoming, packets originating from the VRx
4849
#define MSP_ELRS_BACKPACK_SET_MODE 0x0380 // enable wifi/binding mode

lib/WIFI/devWIFI.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
#include "helpers.h"
2626

2727
#include "UpdateWrapper.h"
28+
#include "time.h"
2829

2930
#include "WebContent.h"
3031

3132
#include "config.h"
3233
#if defined(TARGET_VRX_BACKPACK)
3334
extern VrxBackpackConfig config;
35+
extern bool sendRTCChangesToVrx;
3436
#else
3537
extern TxBackpackConfig config;
3638
#endif
@@ -422,6 +424,33 @@ static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) {
422424
}
423425
}
424426

427+
static void WebUploadRTCUpdateHandler(AsyncWebServerRequest *request) {
428+
static String ntpServer = request->arg("server");
429+
long offset = request->arg("offset").toInt();
430+
long dst = request->arg("dst") == "on" ? 3600 : 0;
431+
long utcOffset = offset < 0 ? (12 + abs(offset)) * 3600 : offset * 3600;
432+
433+
DBGLN("Getting NTP data from %s", ntpServer.c_str());
434+
configTime(dst, utcOffset, ntpServer.c_str());
435+
436+
tm timeData;
437+
AsyncWebServerResponse *response;
438+
if(!getLocalTime(&timeData)) {
439+
response = request->beginResponse(500);
440+
}
441+
else {
442+
response = request->beginResponse(200, "text/plain", "RTC clock synced with NTP server.");
443+
}
444+
445+
response->addHeader("Connection", "close");
446+
request->send(response);
447+
request->client()->close();
448+
449+
#if defined(TARGET_VRX_BACKPACK)
450+
sendRTCChangesToVrx = true;
451+
#endif
452+
}
453+
425454
static void wifiOff()
426455
{
427456
wifiStarted = false;
@@ -554,6 +583,7 @@ static void startServices()
554583

555584
server.on("/update", HTTP_POST, WebUploadResponseHandler, WebUploadDataHandler);
556585
server.on("/forceupdate", WebUploadForceUpdateHandler);
586+
server.on("/setrtc", WebUploadRTCUpdateHandler);
557587

558588
server.on("/log.js", WebUpdateSendContent);
559589
server.on("/log.html", WebUpdateSendContent);

src/Vrx_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ unsigned long rebootTime = 0;
6969
uint8_t cachedIndex = 0;
7070
bool sendChannelChangesToVrx = false;
7171
bool sendHeadTrackingChangesToVrx = false;
72+
bool sendRTCChangesToVrx = false;
7273
bool gotInitialPacket = false;
7374
bool headTrackingEnabled = false;
7475
uint32_t lastSentRequest = 0;
@@ -445,6 +446,11 @@ void loop()
445446

446447
if (connectionState == wifiUpdate)
447448
{
449+
if (sendRTCChangesToVrx)
450+
{
451+
sendRTCChangesToVrx = false;
452+
vrxModule.SetRTC();
453+
}
448454
return;
449455
}
450456

src/hdzero.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "hdzero.h"
33
#include "msptypes.h"
44
#include "logging.h"
5+
#include "time.h"
56

67
void
78
HDZero::Init()
@@ -115,3 +116,26 @@ HDZero::SetOSD(mspPacket_t *packet)
115116
MSP msp;
116117
msp.sendPacket(packet, m_port);
117118
}
119+
120+
void
121+
HDZero::SetRTC()
122+
{
123+
MSP msp;
124+
mspPacket_t packet;
125+
tm timeData;
126+
if(!getLocalTime(&timeData)) {
127+
DBGLN("Could not obtain time data.");
128+
return;
129+
}
130+
packet.reset();
131+
packet.makeCommand();
132+
packet.function = MSP_ELRS_BACKPACK_SET_RTC;
133+
packet.addByte(timeData.tm_year);
134+
packet.addByte(timeData.tm_mon);
135+
packet.addByte(timeData.tm_mday);
136+
packet.addByte(timeData.tm_hour);
137+
packet.addByte(timeData.tm_min);
138+
packet.addByte(timeData.tm_sec);
139+
140+
msp.sendPacket(&packet, m_port);
141+
}

src/hdzero.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class HDZero : public MSPModuleBase
2525
void SetRecordingState(uint8_t recordingState, uint16_t delay);
2626
void SendHeadTrackingEnableCmd(bool enable);
2727
void SetOSD(mspPacket_t *packet);
28+
void SetRTC();
2829
};

src/module_base.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ ModuleBase::SendHeadTrackingEnableCmd(bool enable)
3737
{
3838
}
3939

40+
void
41+
ModuleBase::SetRTC()
42+
{
43+
}
44+
4045
void
4146
ModuleBase::Loop(uint32_t now)
4247
{

src/module_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ModuleBase
1111
void SetRecordingState(uint8_t recordingState, uint16_t delay);
1212
void SetOSD(mspPacket_t *packet);
1313
void SendHeadTrackingEnableCmd(bool enable);
14+
void SetRTC();
1415
void Loop(uint32_t now);
1516
};
1617

targets/common.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ------------------------- COMMON ENV DEFINITIONS -----------------
22
[env]
3-
platform = espressif8266@3.2.0
3+
platform = espressif8266@4.2.0
44
framework = arduino
55
extra_scripts =
66
pre:python/build_flags.py

0 commit comments

Comments
 (0)