Notification banners implemented

This commit is contained in:
HarukiToreda
2025-05-08 22:00:57 -04:00
parent 581021031c
commit 14752caee5
7 changed files with 109 additions and 56 deletions

View File

@@ -1096,7 +1096,7 @@ void AdminModule::handleGetDeviceUIConfig(const meshtastic_MeshPacket &req)
void AdminModule::reboot(int32_t seconds)
{
LOG_INFO("Reboot in %d seconds", seconds);
screen->startAlert("Rebooting...");
screen->showOverlayBanner("Rebooting...", 0); // stays on screen
rebootAtMsec = (seconds < 0) ? 0 : (millis() + seconds * 1000);
}

View File

@@ -463,52 +463,57 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
break;
// mute (switch off/toggle) external notifications on fn+m
case INPUT_BROKER_MSG_MUTE_TOGGLE:
if (moduleConfig.external_notification.enabled == true) {
if (externalNotificationModule->getMute()) {
externalNotificationModule->setMute(false);
showTemporaryMessage("Notifications \nEnabled");
if (screen)
screen->removeFunctionSymbol("M"); // remove the mute symbol from the bottom right corner
} else {
externalNotificationModule->stopNow(); // this will turn off all GPIO and sounds and idle the loop
externalNotificationModule->setMute(true);
showTemporaryMessage("Notifications \nDisabled");
if (screen)
screen->setFunctionSymbol("M"); // add the mute symbol to the bottom right corner
if (moduleConfig.external_notification.enabled == true) {
if (externalNotificationModule->getMute()) {
externalNotificationModule->setMute(false);
if (screen) {
screen->removeFunctionSymbol("M");
screen->showOverlayBanner("Notifications\nEnabled", 3000);
}
} else {
externalNotificationModule->stopNow();
externalNotificationModule->setMute(true);
if (screen) {
screen->setFunctionSymbol("M");
screen->showOverlayBanner("Notifications\nDisabled", 3000);
}
}
break;
case INPUT_BROKER_MSG_GPS_TOGGLE: // toggle GPS like triple press does
#if !MESHTASTIC_EXCLUDE_GPS
}
break;
case INPUT_BROKER_MSG_GPS_TOGGLE:
#if !MESHTASTIC_EXCLUDE_GPS
if (gps != nullptr) {
gps->toggleGpsMode();
}
if (screen)
if (screen) {
screen->forceDisplay();
showTemporaryMessage("GPS Toggled");
#endif
screen->showOverlayBanner("GPS Toggled", 3000);
}
#endif
break;
case INPUT_BROKER_MSG_BLUETOOTH_TOGGLE: // toggle Bluetooth on/off
case INPUT_BROKER_MSG_BLUETOOTH_TOGGLE:
if (config.bluetooth.enabled == true) {
config.bluetooth.enabled = false;
LOG_INFO("User toggled Bluetooth");
nodeDB->saveToDisk();
disableBluetooth();
showTemporaryMessage("Bluetooth OFF");
} else if (config.bluetooth.enabled == false) {
if (screen) screen->showOverlayBanner("Bluetooth OFF", 3000);
} else {
config.bluetooth.enabled = true;
LOG_INFO("User toggled Bluetooth");
nodeDB->saveToDisk();
rebootAtMsec = millis() + 2000;
showTemporaryMessage("Bluetooth ON\nReboot");
if (screen) screen->showOverlayBanner("Bluetooth ON\nRebooting", 3000);
}
break;
case INPUT_BROKER_MSG_SEND_PING: // fn+space send network ping like double press does
case INPUT_BROKER_MSG_SEND_PING:
service->refreshLocalMeshNode();
if (service->trySendPosition(NODENUM_BROADCAST, true)) {
showTemporaryMessage("Position \nUpdate Sent");
if (screen) screen->showOverlayBanner("Position\nUpdate Sent", 3000);
} else {
showTemporaryMessage("Node Info \nUpdate Sent");
if (screen) screen->showOverlayBanner("Node Info\nUpdate Sent", 3000);
}
break;
case INPUT_BROKER_MSG_DISMISS_FRAME: // fn+del: dismiss screen frames like text or waypoint
@@ -869,14 +874,13 @@ int32_t CannedMessageModule::runOnce()
// handle fn+s for shutdown
case INPUT_BROKER_MSG_SHUTDOWN:
if (screen)
screen->startAlert("Shutting down...");
shutdownAtMsec = millis() + DEFAULT_SHUTDOWN_SECONDS * 1000;
runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
break;
// and fn+r for reboot
case INPUT_BROKER_MSG_REBOOT:
if (screen)
screen->startAlert("Rebooting...");
screen->showOverlayBanner("Rebooting...", 0); // stays on screen
rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000;
runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
break;

View File

@@ -402,14 +402,24 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
entries.push_back("Prss: " + String(m.barometric_pressure, 0) + " hPa");
if (m.iaq != 0) {
String aqi = "IAQ: " + String(m.iaq);
const char *bannerMsg = nullptr; // Default: no banner
if (m.iaq <= 50) aqi += " (Good)";
else if (m.iaq <= 100) aqi += " (Moderate)";
else if (m.iaq <= 150) aqi += " (Poor)";
else if (m.iaq <= 200) aqi += " (Unhealthy)";
else if (m.iaq <= 250) aqi += " (Very Unhealthy)";
else if (m.iaq <= 350) aqi += " (Hazardous)";
else aqi += " (Extreme)";
if (m.iaq <= 25) aqi += " (Excellent)";
else if (m.iaq <= 50) aqi += " (Good)";
else if (m.iaq <= 100) aqi += " (Moderate)";
else if (m.iaq <= 150) aqi += " (Poor)";
else if (m.iaq <= 200) {
aqi += " (Unhealthy)";
bannerMsg = "Unhealthy IAQ";
}
else if (m.iaq <= 300) {
aqi += " (Very Unhealthy)";
bannerMsg = "Very Unhealthy IAQ";
}
else {
aqi += " (Hazardous)";
bannerMsg = "Hazardous IAQ";
}
entries.push_back(aqi);
@@ -418,14 +428,17 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
uint32_t now = millis();
bool isOwnTelemetry = lastMeasurementPacket->from == nodeDB->getNodeNum();
bool isIAQAlert = m.iaq > 200 && (now - lastAlertTime > 60000);
bool isCooldownOver = (now - lastAlertTime > 60000);
if (isOwnTelemetry && isIAQAlert) {
LOG_INFO("drawFrame: IAQ %d (own) — showing banner", m.iaq);
screen->showOverlayBanner("Unhealthy IAQ Levels", 3000); // Always show banner
if (moduleConfig.external_notification.enabled && !externalNotificationModule->getMute()) {
playLongBeep(); // Only buzz if not muted
if (isOwnTelemetry && bannerMsg && isCooldownOver) {
LOG_INFO("drawFrame: IAQ %d (own) — showing banner: %s", m.iaq, bannerMsg);
screen->showOverlayBanner(bannerMsg, 3000);
// Only buzz if IAQ is over 200
if (m.iaq > 200 && moduleConfig.external_notification.enabled && !externalNotificationModule->getMute()) {
playLongBeep();
}
lastAlertTime = now;
}
}