Skip to content

Commit

Permalink
Merge branch 'master' into hdzero-osd
Browse files Browse the repository at this point in the history
  • Loading branch information
pkendall64 committed May 20, 2023
2 parents 7454692 + 0a10cb4 commit f929048
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 10 deletions.
4 changes: 4 additions & 0 deletions html/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function get_mode() {
var data = JSON.parse(this.responseText);
if (data.mode==="STA") {
_('stamode').style.display = 'block';
_('rtctab').style.display = 'block';
_('ssid').textContent = data.ssid;
} else {
_('apmode').style.display = 'block';
Expand Down Expand Up @@ -347,6 +348,9 @@ _('forget').addEventListener('click', callback("Forget Home Network", "An error
if (_('modelmatch') != undefined) {
_('modelmatch').addEventListener('submit', callback("Set Model Match", "An error occurred updating the model match number", "/model", null));
}
_('setrtc').addEventListener('submit', callback("Set RTC Time", "An error occured setting the RTC time", "/setrtc", function() {
return new FormData(_('setrtc'));
}));

//=========================================================

Expand Down
24 changes: 24 additions & 0 deletions html/vrx_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>Welcome to your <b>ExpressLRS</b><br /> update page<br />
<ul class="mui-tabs__bar mui-tabs__bar--justified">
<li class="mui--is-active"><a data-mui-toggle="tab" data-mui-controls="pane-justified-1">Update</a></li>
<li><a data-mui-toggle="tab" data-mui-controls="pane-justified-2">Network</a></li>
<li id="rtctab" style="display:none;"><a data-mui-toggle="tab" data-mui-controls="pane-justified-3">RTC Time</a></li>
</ul>

<div class="mui-tabs__pane mui--is-active" id="pane-justified-1">
Expand Down Expand Up @@ -81,6 +82,29 @@ <h2>Home Network: <span id="ssid"></span></h2>
<a id="access" href="#" class="mui-btn mui-btn--primary">Disconnect</a>
</div>
</div>

<div class="mui-tabs__pane" id="pane-justified-3">
<div class="mui-panel">
<h2>RTC Update via NTP</h2>
Here you can update your goggle RTC clock time using any available NTP server.
Make sure that the home network you're connected to has access to the Internet in order to connect to the NTP server.
<form action="/setrtc" id="setrtc" method="POST" class="mui-form">
<div class="mui-textfield" style="width: 50%;">
<input id="server" type="text" name="server" value="pool.ntp.org"/>
</div>
<div class="mui-textfield" style="width: 50%;">
<input id="offset" type="number" name="offset" min="-12" max="12" placeholder="UTC Offset"/>
</div>
<div class="mui-checkbox">
<label>
<input id="dst" type="checkbox" name="dst" checked>
Daylight Saving
</label>
</div>
<input type="submit" value="Set Time" class="mui-btn mui-btn--primary">
</form>
</div>
</div>
</div>
</div>
<footer>
Expand Down
1 change: 1 addition & 0 deletions lib/MSP/msptypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define MSP_ELRS_BACKPACK_SET_BUZZER 0x030B
#define MSP_ELRS_BACKPACK_SET_OSD_ELEMENT 0x030C
#define MSP_ELRS_BACKPACK_SET_HEAD_TRACKING 0x030D // enable/disable head-tracking forwarding packets to the TX
#define MSP_ELRS_BACKPACK_SET_RTC 0x030E

// incoming, packets originating from the VRx
#define MSP_ELRS_BACKPACK_SET_MODE 0x0380 // enable wifi/binding mode
Expand Down
30 changes: 30 additions & 0 deletions lib/WIFI/devWIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
#include "helpers.h"

#include "UpdateWrapper.h"
#include "time.h"

#include "WebContent.h"

#include "config.h"
#if defined(TARGET_VRX_BACKPACK)
extern VrxBackpackConfig config;
extern bool sendRTCChangesToVrx;
#else
extern TxBackpackConfig config;
#endif
Expand Down Expand Up @@ -422,6 +424,33 @@ static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) {
}
}

static void WebUploadRTCUpdateHandler(AsyncWebServerRequest *request) {
static String ntpServer = request->arg("server");
long offset = request->arg("offset").toInt();
long dst = request->arg("dst") == "on" ? 3600 : 0;
long utcOffset = offset < 0 ? (12 + abs(offset)) * 3600 : offset * 3600;

DBGLN("Getting NTP data from %s", ntpServer.c_str());
configTime(dst, utcOffset, ntpServer.c_str());

tm timeData;
AsyncWebServerResponse *response;
if(!getLocalTime(&timeData)) {
response = request->beginResponse(500);
}
else {
response = request->beginResponse(200, "text/plain", "RTC clock synced with NTP server.");
}

response->addHeader("Connection", "close");
request->send(response);
request->client()->close();

#if defined(TARGET_VRX_BACKPACK)
sendRTCChangesToVrx = true;
#endif
}

static void wifiOff()
{
wifiStarted = false;
Expand Down Expand Up @@ -554,6 +583,7 @@ static void startServices()

server.on("/update", HTTP_POST, WebUploadResponseHandler, WebUploadDataHandler);
server.on("/forceupdate", WebUploadForceUpdateHandler);
server.on("/setrtc", WebUploadRTCUpdateHandler);

server.on("/log.js", WebUpdateSendContent);
server.on("/log.html", WebUpdateSendContent);
Expand Down
6 changes: 6 additions & 0 deletions src/Vrx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ unsigned long rebootTime = 0;
uint8_t cachedIndex = 0;
bool sendChannelChangesToVrx = false;
bool sendHeadTrackingChangesToVrx = false;
bool sendRTCChangesToVrx = false;
bool gotInitialPacket = false;
bool headTrackingEnabled = false;
uint32_t lastSentRequest = 0;
Expand Down Expand Up @@ -445,6 +446,11 @@ void loop()

if (connectionState == wifiUpdate)
{
if (sendRTCChangesToVrx)
{
sendRTCChangesToVrx = false;
vrxModule.SetRTC();
}
return;
}

Expand Down
24 changes: 24 additions & 0 deletions src/hdzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "hdzero.h"
#include "msptypes.h"
#include "logging.h"
#include "time.h"

void
HDZero::Init()
Expand Down Expand Up @@ -115,3 +116,26 @@ HDZero::SetOSD(mspPacket_t *packet)
MSP msp;
msp.sendPacket(packet, m_port);
}

void
HDZero::SetRTC()
{
MSP msp;
mspPacket_t packet;
tm timeData;
if(!getLocalTime(&timeData)) {
DBGLN("Could not obtain time data.");
return;
}
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_SET_RTC;
packet.addByte(timeData.tm_year);
packet.addByte(timeData.tm_mon);
packet.addByte(timeData.tm_mday);
packet.addByte(timeData.tm_hour);
packet.addByte(timeData.tm_min);
packet.addByte(timeData.tm_sec);

msp.sendPacket(&packet, m_port);
}
1 change: 1 addition & 0 deletions src/hdzero.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class HDZero : public MSPModuleBase
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SendHeadTrackingEnableCmd(bool enable);
void SetOSD(mspPacket_t *packet);
void SetRTC();
};
5 changes: 5 additions & 0 deletions src/module_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ ModuleBase::SendHeadTrackingEnableCmd(bool enable)
{
}

void
ModuleBase::SetRTC()
{
}

void
ModuleBase::Loop(uint32_t now)
{
Expand Down
1 change: 1 addition & 0 deletions src/module_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ModuleBase
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SetOSD(mspPacket_t *packet);
void SendHeadTrackingEnableCmd(bool enable);
void SetRTC();
void Loop(uint32_t now);
};

Expand Down
2 changes: 1 addition & 1 deletion targets/common.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ------------------------- COMMON ENV DEFINITIONS -----------------
[env]
platform = espressif8266@3.2.0
platform = espressif8266@4.2.0
framework = arduino
extra_scripts =
pre:python/build_flags.py
Expand Down
18 changes: 9 additions & 9 deletions targets/hdzero.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# VRX backpack targets
# ********************************

[env:HDZero_RX5.1_ESP8285_Backpack_via_UART]
[env:HDZero_RX51_ESP8285_Backpack_via_UART]
extends = env_common_esp8285, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
${env_common_esp8285.build_flags}
${hdzero_vrx_backpack_common.build_flags}
-D PIN_LED=16

[env:HDZero_RX5.1_ESP8285_Backpack_via_WIFI]
extends = env:HDZero_RX5.1_ESP8285_Backpack_via_UART
[env:HDZero_RX51_ESP8285_Backpack_via_WIFI]
extends = env:HDZero_RX51_ESP8285_Backpack_via_UART

[env:HDZero_RX5.1_ESP32_Backpack_via_UART]
[env:HDZero_RX51_ESP32_Backpack_via_UART]
extends = env_common_esp32, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
Expand All @@ -22,10 +22,10 @@ build_flags =
-D PIN_LED=4
lib_ignore = STM32UPDATE

[env:HDZero_RX5.1_ESP32_Backpack_via_WIFI]
extends = env:HDZero_RX5.1_ESP32_Backpack_via_UART
[env:HDZero_RX51_ESP32_Backpack_via_WIFI]
extends = env:HDZero_RX51_ESP32_Backpack_via_UART

[env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_UART]
[env:HDZero_Goggle_ESP32_Backpack_via_UART]
extends = env_common_esp32, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
Expand All @@ -35,5 +35,5 @@ build_flags =
-D NO_AUTOBIND=1
lib_ignore = STM32UPDATE

[env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_WIFI]
extends = env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_UART
[env:HDZero_Goggle_ESP32_Backpack_via_WIFI]
extends = env:HDZero_Goggle_ESP32_Backpack_via_UART

0 comments on commit f929048

Please sign in to comment.