Default fresh settings to sound off and vibration on, and keep existing saved choices. Apply changes immediately across all three UIs and make custom notification patterns respect the same mute controls. Keep the Wio Mini Companion within its existing flash boundary by storing its LED switch in a reserved preference byte and shortening CLI help without removing commands. Add coverage for live output changes, persistence, and storage failures. Adapted from https://github.com/meshcore-dev/MeshCore/pull/3603. Co-authored-by: R0ck <develop@hectospark.co.uk>
145 lines
3.8 KiB
C++
145 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include <MeshCore.h>
|
|
#include <helpers/ui/DisplayDriver.h>
|
|
#include <helpers/ui/UIScreen.h>
|
|
#include <helpers/SensorManager.h>
|
|
#include <helpers/MultiSerialInterface.h>
|
|
#include <Arduino.h>
|
|
#include <helpers/sensors/LPPDataHelpers.h>
|
|
|
|
#include "ScrollingStatusBar.h"
|
|
|
|
|
|
#ifndef LED_STATE_ON
|
|
#define LED_STATE_ON 1
|
|
#endif
|
|
|
|
#ifdef PIN_BUZZER
|
|
#include <helpers/ui/buzzer.h>
|
|
#endif
|
|
#ifdef HAS_DRV2605
|
|
#include <helpers/ui/DRV2605Vibration.h>
|
|
#elif defined(PIN_VIBRATION)
|
|
#include <helpers/ui/GenericVibration.h>
|
|
#endif
|
|
|
|
#include "../AbstractUITask.h"
|
|
#include "../NodePrefs.h"
|
|
|
|
class UITask : public AbstractUITask {
|
|
DisplayDriver* _display;
|
|
SensorManager* _sensors;
|
|
ScrollingStatusBar _statusBar;
|
|
#ifdef PIN_BUZZER
|
|
genericBuzzer buzzer;
|
|
#endif
|
|
#ifdef HAS_DRV2605
|
|
DRV2605Vibration vibration;
|
|
#elif defined(PIN_VIBRATION)
|
|
GenericVibration vibration;
|
|
#endif
|
|
uint32_t _next_refresh;
|
|
CompanionNodePrefs* _node_prefs = nullptr;
|
|
char _alert[80];
|
|
uint32_t _alert_expiry;
|
|
unsigned long _pairing_screen_until;
|
|
int _msgcount;
|
|
unsigned long ui_started_at;
|
|
uint32_t next_batt_chck;
|
|
uint32_t last_backlight_btn_check = 0;
|
|
uint16_t _cached_batt_mv;
|
|
bool _startup_complete = false;
|
|
#ifdef PIN_STATUS_LED
|
|
int led_state = 0;
|
|
uint32_t last_led_change = 0;
|
|
uint32_t led_phase_millis = 0;
|
|
#endif
|
|
|
|
#ifdef PIN_USER_BTN_ANA
|
|
unsigned long _analogue_pin_read_millis = millis();
|
|
#endif
|
|
|
|
UIScreen* splash;
|
|
UIScreen* home;
|
|
#if UI_SMALL_MESSAGE_FONT == 1
|
|
UIScreen* msg_preview = nullptr;
|
|
bool _deferred_msg_preview = false;
|
|
unsigned long _msg_preview_until = 0;
|
|
#endif
|
|
UIScreen* curr;
|
|
|
|
|
|
void userLedHandler();
|
|
|
|
// Button action handlers
|
|
char checkDisplayOn(char c);
|
|
char handleLongPress(char c);
|
|
char handleDoubleClick(char c);
|
|
char handleTripleClick(char c);
|
|
|
|
void setCurrScreen(UIScreen* c);
|
|
bool isPairingScreenActive() const;
|
|
void showPairingPin();
|
|
void finishPairingScreen(bool timed_out);
|
|
|
|
public:
|
|
|
|
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
|
next_batt_chck = _next_refresh = 0;
|
|
_cached_batt_mv = 0;
|
|
_pairing_screen_until = 0;
|
|
ui_started_at = 0;
|
|
curr = NULL;
|
|
}
|
|
void begin(DisplayDriver* display, SensorManager* sensors, CompanionNodePrefs* node_prefs);
|
|
|
|
void gotoHomeScreen() { setCurrScreen(home); }
|
|
void showAlert(const char* text, int duration_millis);
|
|
int getMsgCount() const { return _msgcount; }
|
|
uint16_t getCachedBattMV() const { return _cached_batt_mv; }
|
|
bool hasDisplay() const { return _display != NULL; }
|
|
bool supportsDisplayRotation() const override {
|
|
return _display != NULL && _display->supportsRotation();
|
|
}
|
|
bool setDisplayRotationDegrees(uint16_t degrees) override {
|
|
if (_display == NULL || !_display->setRotationDegrees(degrees)) return false;
|
|
_next_refresh = millis();
|
|
return true;
|
|
}
|
|
bool isButtonPressed() const;
|
|
void servicePairingState() override;
|
|
bool isPairingPromptActive() const override {
|
|
return isPairingScreenActive();
|
|
}
|
|
|
|
bool isBuzzerQuiet() {
|
|
#ifdef PIN_BUZZER
|
|
return buzzer.isQuiet();
|
|
#else
|
|
return true;
|
|
#endif
|
|
}
|
|
|
|
void toggleBuzzer();
|
|
bool getGPSState();
|
|
void toggleGPS();
|
|
|
|
|
|
// from AbstractUITask
|
|
void msgRead(int msgcount) override;
|
|
void newMsg(uint8_t path_len, const char* from_name, const char* text,
|
|
int msgcount, int channel_idx = -1,
|
|
const char* channel_name = nullptr,
|
|
int queue_index = -1) override;
|
|
void notify(UIEventType t = UIEventType::none) override;
|
|
uint8_t notificationCapabilities() const override;
|
|
void notificationVibration(bool on) override;
|
|
void notificationMelody(const char* text) override;
|
|
void notificationScreen(int8_t mode) override;
|
|
void syncAlertPreferences() override;
|
|
void loop() override;
|
|
|
|
void shutdown(bool restart = false);
|
|
};
|