mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
Settings screen (UI_HAS_JOYSTICK_UPDOWN build variant): - Display brightness (5 levels, contrast curve tuned for SH1106 non-linearity) - Buzzer on/off (respected at startup, no more forced unmute) - TX power (2–22 dBm) - Auto-off delay (5s / 15s / 30s / 60s / never) - GPS update interval (off / 30s / 1min / 5min / 15min / 30min) - Timezone offset (UTC-12..+14) for clock screen - Low battery auto-shutdown threshold (off / 3.0–3.5V, default 3.4V) - Battery display mode (icon / % / voltage) Battery: - EMA filter (alpha=0.2) on ADC readings to smooth voltage spikes from uneven load - Battery % calculated using low_batt_mv as 0% anchor - Mute icon repositions dynamically based on battery display width Clock screen on HomeScreen showing time/date with timezone support. Build: - _settings variants added for USB and BLE companion radio builds - Automatic UF2 generation on every build via create-uf2.py post-script - UI_HAS_JOYSTICK_UPDOWN flag guards joystick_up/down to avoid breaking other boards Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
117 lines
3.0 KiB
C++
117 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include <MeshCore.h>
|
|
#include <helpers/ui/DisplayDriver.h>
|
|
#include <helpers/ui/UIScreen.h>
|
|
#include <helpers/SensorManager.h>
|
|
#include <helpers/BaseSerialInterface.h>
|
|
#include <Arduino.h>
|
|
#include <helpers/sensors/LPPDataHelpers.h>
|
|
|
|
#ifndef LED_STATE_ON
|
|
#define LED_STATE_ON 1
|
|
#endif
|
|
|
|
#ifdef PIN_BUZZER
|
|
#include <helpers/ui/buzzer.h>
|
|
#endif
|
|
#ifdef PIN_VIBRATION
|
|
#include <helpers/ui/GenericVibration.h>
|
|
#endif
|
|
|
|
#include "../AbstractUITask.h"
|
|
#include "../NodePrefs.h"
|
|
|
|
class UITask : public AbstractUITask {
|
|
DisplayDriver* _display;
|
|
SensorManager* _sensors;
|
|
#ifdef PIN_BUZZER
|
|
genericBuzzer buzzer;
|
|
#endif
|
|
#ifdef PIN_VIBRATION
|
|
GenericVibration vibration;
|
|
#endif
|
|
unsigned long _next_refresh, _auto_off;
|
|
NodePrefs* _node_prefs;
|
|
char _alert[80];
|
|
unsigned long _alert_expiry;
|
|
int _msgcount;
|
|
unsigned long ui_started_at, next_batt_chck;
|
|
uint16_t _batt_mv; // EMA-filtered battery voltage
|
|
int next_backlight_btn_check = 0;
|
|
#ifdef PIN_STATUS_LED
|
|
int led_state = 0;
|
|
int next_led_change = 0;
|
|
int last_led_increment = 0;
|
|
#endif
|
|
|
|
#ifdef PIN_USER_BTN_ANA
|
|
unsigned long _analogue_pin_read_millis = millis();
|
|
#endif
|
|
|
|
UIScreen* splash;
|
|
UIScreen* home;
|
|
UIScreen* msg_preview;
|
|
UIScreen* settings;
|
|
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);
|
|
|
|
public:
|
|
|
|
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
|
|
next_batt_chck = _next_refresh = 0;
|
|
ui_started_at = 0;
|
|
_batt_mv = 0;
|
|
curr = NULL;
|
|
}
|
|
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
|
|
|
|
NodePrefs* getNodePrefs() const { return _node_prefs; }
|
|
uint16_t getBattMilliVolts() const { return _batt_mv > 0 ? _batt_mv : AbstractUITask::getBattMilliVolts(); }
|
|
void gotoHomeScreen() { setCurrScreen(home); }
|
|
void gotoSettingsScreen() { setCurrScreen(settings); }
|
|
void showAlert(const char* text, int duration_millis);
|
|
int getMsgCount() const { return _msgcount; }
|
|
bool hasDisplay() const { return _display != NULL; }
|
|
bool isButtonPressed() const;
|
|
|
|
bool isBuzzerQuiet() {
|
|
#ifdef PIN_BUZZER
|
|
return buzzer.isQuiet();
|
|
#else
|
|
return true;
|
|
#endif
|
|
}
|
|
|
|
void toggleBuzzer();
|
|
bool getGPSState();
|
|
void toggleGPS();
|
|
void applyBrightness();
|
|
void setBrightnessLevel(uint8_t level);
|
|
uint8_t getBrightnessLevel() const { return _node_prefs ? _node_prefs->display_brightness : 2; }
|
|
void applyTxPower();
|
|
void applyGPSInterval();
|
|
uint32_t autoOffMillis() const {
|
|
if (!_node_prefs || _node_prefs->auto_off_secs == 0) return 0;
|
|
return (uint32_t)_node_prefs->auto_off_secs * 1000UL;
|
|
}
|
|
|
|
|
|
// from AbstractUITask
|
|
void msgRead(int msgcount) override;
|
|
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
|
|
void notify(UIEventType t = UIEventType::none) override;
|
|
void loop() override;
|
|
|
|
void shutdown(bool restart = false);
|
|
};
|