mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
Fix time updates from client device and potentially incorrect UI frame receiving 'toggle watch face' button tap (#3974)
This commit is contained in:
parent
aa33ad1d58
commit
77cf5c6200
@ -96,13 +96,17 @@ void readFromRTC()
|
|||||||
*
|
*
|
||||||
* If we haven't yet set our RTC this boot, set it from a GPS derived time
|
* If we haven't yet set our RTC this boot, set it from a GPS derived time
|
||||||
*/
|
*/
|
||||||
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
|
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate)
|
||||||
{
|
{
|
||||||
static uint32_t lastSetMsec = 0;
|
static uint32_t lastSetMsec = 0;
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
bool shouldSet;
|
bool shouldSet;
|
||||||
if (q > currentQuality) {
|
if (forceUpdate) {
|
||||||
|
shouldSet = true;
|
||||||
|
LOG_DEBUG("Overriding current RTC quality (%s) with incoming time of RTC quality of %s\n", RtcName(currentQuality),
|
||||||
|
RtcName(q));
|
||||||
|
} else if (q > currentQuality) {
|
||||||
shouldSet = true;
|
shouldSet = true;
|
||||||
LOG_DEBUG("Upgrading time to quality %s\n", RtcName(q));
|
LOG_DEBUG("Upgrading time to quality %s\n", RtcName(q));
|
||||||
} else if (q >= RTCQualityNTP && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) {
|
} else if (q >= RTCQualityNTP && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) {
|
||||||
|
@ -25,7 +25,7 @@ enum RTCQuality {
|
|||||||
RTCQuality getRTCQuality();
|
RTCQuality getRTCQuality();
|
||||||
|
|
||||||
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
||||||
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv);
|
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate = false);
|
||||||
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
||||||
|
|
||||||
/// Return a string name for the quality
|
/// Return a string name for the quality
|
||||||
|
@ -1461,17 +1461,12 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
static char signalStr[20];
|
static char signalStr[20];
|
||||||
|
|
||||||
// section here to choose whether to display hops away rather than signal strength if more than 0 hops away.
|
// section here to choose whether to display hops away rather than signal strength if more than 0 hops away.
|
||||||
if(node->hops_away>0)
|
if (node->hops_away > 0) {
|
||||||
{
|
|
||||||
snprintf(signalStr, sizeof(signalStr), "Hops Away: %d", node->hops_away);
|
snprintf(signalStr, sizeof(signalStr), "Hops Away: %d", node->hops_away);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
snprintf(signalStr, sizeof(signalStr), "Signal: %d%%", clamp((int)((node->snr + 10) * 5), 0, 100));
|
snprintf(signalStr, sizeof(signalStr), "Signal: %d%%", clamp((int)((node->snr + 10) * 5), 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t agoSecs = sinceLastSeen(node);
|
uint32_t agoSecs = sinceLastSeen(node);
|
||||||
static char lastStr[20];
|
static char lastStr[20];
|
||||||
|
|
||||||
@ -2099,6 +2094,10 @@ void Screen::setFrames()
|
|||||||
if (error_code)
|
if (error_code)
|
||||||
normalFrames[numframes++] = drawCriticalFaultFrame;
|
normalFrames[numframes++] = drawCriticalFaultFrame;
|
||||||
|
|
||||||
|
#ifdef T_WATCH_S3
|
||||||
|
normalFrames[numframes++] = screen->digitalWatchFace ? &Screen::drawDigitalClockFrame : &Screen::drawAnalogClockFrame;
|
||||||
|
#endif
|
||||||
|
|
||||||
// If we have a text message - show it next, unless it's a phone message and we aren't using any special modules
|
// If we have a text message - show it next, unless it's a phone message and we aren't using any special modules
|
||||||
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
|
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
|
||||||
normalFrames[numframes++] = drawTextMessageFrame;
|
normalFrames[numframes++] = drawTextMessageFrame;
|
||||||
@ -2108,10 +2107,6 @@ void Screen::setFrames()
|
|||||||
normalFrames[numframes++] = drawWaypointFrame;
|
normalFrames[numframes++] = drawWaypointFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef T_WATCH_S3
|
|
||||||
normalFrames[numframes++] = screen->digitalWatchFace ? &Screen::drawDigitalClockFrame : &Screen::drawAnalogClockFrame;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// then all the nodes
|
// then all the nodes
|
||||||
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
|
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
|
||||||
size_t numToShow = min(numMeshNodes, 4U);
|
size_t numToShow = min(numMeshNodes, 4U);
|
||||||
@ -2686,8 +2681,10 @@ int Screen::handleInputEvent(const InputEvent *event)
|
|||||||
|
|
||||||
#ifdef T_WATCH_S3
|
#ifdef T_WATCH_S3
|
||||||
// For the T-Watch, intercept touches to the 'toggle digital/analog watch face' button
|
// For the T-Watch, intercept touches to the 'toggle digital/analog watch face' button
|
||||||
if (this->ui->getUiState()->currentFrame == 0 && event->touchX >= 204 && event->touchX <= 240 && event->touchY >= 204 &&
|
uint8_t watchFaceFrame = error_code ? 1 : 0;
|
||||||
event->touchY <= 240) {
|
|
||||||
|
if (this->ui->getUiState()->currentFrame == watchFaceFrame && event->touchX >= 204 && event->touchX <= 240 &&
|
||||||
|
event->touchY >= 204 && event->touchY <= 240) {
|
||||||
screen->digitalWatchFace = !screen->digitalWatchFace;
|
screen->digitalWatchFace = !screen->digitalWatchFace;
|
||||||
|
|
||||||
setFrames();
|
setFrames();
|
||||||
|
@ -55,6 +55,15 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
isLocal = true;
|
isLocal = true;
|
||||||
if (config.position.fixed_position) {
|
if (config.position.fixed_position) {
|
||||||
LOG_DEBUG("Ignore incoming position update from myself except for time, because position.fixed_position is true\n");
|
LOG_DEBUG("Ignore incoming position update from myself except for time, because position.fixed_position is true\n");
|
||||||
|
|
||||||
|
#ifdef T_WATCH_S3
|
||||||
|
// Since we return early if position.fixed_position is true, set the T-Watch's RTC to the time received from the
|
||||||
|
// client device here
|
||||||
|
if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
|
||||||
|
trySetRtc(p, isLocal, true);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
nodeDB->setLocalPosition(p, true);
|
nodeDB->setLocalPosition(p, true);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -71,8 +80,17 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
p.time);
|
p.time);
|
||||||
|
|
||||||
if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
|
if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
|
||||||
|
bool force = false;
|
||||||
|
|
||||||
|
#ifdef T_WATCH_S3
|
||||||
|
// The T-Watch appears to "pause" its RTC when shut down, such that the time it reads upon powering on is the same as when
|
||||||
|
// it was shut down. So we need to force the update here, since otherwise RTC::perhapsSetRTC will ignore it because it
|
||||||
|
// will always be an equivalent or lesser RTCQuality (RTCQualityNTP or RTCQualityNet).
|
||||||
|
force = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Set from phone RTC Quality to RTCQualityNTP since it should be approximately so
|
// Set from phone RTC Quality to RTCQualityNTP since it should be approximately so
|
||||||
trySetRtc(p, isLocal);
|
trySetRtc(p, isLocal, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeDB->updatePosition(getFrom(&mp), p);
|
nodeDB->updatePosition(getFrom(&mp), p);
|
||||||
@ -104,14 +122,14 @@ void PositionModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PositionModule::trySetRtc(meshtastic_Position p, bool isLocal)
|
void PositionModule::trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
uint32_t secs = p.time;
|
uint32_t secs = p.time;
|
||||||
|
|
||||||
tv.tv_sec = secs;
|
tv.tv_sec = secs;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv);
|
perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv, forceUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *PositionModule::allocReply()
|
meshtastic_MeshPacket *PositionModule::allocReply()
|
||||||
|
@ -54,7 +54,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
private:
|
private:
|
||||||
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
||||||
meshtastic_MeshPacket *allocAtakPli();
|
meshtastic_MeshPacket *allocAtakPli();
|
||||||
void trySetRtc(meshtastic_Position p, bool isLocal);
|
void trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate = false);
|
||||||
uint32_t precision;
|
uint32_t precision;
|
||||||
void sendLostAndFoundText();
|
void sendLostAndFoundText();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user