Add saved OLED controller selection on RAK boards
Allow Auto, SSD1306 or SH1106 through display.controller on display-enabled RAK4631 and RAK3401 roles. Persist the choice before restart without changing the active screen policy, and let saved Auto override legacy build defaults. Share checked settings I/O and the existing atomic writer to keep Full Companion within its flash boundary while retaining features and existing record formats. Cover save failures, backup recovery, startup selection and ambiguous OLED replies. Validation: 35 targeted host tests passed. RAK4631 Full Companion and RAK3401 unified LoRa OTA repeater build and package checks passed with release-length version strings.
This commit is contained in:
1 parent
e22d5d7d0a
commit
300b889bca
23 files changed
+955
-67
No files matched your search
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/IdentityStore.h>
|
||||
#include <string.h>
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include <helpers/AtomicFileWriter.h>
|
||||
#endif
|
||||
|
||||
namespace mesh { namespace storage {
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#define MESH_SETTINGS_FILE_SHARED __attribute__((noinline, noclone))
|
||||
#else
|
||||
#define MESH_SETTINGS_FILE_SHARED __attribute__((noinline))
|
||||
#endif
|
||||
|
||||
// Share the filesystem boundary between small settings records. Callers keep
|
||||
// their own format/version checks; no preference layout changes here.
|
||||
MESH_SETTINGS_FILE_SHARED inline bool readFixedSettingsFile(
|
||||
FILESYSTEM* fs, const char* path, uint8_t* data, size_t size) {
|
||||
if (!fs) return false;
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
File file(*fs);
|
||||
if (!file.open(path, FILE_O_READ)) return false;
|
||||
#else
|
||||
File file = fs->open(path, "r");
|
||||
if (!file) return false;
|
||||
#endif
|
||||
const bool complete = file.size() == size && file.read(data, size) == size;
|
||||
file.close();
|
||||
return complete;
|
||||
}
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
// Reuse the existing atomic writer and compare the complete public record as
|
||||
// well as its transaction checksum. Keep this uncommon path out of callers.
|
||||
MESH_SETTINGS_FILE_SHARED inline AtomicFileWriter::Outcome writeCheckedSettingsFile(
|
||||
FILESYSTEM* fs, const char* path, const uint8_t* data, size_t size) {
|
||||
using Outcome = AtomicFileWriter::Outcome;
|
||||
uint8_t verified[16];
|
||||
if (!fs || !data || size == 0 || size > sizeof(verified)) return Outcome::NotCommitted;
|
||||
AtomicFileWriter file(fs, path);
|
||||
if (!file || file.write(data, size) != size) return Outcome::NotCommitted;
|
||||
if (!file.commit()) return file.outcome();
|
||||
if (!readFixedSettingsFile(fs, path, verified, size)
|
||||
|| memcmp(data, verified, size) != 0) return Outcome::Indeterminate;
|
||||
return Outcome::Committed;
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef MESH_SETTINGS_FILE_SHARED
|
||||
|
||||
}} // namespace mesh::storage
|
||||
@@ -9,6 +9,9 @@
|
||||
#include "PowerSavingDiagnostics.h"
|
||||
#include "HilStartupTrace.h"
|
||||
#include <helpers/ui/DisplayPowerSettings.h>
|
||||
#if defined(OLED_AUTO_DETECT) && OLED_AUTO_DETECT && defined(DISPLAY_CLASS)
|
||||
#include <helpers/ui/OLEDControllerSettings.h>
|
||||
#endif
|
||||
#if defined(HELTEC_V4_R8_TFT) && defined(HELTEC_TFT_RUNTIME_ROTATION) \
|
||||
&& HELTEC_TFT_RUNTIME_ROTATION == 1
|
||||
#include <helpers/ui/DisplayRotationSettings.h>
|
||||
@@ -3060,6 +3063,9 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
return;
|
||||
}
|
||||
if (mesh::ui::handleDisplayPowerCommand(command, reply, 160)) return;
|
||||
#if defined(OLED_AUTO_DETECT) && OLED_AUTO_DETECT && defined(DISPLAY_CLASS)
|
||||
if (mesh::ui::handleOLEDControllerCommand(command, reply, 160, true)) return;
|
||||
#endif
|
||||
#if defined(HELTEC_V4_R8_TFT) && defined(HELTEC_TFT_RUNTIME_ROTATION) \
|
||||
&& HELTEC_TFT_RUNTIME_ROTATION == 1
|
||||
if (mesh::ui::handleDisplayRotationCommand(command, reply, 160, true)) return;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "LedSettings.h"
|
||||
#include "CheckedSettingsFile.h"
|
||||
#include <MeshCore.h>
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
#include <helpers/AtomicFileWriter.h>
|
||||
@@ -22,18 +23,8 @@ const uint8_t images[2][8] = {
|
||||
// Return the saved value, or -1 for an absent or invalid image. Comparing the
|
||||
// two canonical images shares the write format without a second encoder.
|
||||
int readSetting(const char* name) {
|
||||
if (!settings_fs) return -1;
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
File file(*settings_fs);
|
||||
if (!file.open(name, FILE_O_READ)) return -1;
|
||||
#else
|
||||
File file = settings_fs->open(name, "r");
|
||||
if (!file) return -1;
|
||||
#endif
|
||||
uint8_t data[8];
|
||||
const bool complete = file.size() == sizeof(data)
|
||||
&& file.read(data, sizeof(data)) == sizeof(data);
|
||||
file.close();
|
||||
const bool complete = storage::readFixedSettingsFile(settings_fs, name, data, sizeof(data));
|
||||
if (!complete || data[4] > 1
|
||||
|| memcmp(data, images[data[4]], sizeof(data)) != 0) return -1;
|
||||
return data[4];
|
||||
@@ -42,7 +33,11 @@ int readSetting(const char* name) {
|
||||
bool saveSetting(bool on) {
|
||||
if (!settings_fs) return false;
|
||||
const uint8_t* data = images[on ? 1 : 0];
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM)
|
||||
return storage::writeCheckedSettingsFile(settings_fs, path, data, sizeof(images[0]))
|
||||
== AtomicFileWriter::Outcome::Committed;
|
||||
#else
|
||||
#if defined(STM32_PLATFORM)
|
||||
AtomicFileWriter file(settings_fs, path);
|
||||
#else
|
||||
ContactFileTransaction file(settings_fs, path);
|
||||
@@ -50,6 +45,7 @@ bool saveSetting(bool on) {
|
||||
if (!file || file.write(data, sizeof(images[0])) != sizeof(images[0]) || !file.commit())
|
||||
return false;
|
||||
return readSetting(path) == int(on);
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "NRF52VoltageRules.h"
|
||||
#include "NRF52VoltagePolicy.h"
|
||||
#include "PersistentStoreFormat.h"
|
||||
#include "CheckedSettingsFile.h"
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include "AtomicFileWriter.h"
|
||||
#endif
|
||||
@@ -64,17 +65,7 @@ void encode(RegulatorMode mcu, RegulatorMode radio, uint8_t fallback, uint8_t (&
|
||||
storage::writeLE32(data + 8, storage::updateCRC32(0xffffffffUL, data, 8));
|
||||
}
|
||||
bool readFile(const char* name, uint8_t (&data)[12]) {
|
||||
if (!settings_fs) return false;
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
File file(*settings_fs);
|
||||
if (!file.open(name, FILE_O_READ)) return false;
|
||||
#else
|
||||
File file = settings_fs->open(name, "r");
|
||||
if (!file) return false;
|
||||
#endif
|
||||
const bool complete = file.size() == sizeof(data)
|
||||
&& file.read(data, sizeof(data)) == sizeof(data);
|
||||
file.close();
|
||||
const bool complete = storage::readFixedSettingsFile(settings_fs, name, data, sizeof(data));
|
||||
return complete && memcmp(data, "REG1", 4) == 0
|
||||
&& data[4] <= 2 && data[5] <= 2 && data[6] <= RECOVERY_DOMAINS
|
||||
&& data[7] == 0 && storage::readLE32(data + 8)
|
||||
@@ -83,17 +74,16 @@ bool readFile(const char* name, uint8_t (&data)[12]) {
|
||||
bool save(RegulatorMode mcu, RegulatorMode radio, uint8_t fallback) {
|
||||
if (!settings_fs) return false;
|
||||
#if defined(NRF52_PLATFORM)
|
||||
uint8_t data[12], checked[12];
|
||||
uint8_t data[12];
|
||||
if (uint8_t(mcu) > 2 || uint8_t(radio) > 2 || fallback > RECOVERY_DOMAINS) return false;
|
||||
encode(mcu, radio, fallback, data);
|
||||
// The shared LittleFS writer already stages, flushes, checks size/CRC32C,
|
||||
// atomically publishes and verifies the public file. Reuse it rather than
|
||||
// linking a second replacement transaction into flash-constrained targets.
|
||||
mesh::AtomicFileWriter file(settings_fs, path);
|
||||
if (!file || file.write(data, sizeof(data)) != sizeof(data) || !file.commit()) return false;
|
||||
// Retain the format validation and exact-byte comparison as well as the
|
||||
// writer's independent transaction checksum. Legacy .bak files remain
|
||||
// readable at boot and are retired only after this verified publication.
|
||||
if (!readFile(path, checked) || memcmp(data, checked, sizeof(data)) != 0) return false;
|
||||
if (storage::writeCheckedSettingsFile(settings_fs, path, data, sizeof(data))
|
||||
!= mesh::AtomicFileWriter::Outcome::Committed) return false;
|
||||
// The checked writer compares the complete encoded record after commit.
|
||||
// Retire legacy backups only after this verified publication.
|
||||
settings_fs->remove(backup);
|
||||
saved_fallback = fallback;
|
||||
return true;
|
||||
|
||||
@@ -20,7 +20,8 @@ class AutoOLEDBackend : public Adafruit_SSD1306 {
|
||||
public:
|
||||
using Adafruit_SSD1306::Adafruit_SSD1306;
|
||||
|
||||
bool begin(uint8_t vcc, uint8_t address, bool reset, bool periphBegin) {
|
||||
bool begin(uint8_t vcc, uint8_t address, bool reset, bool periphBegin,
|
||||
mesh::ui::OLEDControllerMode mode = mesh::ui::defaultOLEDControllerMode()) {
|
||||
_ready = false;
|
||||
i2caddr = address;
|
||||
if (periphBegin) wire->begin();
|
||||
@@ -33,16 +34,14 @@ public:
|
||||
digitalWrite(rstPin, HIGH);
|
||||
}
|
||||
|
||||
#if defined(OLED_CONTROLLER_OVERRIDE) && OLED_CONTROLLER_OVERRIDE != 0
|
||||
static_assert(OLED_CONTROLLER_OVERRIDE == 1 || OLED_CONTROLLER_OVERRIDE == 2,
|
||||
"OLED_CONTROLLER_OVERRIDE must be 0 (auto), 1 (SSD1306) or 2 (SH1106)");
|
||||
wire->beginTransmission(address);
|
||||
_controller = wire->endTransmission() != 0 ? mesh::ui::OLEDController::Absent
|
||||
: OLED_CONTROLLER_OVERRIDE == 2 ? mesh::ui::OLEDController::SH1106
|
||||
: mesh::ui::OLEDController::SSD1306;
|
||||
#else
|
||||
_controller = mesh::ui::detectOLEDController(*wire, address);
|
||||
#endif
|
||||
if (mode == mesh::ui::OLEDControllerMode::Auto) {
|
||||
_controller = mesh::ui::detectOLEDController(*wire, address);
|
||||
} else {
|
||||
wire->beginTransmission(address);
|
||||
_controller = wire->endTransmission() != 0 ? mesh::ui::OLEDController::Absent
|
||||
: mode == mesh::ui::OLEDControllerMode::SH1106 ? mesh::ui::OLEDController::SH1106
|
||||
: mesh::ui::OLEDController::SSD1306;
|
||||
}
|
||||
if (_controller == mesh::ui::OLEDController::Absent) return false;
|
||||
if (_controller == mesh::ui::OLEDController::SSD1306) {
|
||||
_ready = Adafruit_SSD1306::begin(vcc, address, false, false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "DisplayPowerSettings.h"
|
||||
#include "DisplayBuildFlags.h"
|
||||
#include <helpers/CheckedSettingsFile.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace mesh { namespace ui {
|
||||
@@ -9,7 +10,9 @@ bool pairing_available = false;
|
||||
FILESYSTEM* settings_fs = nullptr;
|
||||
const char* const path = "/display_prefs";
|
||||
const char* const backup = "/display_prefs.bak";
|
||||
#if !defined(NRF52_PLATFORM)
|
||||
const char* const temporary = "/display_prefs.tmp";
|
||||
#endif
|
||||
|
||||
// Explicit bytes avoid compiler padding and preserve a small fixed format.
|
||||
void encode(const DisplayPowerPrefs& prefs, uint8_t (&data)[12]) {
|
||||
@@ -22,18 +25,8 @@ void encode(const DisplayPowerPrefs& prefs, uint8_t (&data)[12]) {
|
||||
for (unsigned i = 0; i < 11; ++i) data[11] ^= data[i];
|
||||
}
|
||||
bool readPrefs(const char* name, DisplayPowerPrefs& prefs) {
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
File file(*settings_fs);
|
||||
if (!file.open(name, FILE_O_READ)) return false;
|
||||
#else
|
||||
File file = settings_fs->open(name, "r");
|
||||
if (!file) return false;
|
||||
#endif
|
||||
uint8_t data[12], expected[12];
|
||||
const bool complete = file.size() == sizeof(data)
|
||||
&& file.read(data, sizeof(data)) == sizeof(data);
|
||||
file.close();
|
||||
if (!complete) return false;
|
||||
if (!mesh::storage::readFixedSettingsFile(settings_fs, name, data, sizeof(data))) return false;
|
||||
prefs.battery.mode = DisplayMode(data[3]);
|
||||
prefs.battery.seconds = uint16_t(data[4]) | (uint16_t(data[5]) << 8);
|
||||
prefs.usb.mode = DisplayMode(data[6]);
|
||||
@@ -49,8 +42,25 @@ bool readPrefs(const char* name, DisplayPowerPrefs& prefs) {
|
||||
&& validDisplayProfile(prefs.battery) && validDisplayProfile(prefs.usb)
|
||||
&& uint8_t(prefs.inbox) <= uint8_t(DisplayInboxMode::Unread);
|
||||
}
|
||||
#if defined(NRF52_PLATFORM)
|
||||
// Both CLI updates and legacy migration use this transaction.
|
||||
__attribute__((noinline))
|
||||
#endif
|
||||
bool savePrefs(const DisplayPowerPrefs& prefs) {
|
||||
if (!settings_fs) return false;
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (!validDisplayProfile(prefs.battery) || !validDisplayProfile(prefs.usb)
|
||||
|| uint8_t(prefs.inbox) > uint8_t(DisplayInboxMode::Unread)) return false;
|
||||
uint8_t data[12];
|
||||
encode(prefs, data);
|
||||
// The shared transaction verifies staging and exact published bytes.
|
||||
if (mesh::storage::writeCheckedSettingsFile(settings_fs, path, data, sizeof(data))
|
||||
!= mesh::AtomicFileWriter::Outcome::Committed) return false;
|
||||
// Older images can leave a .bak record. Retire it only after publication
|
||||
// of the checked display format has been verified.
|
||||
settings_fs->remove(backup);
|
||||
return true;
|
||||
#else
|
||||
// Preserve the previous complete file until the replacement is verified.
|
||||
settings_fs->remove(temporary);
|
||||
if (settings_fs->exists(temporary)) return false;
|
||||
@@ -78,6 +88,7 @@ bool savePrefs(const DisplayPowerPrefs& prefs) {
|
||||
}
|
||||
settings_fs->remove(backup);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
#endif // MESHCORE_HAS_REAL_DISPLAY
|
||||
}
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
#if defined(OLED_AUTO_DETECT) && OLED_AUTO_DETECT
|
||||
|
||||
#include "OLEDControllerSettings.h"
|
||||
#include <helpers/CheckedSettingsFile.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace mesh { namespace ui {
|
||||
namespace {
|
||||
FILESYSTEM* settings_fs = nullptr;
|
||||
OLEDControllerMode active_mode = defaultOLEDControllerMode();
|
||||
OLEDControllerMode configured_mode = defaultOLEDControllerMode();
|
||||
bool saved_mode = false;
|
||||
bool recovery_pending = false;
|
||||
const char* const path = "/display_controller";
|
||||
const char* const backup = "/display_controller.bak";
|
||||
#if !defined(NRF52_PLATFORM)
|
||||
const char* const temporary = "/display_controller.tmp";
|
||||
#endif
|
||||
|
||||
const char* modeName(OLEDControllerMode mode) {
|
||||
switch (mode) {
|
||||
case OLEDControllerMode::SSD1306: return "ssd1306";
|
||||
case OLEDControllerMode::SH1106: return "sh1106";
|
||||
default: return "auto";
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t images[3][6] = {
|
||||
{'O', 'C', 1, 0, 0, 'O' ^ 'C' ^ 1},
|
||||
{'O', 'C', 1, 1, 0, 'O' ^ 'C' ^ 1 ^ 1},
|
||||
{'O', 'C', 1, 2, 0, 'O' ^ 'C' ^ 1 ^ 2}};
|
||||
|
||||
bool readPrefs(const char* name, OLEDControllerMode& mode) {
|
||||
uint8_t data[sizeof(images[0])];
|
||||
if (!storage::readFixedSettingsFile(settings_fs, name, data, sizeof(data))
|
||||
|| data[3] > uint8_t(OLEDControllerMode::SH1106)
|
||||
|| memcmp(data, images[data[3]], sizeof(data)) != 0) return false;
|
||||
mode = OLEDControllerMode(data[3]);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool savePrefs(OLEDControllerMode mode) {
|
||||
// A failed backup recovery may leave that backup as the only valid record.
|
||||
// Do not rotate it away until a later successful load repairs the store.
|
||||
if (!settings_fs || recovery_pending) return false;
|
||||
const uint8_t* data = images[uint8_t(mode)];
|
||||
#if defined(NRF52_PLATFORM)
|
||||
// Share the existing LittleFS transaction implementation on constrained
|
||||
// nRF52 targets: it verifies staged bytes and the published file by CRC32C.
|
||||
const auto outcome = storage::writeCheckedSettingsFile(
|
||||
settings_fs, path, data, sizeof(images[0]));
|
||||
if (outcome != mesh::AtomicFileWriter::Outcome::Committed) {
|
||||
recovery_pending = outcome == mesh::AtomicFileWriter::Outcome::Indeterminate;
|
||||
return false;
|
||||
}
|
||||
settings_fs->remove(backup);
|
||||
return true;
|
||||
#else
|
||||
// Keep the previous complete record until the replacement is read back.
|
||||
settings_fs->remove(temporary);
|
||||
if (settings_fs->exists(temporary)) return false;
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
File file(*settings_fs);
|
||||
if (!file.open(temporary, FILE_O_WRITE)) return false;
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
File file = settings_fs->open(temporary, "w");
|
||||
if (!file) return false;
|
||||
#else
|
||||
File file = settings_fs->open(temporary, "w", true);
|
||||
if (!file) return false;
|
||||
#endif
|
||||
const bool written = file.write(data, sizeof(images[0])) == sizeof(images[0]);
|
||||
file.close();
|
||||
OLEDControllerMode checked = OLEDControllerMode::Auto;
|
||||
if (!written || !readPrefs(temporary, checked) || checked != mode) return false;
|
||||
if (settings_fs->exists(backup) && !settings_fs->remove(backup)) return false;
|
||||
if (settings_fs->exists(path) && !settings_fs->rename(path, backup)) return false;
|
||||
if (!settings_fs->rename(temporary, path)) {
|
||||
if (settings_fs->exists(backup) && !settings_fs->rename(backup, path)) {
|
||||
recovery_pending = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
settings_fs->remove(backup);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool equalMode(const char* value, const char* expected) {
|
||||
while (*value && *expected) {
|
||||
const char c = *value >= 'A' && *value <= 'Z' ? *value + ('a' - 'A') : *value;
|
||||
if (c != *expected) return false;
|
||||
++value;
|
||||
++expected;
|
||||
}
|
||||
return *value == 0 && *expected == 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool loadOLEDControllerSettings(FILESYSTEM* fs) {
|
||||
settings_fs = fs;
|
||||
active_mode = configured_mode = defaultOLEDControllerMode();
|
||||
saved_mode = recovery_pending = false;
|
||||
if (!fs) return false;
|
||||
OLEDControllerMode loaded = defaultOLEDControllerMode();
|
||||
bool found = readPrefs(path, loaded);
|
||||
if (!found && readPrefs(backup, loaded)) {
|
||||
found = true;
|
||||
recovery_pending = (fs->exists(path) && !fs->remove(path))
|
||||
|| !fs->rename(backup, path);
|
||||
}
|
||||
if (found) {
|
||||
active_mode = configured_mode = loaded;
|
||||
saved_mode = true;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
OLEDControllerMode oledControllerMode() { return active_mode; }
|
||||
|
||||
bool handleOLEDControllerCommand(const char* command, char* reply,
|
||||
size_t reply_size, bool supported) {
|
||||
const bool get = strncmp(command, "get ", 4) == 0;
|
||||
const bool set = strncmp(command, "set ", 4) == 0;
|
||||
if (!get && !set) return false;
|
||||
const char* key = command + 4;
|
||||
constexpr size_t key_length = sizeof("display.controller") - 1;
|
||||
if (strncmp(key, "display.controller", key_length) != 0
|
||||
|| (key[key_length] != 0 && key[key_length] != ' ')) return false;
|
||||
if (!supported) {
|
||||
snprintf(reply, reply_size, "Error: display controller unsupported");
|
||||
return true;
|
||||
}
|
||||
const char* value = key + key_length;
|
||||
if (get) {
|
||||
if (*value) snprintf(reply, reply_size, "Error: unexpected argument");
|
||||
else snprintf(reply, reply_size, "display.controller %s (active %s%s)",
|
||||
modeName(configured_mode), modeName(active_mode),
|
||||
configured_mode != active_mode ? "; restart required" : "");
|
||||
return true;
|
||||
}
|
||||
while (*value == ' ') ++value;
|
||||
OLEDControllerMode candidate;
|
||||
if (equalMode(value, "auto")) candidate = OLEDControllerMode::Auto;
|
||||
else if (equalMode(value, "ssd1306")) candidate = OLEDControllerMode::SSD1306;
|
||||
else if (equalMode(value, "sh1106")) candidate = OLEDControllerMode::SH1106;
|
||||
else {
|
||||
snprintf(reply, reply_size, "Error: use set display.controller <auto|ssd1306|sh1106>");
|
||||
return true;
|
||||
}
|
||||
if ((!saved_mode || candidate != configured_mode) && !savePrefs(candidate)) {
|
||||
snprintf(reply, reply_size, "Error: display controller save failed");
|
||||
return true;
|
||||
}
|
||||
configured_mode = candidate;
|
||||
saved_mode = true;
|
||||
snprintf(reply, reply_size, "OK - display controller %s%s", modeName(candidate),
|
||||
configured_mode != active_mode ? "; restart required" : "");
|
||||
return true;
|
||||
}
|
||||
|
||||
}} // namespace mesh::ui
|
||||
|
||||
#endif // OLED_AUTO_DETECT
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <helpers/IdentityStore.h>
|
||||
#include "OLEDDisplayProbe.h"
|
||||
|
||||
namespace mesh { namespace ui {
|
||||
|
||||
// Separate, checked storage leaves existing node preference layouts unchanged.
|
||||
// Load before display startup. A saved Auto selection overrides a build override.
|
||||
bool loadOLEDControllerSettings(FILESYSTEM* fs);
|
||||
|
||||
// The mode selected at startup. Saved changes take effect after a restart.
|
||||
OLEDControllerMode oledControllerMode();
|
||||
|
||||
bool handleOLEDControllerCommand(const char* command, char* reply,
|
||||
size_t reply_size, bool supported);
|
||||
|
||||
}} // namespace mesh::ui
|
||||
@@ -6,6 +6,18 @@ namespace mesh { namespace ui {
|
||||
|
||||
enum class OLEDController : uint8_t { Absent, SSD1306, SH1106 };
|
||||
|
||||
enum class OLEDControllerMode : uint8_t { Auto, SSD1306, SH1106 };
|
||||
|
||||
constexpr OLEDControllerMode defaultOLEDControllerMode() {
|
||||
#if defined(OLED_CONTROLLER_OVERRIDE)
|
||||
static_assert(OLED_CONTROLLER_OVERRIDE >= 0 && OLED_CONTROLLER_OVERRIDE <= 2,
|
||||
"OLED_CONTROLLER_OVERRIDE must be 0 (auto), 1 (SSD1306) or 2 (SH1106)");
|
||||
return static_cast<OLEDControllerMode>(OLED_CONTROLLER_OVERRIDE);
|
||||
#else
|
||||
return OLEDControllerMode::Auto;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Status-byte detection is used by ss_oled and Meshtastic. Only 0x08 is
|
||||
// evidence of SH1106: some RAK1921 SSD1306 panels return the ambiguous 0x00.
|
||||
// See https://github.com/meshtastic/firmware/pull/11265.
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include "SSD1306Display.h"
|
||||
#if defined(OLED_AUTO_DETECT) && OLED_AUTO_DETECT
|
||||
#include "OLEDControllerSettings.h"
|
||||
#endif
|
||||
|
||||
#if defined(ESP32_PLATFORM) || (defined(NRF52_PLATFORM) && defined(RAK4631_COMBINED_ETHERNET))
|
||||
// Adafruit_SSD1306::begin allocates WIDTH * ((HEIGHT + 7) / 8) once and
|
||||
@@ -34,7 +37,11 @@ bool SSD1306Display::begin() {
|
||||
_isOn = true;
|
||||
}
|
||||
const bool started = display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS,
|
||||
true, false)
|
||||
true, false
|
||||
#if defined(OLED_AUTO_DETECT) && OLED_AUTO_DETECT
|
||||
, mesh::ui::oledControllerMode()
|
||||
#endif
|
||||
)
|
||||
&& i2c_probe(Wire, DISPLAY_ADDRESS);
|
||||
if (started) {
|
||||
_panel_ready = true;
|
||||
|
||||
Reference in new issue
Block a user