Files
MeshCore/variants/m5stack_cardputer_adv/CardputerDataStore.h
T
mikecarper 9a2211e85a Fix Cardputer delivery, live settings and power management
Keep selected chats bound to full contact keys and route keyboard channel sends through the active transport. Deliver accepted plain, room and Meshtext messages to local history and notifications once; disarm rejected sends and retries.

Use shared live radio settings, GPS acquisition and power-saving policy, screen timers and red night palette. Report save failures, preserve verified custom preferences, and guard display controls and shutdown.

Add executable sanitizer regressions for routing, retries, selection, storage faults, UI lifecycle and GPS. Both Companion builds and the shared T-Deck regression pass; no physical Cardputer testing performed.
2026-10-27 22:59:26 -07:00

42 lines
1.4 KiB
C++

#pragma once
#include <DataStore.h>
#include "globals.h"
#include "RingBuffer.h"
//** Custom node preferences, persisted to file. Power saving is the
// companion's own powersaving_enabled pref (shared with the CLI). */
struct __attribute__((packed)) CustomNodePrefs {
float battery_correction;
uint8_t brightness;
uint8_t text_level; // CardputerDisplay::TextLevel
};
struct HistoryMessage {
char text[MAX_MESSAGE_LENGTH];
bool out;
};
using ChatHistory = RingBuffer<HistoryMessage, CHAT_HISTORY_RINGBUF_SIZE>;
// Contacts, channels and node prefs stay on the primary (internal) FS managed
// by DataStore. Cardputer UI prefs live there too; per-chat history is kept
// only when a microSD card is mounted.
class CardputerDataStore : public DataStore {
private:
FILESYSTEM *_fs;
FILESYSTEM *_history_fs = nullptr;
bool _custom_prefs_write_blocked = false;
public:
CardputerDataStore(FILESYSTEM &fs, mesh::RTCClock &clock) : DataStore(fs, clock), _fs(&fs) {}
// Call after the SD card is mounted (or not); nullptr disables history.
void beginCustom(FILESYSTEM *history_fs);
bool hasHistory() const { return _history_fs != nullptr; }
bool loadCustomPrefs(CustomNodePrefs &prefs);
bool saveCustomPrefs(const CustomNodePrefs &prefs);
void storeMessage(const uint8_t pkey[PUB_KEY_SIZE], const char *text, bool is_sent, bool is_channel);
void loadMessages(const uint8_t pkey[PUB_KEY_SIZE], bool is_channel, ChatHistory &history);
};