replace screens with unique_ptr (#11163)

This commit is contained in:
Jorropo
2026-07-25 11:51:13 +00:00
committed by GitHub
co-authored by GitHub
parent abf217c38d
commit 9e529da460
15 changed files with 19 additions and 18 deletions
-1
View File
@@ -868,7 +868,6 @@ void Power::reboot()
Wire.end(); Wire.end();
Serial1.end(); Serial1.end();
if (screen) { if (screen) {
delete screen;
screen = nullptr; screen = nullptr;
} }
LOG_DEBUG("final reboot!"); LOG_DEBUG("final reboot!");
+1 -1
View File
@@ -18,7 +18,7 @@
Only for cases where we can know it (ESP32 or known screen) we can do this. Only for cases where we can know it (ESP32 or known screen) we can do this.
*/ */
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
class ReClockI2C class ReClockI2C
{ {
+2 -1
View File
@@ -6,6 +6,7 @@
#include "mesh/generated/meshtastic/config.pb.h" #include "mesh/generated/meshtastic/config.pb.h"
#include <OLEDDisplay.h> #include <OLEDDisplay.h>
#include <functional> #include <functional>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -842,6 +843,6 @@ class Screen : public concurrency::OSThread
// Extern declarations for function symbols used in UIRenderer // Extern declarations for function symbols used in UIRenderer
extern std::vector<std::string> functionSymbol; extern std::vector<std::string> functionSymbol;
extern std::string functionSymbolString; extern std::string functionSymbolString;
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#endif #endif
+1 -1
View File
@@ -38,7 +38,7 @@
using namespace meshtastic; using namespace meshtastic;
// External variables // External variables
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
extern PowerStatus *powerStatus; extern PowerStatus *powerStatus;
extern NodeStatus *nodeStatus; extern NodeStatus *nodeStatus;
extern GPSStatus *gpsStatus; extern GPSStatus *gpsStatus;
+1 -1
View File
@@ -23,7 +23,7 @@
// External declarations // External declarations
extern bool hasUnreadMessage; extern bool hasUnreadMessage;
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
using graphics::Emote; using graphics::Emote;
using graphics::emotes; using graphics::emotes;
+1 -1
View File
@@ -18,7 +18,7 @@
#include <algorithm> #include <algorithm>
// Global screen instance // Global screen instance
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#if defined(OLED_TINY) #if defined(OLED_TINY)
static uint32_t lastSwitchTime = 0; static uint32_t lastSwitchTime = 0;
+1 -1
View File
@@ -28,7 +28,7 @@
#include <gps/RTC.h> #include <gps/RTC.h>
// External variables // External variables
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#if defined(OLED_TINY) #if defined(OLED_TINY)
static uint32_t lastSwitchTime = 0; static uint32_t lastSwitchTime = 0;
#endif #endif
+4 -4
View File
@@ -212,7 +212,7 @@ using namespace concurrency;
volatile static const char slipstreamTZString[] = {USERPREFS_TZ_STRING}; volatile static const char slipstreamTZString[] = {USERPREFS_TZ_STRING};
// We always create a screen object, but we only init it if we find the hardware // We always create a screen object, but we only init it if we find the hardware
graphics::Screen *screen = nullptr; std::unique_ptr<graphics::Screen> screen = nullptr;
// Global power status // Global power status
meshtastic::PowerStatus *powerStatus = new meshtastic::PowerStatus(); meshtastic::PowerStatus *powerStatus = new meshtastic::PowerStatus();
@@ -966,15 +966,15 @@ void setup()
if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
#if defined(HAS_SPI_TFT) || defined(USE_EINK) || defined(USE_SPISSD1306) #if defined(HAS_SPI_TFT) || defined(USE_EINK) || defined(USE_SPISSD1306)
screen = new graphics::Screen(screen_found, screen_model, screen_geometry); screen = std::make_unique<graphics::Screen>(screen_found, screen_model, screen_geometry);
#elif defined(ARCH_PORTDUINO) #elif defined(ARCH_PORTDUINO)
if ((screen_found.port != ScanI2C::I2CPort::NO_I2C || portduino_config.displayPanel) && if ((screen_found.port != ScanI2C::I2CPort::NO_I2C || portduino_config.displayPanel) &&
config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) {
screen = new graphics::Screen(screen_found, screen_model, screen_geometry); screen = std::make_unique<graphics::Screen>(screen_found, screen_model, screen_geometry);
} }
#else #else
if (screen_found.port != ScanI2C::I2CPort::NO_I2C) if (screen_found.port != ScanI2C::I2CPort::NO_I2C)
screen = new graphics::Screen(screen_found, screen_model, screen_geometry); screen = std::make_unique<graphics::Screen>(screen_found, screen_model, screen_geometry);
#endif #endif
} }
#endif // HAS_SCREEN #endif // HAS_SCREEN
+2 -1
View File
@@ -11,6 +11,7 @@
#include "mesh/generated/meshtastic/telemetry.pb.h" #include "mesh/generated/meshtastic/telemetry.pb.h"
#include <SPI.h> #include <SPI.h>
#include <map> #include <map>
#include <memory>
#if defined(ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH #if defined(ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH
#include "nimble/NimbleBluetooth.h" #include "nimble/NimbleBluetooth.h"
extern NimbleBluetooth *nimbleBluetooth; extern NimbleBluetooth *nimbleBluetooth;
@@ -68,7 +69,7 @@ extern UdpMulticastHandler *udpHandler;
#endif #endif
// Global Screen singleton. // Global Screen singleton.
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && !MESHTASTIC_EXCLUDE_ACCELEROMETER #if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && !MESHTASTIC_EXCLUDE_ACCELEROMETER
#include "motion/AccelerometerThread.h" #include "motion/AccelerometerThread.h"
+1 -1
View File
@@ -12,7 +12,7 @@
#include "modules/TrafficManagementModule.h" #include "modules/TrafficManagementModule.h"
#endif #endif
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
TraceRouteModule *traceRouteModule; TraceRouteModule *traceRouteModule;
+1 -1
View File
@@ -4,7 +4,7 @@
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) #if !defined(MESHTASTIC_EXCLUDE_SCREEN)
// screen is defined in main.cpp // screen is defined in main.cpp
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#endif #endif
BMM150Sensor::BMM150Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {} BMM150Sensor::BMM150Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
+1 -1
View File
@@ -8,7 +8,7 @@ BMX160Sensor::BMX160Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::Mot
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) #if !defined(MESHTASTIC_EXCLUDE_SCREEN)
// screen is defined in main.cpp // screen is defined in main.cpp
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#endif #endif
bool BMX160Sensor::init() bool BMX160Sensor::init()
+1 -1
View File
@@ -4,7 +4,7 @@
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) #if !defined(MESHTASTIC_EXCLUDE_SCREEN)
// screen is defined in main.cpp // screen is defined in main.cpp
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#endif #endif
// Flag when an interrupt has been detected // Flag when an interrupt has been detected
+1 -1
View File
@@ -6,7 +6,7 @@
#include "detect/ScanI2CTwoWire.h" #include "detect/ScanI2CTwoWire.h"
#if !defined(MESHTASTIC_EXCLUDE_SCREEN) #if !defined(MESHTASTIC_EXCLUDE_SCREEN)
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
#endif #endif
static constexpr float MMC5983MA_ZERO_FIELD = 131072.0f; static constexpr float MMC5983MA_ZERO_FIELD = 131072.0f;
+1 -1
View File
@@ -45,7 +45,7 @@ CompassAccelSample latestCompassAccelSample;
} // namespace } // namespace
// screen is defined in main.cpp // screen is defined in main.cpp
extern graphics::Screen *screen; extern std::unique_ptr<graphics::Screen> screen;
MotionSensor::MotionSensor(ScanI2C::FoundDevice foundDevice) MotionSensor::MotionSensor(ScanI2C::FoundDevice foundDevice)
{ {