diff --git a/src/Power.cpp b/src/Power.cpp index 4118dac53..3a2bea10c 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -868,7 +868,6 @@ void Power::reboot() Wire.end(); Serial1.end(); if (screen) { - delete screen; screen = nullptr; } LOG_DEBUG("final reboot!"); diff --git a/src/detect/ReClockI2C.h b/src/detect/ReClockI2C.h index c8a81fb09..503f1a48b 100644 --- a/src/detect/ReClockI2C.h +++ b/src/detect/ReClockI2C.h @@ -18,7 +18,7 @@ Only for cases where we can know it (ESP32 or known screen) we can do this. */ -extern graphics::Screen *screen; +extern std::unique_ptr screen; class ReClockI2C { diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index ce9349408..776a14c58 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -6,6 +6,7 @@ #include "mesh/generated/meshtastic/config.pb.h" #include #include +#include #include #include @@ -842,6 +843,6 @@ class Screen : public concurrency::OSThread // Extern declarations for function symbols used in UIRenderer extern std::vector functionSymbol; extern std::string functionSymbolString; -extern graphics::Screen *screen; +extern std::unique_ptr screen; #endif diff --git a/src/graphics/draw/DebugRenderer.cpp b/src/graphics/draw/DebugRenderer.cpp index 5c755b927..95a76c0e9 100644 --- a/src/graphics/draw/DebugRenderer.cpp +++ b/src/graphics/draw/DebugRenderer.cpp @@ -38,7 +38,7 @@ using namespace meshtastic; // External variables -extern graphics::Screen *screen; +extern std::unique_ptr screen; extern PowerStatus *powerStatus; extern NodeStatus *nodeStatus; extern GPSStatus *gpsStatus; diff --git a/src/graphics/draw/MessageRenderer.cpp b/src/graphics/draw/MessageRenderer.cpp index af5ffe93d..932dc773e 100644 --- a/src/graphics/draw/MessageRenderer.cpp +++ b/src/graphics/draw/MessageRenderer.cpp @@ -23,7 +23,7 @@ // External declarations extern bool hasUnreadMessage; -extern graphics::Screen *screen; +extern std::unique_ptr screen; using graphics::Emote; using graphics::emotes; diff --git a/src/graphics/draw/NodeListRenderer.cpp b/src/graphics/draw/NodeListRenderer.cpp index 3a307398e..5b4036a98 100644 --- a/src/graphics/draw/NodeListRenderer.cpp +++ b/src/graphics/draw/NodeListRenderer.cpp @@ -18,7 +18,7 @@ #include // Global screen instance -extern graphics::Screen *screen; +extern std::unique_ptr screen; #if defined(OLED_TINY) static uint32_t lastSwitchTime = 0; diff --git a/src/graphics/draw/UIRenderer.cpp b/src/graphics/draw/UIRenderer.cpp index 5656d78f2..aba2fb632 100644 --- a/src/graphics/draw/UIRenderer.cpp +++ b/src/graphics/draw/UIRenderer.cpp @@ -28,7 +28,7 @@ #include // External variables -extern graphics::Screen *screen; +extern std::unique_ptr screen; #if defined(OLED_TINY) static uint32_t lastSwitchTime = 0; #endif diff --git a/src/main.cpp b/src/main.cpp index 37ab56bc8..77beb8396 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -212,7 +212,7 @@ using namespace concurrency; volatile static const char slipstreamTZString[] = {USERPREFS_TZ_STRING}; // We always create a screen object, but we only init it if we find the hardware -graphics::Screen *screen = nullptr; +std::unique_ptr screen = nullptr; // Global power status meshtastic::PowerStatus *powerStatus = new meshtastic::PowerStatus(); @@ -966,15 +966,15 @@ void setup() if (config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { #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(screen_found, screen_model, screen_geometry); #elif defined(ARCH_PORTDUINO) if ((screen_found.port != ScanI2C::I2CPort::NO_I2C || portduino_config.displayPanel) && config.display.displaymode != meshtastic_Config_DisplayConfig_DisplayMode_COLOR) { - screen = new graphics::Screen(screen_found, screen_model, screen_geometry); + screen = std::make_unique(screen_found, screen_model, screen_geometry); } #else if (screen_found.port != ScanI2C::I2CPort::NO_I2C) - screen = new graphics::Screen(screen_found, screen_model, screen_geometry); + screen = std::make_unique(screen_found, screen_model, screen_geometry); #endif } #endif // HAS_SCREEN diff --git a/src/main.h b/src/main.h index 98dcccc71..19b1bace0 100644 --- a/src/main.h +++ b/src/main.h @@ -11,6 +11,7 @@ #include "mesh/generated/meshtastic/telemetry.pb.h" #include #include +#include #if defined(ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !MESHTASTIC_EXCLUDE_BLUETOOTH #include "nimble/NimbleBluetooth.h" extern NimbleBluetooth *nimbleBluetooth; @@ -68,7 +69,7 @@ extern UdpMulticastHandler *udpHandler; #endif // Global Screen singleton. -extern graphics::Screen *screen; +extern std::unique_ptr screen; #if !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C && !MESHTASTIC_EXCLUDE_ACCELEROMETER #include "motion/AccelerometerThread.h" diff --git a/src/modules/TraceRouteModule.cpp b/src/modules/TraceRouteModule.cpp index 7cfe3259f..c0cac7123 100644 --- a/src/modules/TraceRouteModule.cpp +++ b/src/modules/TraceRouteModule.cpp @@ -12,7 +12,7 @@ #include "modules/TrafficManagementModule.h" #endif -extern graphics::Screen *screen; +extern std::unique_ptr screen; TraceRouteModule *traceRouteModule; diff --git a/src/motion/BMM150Sensor.cpp b/src/motion/BMM150Sensor.cpp index f48d20288..4f4bf26c0 100644 --- a/src/motion/BMM150Sensor.cpp +++ b/src/motion/BMM150Sensor.cpp @@ -4,7 +4,7 @@ #if !defined(MESHTASTIC_EXCLUDE_SCREEN) // screen is defined in main.cpp -extern graphics::Screen *screen; +extern std::unique_ptr screen; #endif BMM150Sensor::BMM150Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {} diff --git a/src/motion/BMX160Sensor.cpp b/src/motion/BMX160Sensor.cpp index 863a23f57..7052f3982 100755 --- a/src/motion/BMX160Sensor.cpp +++ b/src/motion/BMX160Sensor.cpp @@ -8,7 +8,7 @@ BMX160Sensor::BMX160Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::Mot #if !defined(MESHTASTIC_EXCLUDE_SCREEN) // screen is defined in main.cpp -extern graphics::Screen *screen; +extern std::unique_ptr screen; #endif bool BMX160Sensor::init() diff --git a/src/motion/ICM20948Sensor.cpp b/src/motion/ICM20948Sensor.cpp index 3dd5a5e46..e0fc2c5a8 100755 --- a/src/motion/ICM20948Sensor.cpp +++ b/src/motion/ICM20948Sensor.cpp @@ -4,7 +4,7 @@ #if !defined(MESHTASTIC_EXCLUDE_SCREEN) // screen is defined in main.cpp -extern graphics::Screen *screen; +extern std::unique_ptr screen; #endif // Flag when an interrupt has been detected diff --git a/src/motion/MMC5983MASensor.cpp b/src/motion/MMC5983MASensor.cpp index d63420d92..62fb1105e 100644 --- a/src/motion/MMC5983MASensor.cpp +++ b/src/motion/MMC5983MASensor.cpp @@ -6,7 +6,7 @@ #include "detect/ScanI2CTwoWire.h" #if !defined(MESHTASTIC_EXCLUDE_SCREEN) -extern graphics::Screen *screen; +extern std::unique_ptr screen; #endif static constexpr float MMC5983MA_ZERO_FIELD = 131072.0f; diff --git a/src/motion/MotionSensor.cpp b/src/motion/MotionSensor.cpp index 878b4dd50..b1744ad92 100755 --- a/src/motion/MotionSensor.cpp +++ b/src/motion/MotionSensor.cpp @@ -45,7 +45,7 @@ CompassAccelSample latestCompassAccelSample; } // namespace // screen is defined in main.cpp -extern graphics::Screen *screen; +extern std::unique_ptr screen; MotionSensor::MotionSensor(ScanI2C::FoundDevice foundDevice) {