diff --git a/src/PowerFSM.cpp b/src/PowerFSM.cpp
index a8ee0275..80580fd0 100644
--- a/src/PowerFSM.cpp
+++ b/src/PowerFSM.cpp
@@ -5,7 +5,7 @@
#include "NodeDB.h"
#include "configuration.h"
#include "main.h"
-#include "screen.h"
+#include "graphics/Screen.h"
#include "sleep.h"
#include "target_specific.h"
#include "timing.h"
diff --git a/src/commands.h b/src/commands.h
new file mode 100644
index 00000000..c9d519de
--- /dev/null
+++ b/src/commands.h
@@ -0,0 +1,15 @@
+/**
+ * @brief This class enables on the fly software and hardware setup.
+ * It will contain all command messages to change internal settings.
+ */
+
+enum class Cmd {
+ INVALID,
+ SET_ON,
+ SET_OFF,
+ ON_PRESS,
+ START_BLUETOOTH_PIN_SCREEN,
+ STOP_BLUETOOTH_PIN_SCREEN,
+ STOP_BOOT_SCREEN,
+ PRINT,
+};
\ No newline at end of file
diff --git a/src/screen.cpp b/src/graphics/Screen.cpp
similarity index 97%
rename from src/screen.cpp
rename to src/graphics/Screen.cpp
index 60bfaadb..23e4d32a 100644
--- a/src/screen.cpp
+++ b/src/graphics/Screen.cpp
@@ -26,25 +26,16 @@ along with this program. If not, see .
#include "MeshService.h"
#include "NodeDB.h"
#include "configuration.h"
-#include "fonts.h"
-#include "images.h"
+#include "graphics/images.h"
#include "main.h"
#include "mesh-pb-constants.h"
-#include "screen.h"
+#include "Screen.h"
#include "utils.h"
+#include "configs.h"
-#define FONT_HEIGHT 14 // actually 13 for "ariel 10" but want a little extra space
-#define FONT_HEIGHT_16 (ArialMT_Plain_16[1] + 1)
-// This means the *visible* area (sh1106 can address 132, but shows 128 for example)
-#define SCREEN_WIDTH 128
-#define SCREEN_HEIGHT 64
-#define TRANSITION_FRAMERATE 30 // fps
-#define IDLE_FRAMERATE 1 // in fps
-#define COMPASS_DIAM 44
+using namespace meshtastic; /** @todo remove */
-#define NUM_EXTRA_FRAMES 2 // text message and debug frame
-
-namespace meshtastic
+namespace graphics
{
// A text message frame + debug frame + all the node infos
@@ -57,8 +48,6 @@ uint8_t imgSatellite[8] = { 0x70, 0x71, 0x22, 0xFA, 0xFA, 0x22, 0x71, 0x70 };
uint32_t dopThresholds[5] = { 2000, 1000, 500, 200, 100 };
-// if defined a pixel will blink to show redraws
-// #define SHOW_REDRAWS
#ifdef SHOW_REDRAWS
static bool heartbeat = false;
#endif
@@ -629,7 +618,7 @@ void Screen::doTask()
// Process incoming commands.
for (;;) {
- CmdItem cmd;
+ ScreenCmd cmd;
if (!cmdQueue.dequeue(&cmd, 0)) {
break;
}
@@ -821,7 +810,7 @@ void Screen::adjustBrightness()
dispdev.setBrightness(brightness);
}
-int Screen::handleStatusUpdate(const Status *arg)
+int Screen::handleStatusUpdate(const meshtastic::Status *arg)
{
//DEBUG_MSG("Screen got status update %d\n", arg->getStatusType());
switch(arg->getStatusType())
@@ -837,4 +826,4 @@ int Screen::handleStatusUpdate(const Status *arg)
setPeriod(1); // Update the screen right away
return 0;
}
-} // namespace meshtastic
+} // namespace graphics
diff --git a/src/screen.h b/src/graphics/Screen.h
similarity index 80%
rename from src/screen.h
rename to src/graphics/Screen.h
index 4f24aaef..2ad015a4 100644
--- a/src/screen.h
+++ b/src/graphics/Screen.h
@@ -14,9 +14,10 @@
#include "TypedQueue.h"
#include "concurrency/LockGuard.h"
#include "power.h"
+#include "commands.h"
#include
-namespace meshtastic
+namespace graphics
{
// Forward declarations
@@ -50,18 +51,18 @@ class DebugInfo
concurrency::Lock lock;
};
-/// Deals with showing things on the screen of the device.
-//
-// Other than setup(), this class is thread-safe. All state-changing calls are
-// queued and executed when the main loop calls us.
-//
-// This class is thread-safe (as long as drawFrame is not called multiple times
-// simultaneously).
+/**
+ * @brief This class deals with showing things on the screen of the device.
+ *
+ * @details Other than setup(), this class is thread-safe as long as drawFrame is not called
+ * multiple times simultaneously. All state-changing calls are queued and executed
+ * when the main loop calls us.
+ */
class Screen : public concurrency::PeriodicTask
{
- CallbackObserver powerStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
- CallbackObserver gpsStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
- CallbackObserver nodeStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
+ CallbackObserver powerStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
+ CallbackObserver gpsStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
+ CallbackObserver nodeStatusObserver = CallbackObserver(this, &Screen::handleStatusUpdate);
public:
Screen(uint8_t address, int sda = -1, int scl = -1);
@@ -81,11 +82,11 @@ class Screen : public concurrency::PeriodicTask
handleSetOn(
false); // We handle off commands immediately, because they might be called because the CPU is shutting down
else
- enqueueCmd(CmdItem{.cmd = on ? Cmd::SET_ON : Cmd::SET_OFF});
+ enqueueCmd(ScreenCmd{.cmd = on ? Cmd::SET_ON : Cmd::SET_OFF});
}
/// Handles a button press.
- void onPress() { enqueueCmd(CmdItem{.cmd = Cmd::ON_PRESS}); }
+ void onPress() { enqueueCmd(ScreenCmd{.cmd = Cmd::ON_PRESS}); }
// Implementation to Adjust Brightness
void adjustBrightness();
@@ -97,22 +98,22 @@ class Screen : public concurrency::PeriodicTask
// with the PIN.
void startBluetoothPinScreen(uint32_t pin)
{
- CmdItem cmd;
+ ScreenCmd cmd;
cmd.cmd = Cmd::START_BLUETOOTH_PIN_SCREEN;
cmd.bluetooth_pin = pin;
enqueueCmd(cmd);
}
/// Stops showing the bluetooth PIN screen.
- void stopBluetoothPinScreen() { enqueueCmd(CmdItem{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
+ void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
/// Stops showing the boot screen.
- void stopBootScreen() { enqueueCmd(CmdItem{.cmd = Cmd::STOP_BOOT_SCREEN}); }
+ void stopBootScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BOOT_SCREEN}); }
/// Writes a string to the screen.
void print(const char *text)
{
- CmdItem cmd;
+ ScreenCmd cmd;
cmd.cmd = Cmd::PRINT;
// TODO(girts): strdup() here is scary, but we can't use std::string as
// FreeRTOS queue is just dumbly copying memory contents. It would be
@@ -168,17 +169,7 @@ class Screen : public concurrency::PeriodicTask
void doTask() final;
private:
- enum class Cmd {
- INVALID,
- SET_ON,
- SET_OFF,
- ON_PRESS,
- START_BLUETOOTH_PIN_SCREEN,
- STOP_BLUETOOTH_PIN_SCREEN,
- STOP_BOOT_SCREEN,
- PRINT,
- };
- struct CmdItem {
+ struct ScreenCmd {
Cmd cmd;
union {
uint32_t bluetooth_pin;
@@ -187,7 +178,7 @@ class Screen : public concurrency::PeriodicTask
};
/// Enques given command item to be processed by main loop().
- bool enqueueCmd(const CmdItem &cmd)
+ bool enqueueCmd(const ScreenCmd &cmd)
{
if (!useDisplay)
return true; // claim success if our display is not in use
@@ -211,7 +202,7 @@ class Screen : public concurrency::PeriodicTask
static void drawDebugInfoTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
/// Queue of commands to execute in doTask.
- TypedQueue cmdQueue;
+ TypedQueue cmdQueue;
/// Whether we are using a display
bool useDisplay = false;
/// Whether the display is currently powered
@@ -222,7 +213,9 @@ class Screen : public concurrency::PeriodicTask
/// Holds state for debug information
DebugInfo debugInfo;
+
/// Display device
+ /** @todo display abstraction */
#ifdef USE_SH1106
SH1106Wire dispdev;
#else
@@ -232,4 +225,4 @@ class Screen : public concurrency::PeriodicTask
OLEDDisplayUi ui;
};
-} // namespace meshtastic
+} // namespace graphics
diff --git a/src/graphics/configs.h b/src/graphics/configs.h
new file mode 100644
index 00000000..c7698f89
--- /dev/null
+++ b/src/graphics/configs.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "fonts.h"
+
+#define FONT_HEIGHT 14 // actually 13 for "Arial 10" but want a little extra space
+#define FONT_HEIGHT_16 (ArialMT_Plain_16[1] + 1)
+// This means the *visible* area (sh1106 can address 132, but shows 128 for example)
+#define SCREEN_WIDTH 128
+#define SCREEN_HEIGHT 64
+#define TRANSITION_FRAMERATE 30 // fps
+#define IDLE_FRAMERATE 1 // in fps
+#define COMPASS_DIAM 44
+
+// DEBUG
+#define NUM_EXTRA_FRAMES 2 // text message and debug frame
+// if defined a pixel will blink to show redraws
+// #define SHOW_REDRAWS
\ No newline at end of file
diff --git a/src/fonts.h b/src/graphics/fonts.h
similarity index 99%
rename from src/fonts.h
rename to src/graphics/fonts.h
index 5be8a83e..4c7cb5ca 100644
--- a/src/fonts.h
+++ b/src/graphics/fonts.h
@@ -1,3 +1,5 @@
+#pragma once
+
const uint8_t Custom_ArialMT_Plain_10[] PROGMEM = {
0x0A, // Width: 10
0x0A, // Height: 10
diff --git a/src/images.h b/src/graphics/images.h
similarity index 94%
rename from src/images.h
rename to src/graphics/images.h
index 2a706494..960d38d1 100644
--- a/src/images.h
+++ b/src/graphics/images.h
@@ -1,3 +1,5 @@
+#pragma once
+
#define SATELLITE_IMAGE_WIDTH 16
#define SATELLITE_IMAGE_HEIGHT 15
const uint8_t SATELLITE_IMAGE[] PROGMEM = {0x00, 0x08, 0x00, 0x1C, 0x00, 0x0E, 0x20, 0x07, 0x70, 0x02,
@@ -10,12 +12,12 @@ const uint8_t imgUser[] PROGMEM = { 0x3C, 0x42, 0x99, 0xA5, 0xA5, 0x99
const uint8_t imgPositionEmpty[] PROGMEM = { 0x20, 0x30, 0x28, 0x24, 0x42, 0xFF };
const uint8_t imgPositionSolid[] PROGMEM = { 0x20, 0x30, 0x38, 0x3C, 0x7E, 0xFF };
-#include "icon.xbm"
+#include "img/icon.xbm"
// We now programmatically draw our compass
#if 0
const
-#include "compass.xbm"
+#include "img/compass.xbm"
#endif
#if 0
diff --git a/src/compass.xbm b/src/graphics/img/compass.xbm
similarity index 100%
rename from src/compass.xbm
rename to src/graphics/img/compass.xbm
diff --git a/src/icon.xbm b/src/graphics/img/icon.xbm
similarity index 100%
rename from src/icon.xbm
rename to src/graphics/img/icon.xbm
diff --git a/src/pin.xbm b/src/graphics/img/pin.xbm
similarity index 100%
rename from src/pin.xbm
rename to src/graphics/img/pin.xbm
diff --git a/src/main.cpp b/src/main.cpp
index 19bd4740..09f09ce7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -35,7 +35,7 @@
#include "DSRRouter.h"
#include "debug.h"
#include "main.h"
-#include "screen.h"
+#include "graphics/Screen.h"
#include "sleep.h"
#include "timing.h"
#include
@@ -55,7 +55,7 @@
#endif
// We always create a screen object, but we only init it if we find the hardware
-meshtastic::Screen screen(SSD1306_ADDRESS);
+graphics::Screen screen(SSD1306_ADDRESS);
// Global power status
meshtastic::PowerStatus *powerStatus = new meshtastic::PowerStatus();
diff --git a/src/main.h b/src/main.h
index 471ba2e8..fb64d9ff 100644
--- a/src/main.h
+++ b/src/main.h
@@ -1,6 +1,6 @@
#pragma once
-#include "screen.h"
+#include "graphics/Screen.h"
#include "PowerStatus.h"
#include "GPSStatus.h"
#include "NodeStatus.h"
@@ -11,7 +11,7 @@ extern bool isCharging;
extern bool isUSBPowered;
// Global Screen singleton.
-extern meshtastic::Screen screen;
+extern graphics::Screen screen;
//extern Observable newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class
//extern meshtastic::PowerStatus *powerStatus;