mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-02 16:10:43 +00:00
fix for message time
This commit is contained in:
@@ -338,9 +338,8 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O
|
||||
uint8_t TFT_MESH_b = rawRGB & 0xFF;
|
||||
LOG_INFO("Values of r,g,b: %d, %d, %d", TFT_MESH_r, TFT_MESH_g, TFT_MESH_b);
|
||||
|
||||
if (TFT_MESH_r <= 255 && TFT_MESH_g <= 255 && TFT_MESH_b <= 255) {
|
||||
TFT_MESH = COLOR565(TFT_MESH_r, TFT_MESH_g, TFT_MESH_b);
|
||||
}
|
||||
// Values are always 0–255, no need to check
|
||||
TFT_MESH = COLOR565(TFT_MESH_r, TFT_MESH_g, TFT_MESH_b);
|
||||
}
|
||||
|
||||
#if defined(USE_SH1106) || defined(USE_SH1107) || defined(USE_SH1107_128_64)
|
||||
@@ -801,6 +800,7 @@ int32_t Screen::runOnce()
|
||||
break;
|
||||
case Cmd::STOP_ALERT_FRAME:
|
||||
NotificationRenderer::pauseBanner = false;
|
||||
break;
|
||||
case Cmd::STOP_BOOT_SCREEN:
|
||||
EINK_ADD_FRAMEFLAG(dispdev, COSMETIC); // E-Ink: Explicitly use full-refresh for next frame
|
||||
if (NotificationRenderer::current_notification_type != notificationTypeEnum::text_input) {
|
||||
@@ -971,9 +971,6 @@ void Screen::setFrames(FrameFocus focus)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Declare this early so it’s available in FOCUS_PRESERVE block
|
||||
bool willInsertTextMessage = shouldDrawMessage(&devicestate.rx_text_message);
|
||||
|
||||
if (!hiddenFrames.home) {
|
||||
fsi.positions.home = numframes;
|
||||
normalFrames[numframes++] = graphics::UIRenderer::drawDeviceFocused;
|
||||
@@ -1441,7 +1438,17 @@ int Screen::handleTextMessage(const meshtastic_MeshPacket *packet)
|
||||
|
||||
// === Save our own outgoing message to live RAM ===
|
||||
StoredMessage sm;
|
||||
sm.timestamp = millis() / 1000;
|
||||
|
||||
// Always use our local time
|
||||
uint32_t nowSecs = getValidTime(RTCQuality::RTCQualityDevice, true);
|
||||
if (nowSecs > 0) {
|
||||
sm.timestamp = nowSecs;
|
||||
sm.isBootRelative = false;
|
||||
} else {
|
||||
sm.timestamp = millis() / 1000;
|
||||
sm.isBootRelative = true; // mark for later upgrade
|
||||
}
|
||||
|
||||
sm.sender = nodeDB->getNodeNum(); // us
|
||||
sm.channelIndex = packet->channel;
|
||||
sm.text = std::string(reinterpret_cast<const char *>(packet->decoded.payload.bytes));
|
||||
@@ -1524,7 +1531,17 @@ int Screen::handleTextMessage(const meshtastic_MeshPacket *packet)
|
||||
|
||||
// === Save this incoming message to live RAM ===
|
||||
StoredMessage sm;
|
||||
sm.timestamp = packet->rx_time ? packet->rx_time : (millis() / 1000);
|
||||
|
||||
// Always use our local time
|
||||
uint32_t nowSecs = getValidTime(RTCQuality::RTCQualityDevice, true);
|
||||
if (nowSecs > 0) {
|
||||
sm.timestamp = nowSecs;
|
||||
sm.isBootRelative = false;
|
||||
} else {
|
||||
sm.timestamp = millis() / 1000;
|
||||
sm.isBootRelative = true; // mark for later upgrade
|
||||
}
|
||||
|
||||
sm.sender = packet->from;
|
||||
sm.channelIndex = packet->channel;
|
||||
sm.text = std::string(reinterpret_cast<const char *>(packet->decoded.payload.bytes));
|
||||
|
||||
@@ -57,8 +57,6 @@ namespace graphics
|
||||
namespace MessageRenderer
|
||||
{
|
||||
|
||||
// Simple cache based on text hash
|
||||
static size_t cachedKey = 0;
|
||||
static std::vector<std::string> cachedLines;
|
||||
static std::vector<int> cachedHeights;
|
||||
|
||||
@@ -249,6 +247,9 @@ const std::vector<uint32_t> &getSeenPeers()
|
||||
|
||||
void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
{
|
||||
// Ensure any boot-relative timestamps are upgraded if RTC is valid
|
||||
messageStore.upgradeBootRelativeTimestamps();
|
||||
|
||||
if (!didReset) {
|
||||
resetScrollState();
|
||||
didReset = true;
|
||||
@@ -375,12 +376,33 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
||||
snprintf(chanType, sizeof(chanType), "(DM)");
|
||||
}
|
||||
}
|
||||
// else: leave empty for thread views
|
||||
|
||||
// Calculate how long ago
|
||||
uint32_t nowSecs = millis() / 1000;
|
||||
uint32_t seconds = (nowSecs > m.timestamp) ? (nowSecs - m.timestamp) : 0;
|
||||
bool invalidTime = (m.timestamp == 0 || seconds > 315360000); // >10 years
|
||||
uint32_t nowSecs = getValidTime(RTCQuality::RTCQualityDevice, true);
|
||||
uint32_t seconds = 0;
|
||||
bool invalidTime = true;
|
||||
|
||||
if (m.timestamp > 0 && nowSecs > 0) {
|
||||
if (nowSecs >= m.timestamp) {
|
||||
seconds = nowSecs - m.timestamp;
|
||||
invalidTime = (seconds > 315360000); // >10 years
|
||||
} else {
|
||||
uint32_t ahead = m.timestamp - nowSecs;
|
||||
if (ahead <= 600) { // allow small skew
|
||||
seconds = 0;
|
||||
invalidTime = false;
|
||||
}
|
||||
}
|
||||
} else if (m.timestamp > 0 && nowSecs == 0) {
|
||||
// RTC not valid: only trust boot-relative if same boot
|
||||
uint32_t bootNow = millis() / 1000;
|
||||
if (m.isBootRelative && m.timestamp <= bootNow) {
|
||||
seconds = bootNow - m.timestamp;
|
||||
invalidTime = false;
|
||||
} else {
|
||||
invalidTime = true; // old persisted boot-relative, ignore until healed
|
||||
}
|
||||
}
|
||||
|
||||
char timeBuf[16];
|
||||
if (invalidTime) {
|
||||
@@ -492,7 +514,6 @@ void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
||||
}
|
||||
}
|
||||
|
||||
// Draw screen title header last
|
||||
graphics::drawCommonHeader(display, x, y, titleStr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user