diff --git a/lib/Display/Display.cpp b/lib/Display/Display.cpp index 6ef53ca..b62074e 100644 --- a/lib/Display/Display.cpp +++ b/lib/Display/Display.cpp @@ -2,7 +2,7 @@ #include #include -Display::Display() : _disp(0), _statusFrame(0), _displayOff(false), _displaySaveMode(false) { +Display::Display() : _disp(0), _statusFrame(0), _displaySaveMode(false) { } Display::~Display() { @@ -22,10 +22,12 @@ void Display::setup(std::shared_ptr boardConfig) { Bitmap bitmap(_disp->getWidth(), _disp->getHeight()); _disp->display(&bitmap); - _displayTimeout.setTimeout(10); - _frameTimeout.setTimeout(15); - _displayUpdateRate.setTimeout(1); - _displayUpdateRate.start(); + + _displayFrameRate.setTimeout(500); + _displayFrameRate.start(); + + _frameTimeout.setTimeout(15 * 1000); + _displaySaveModeTimer.setTimeout(10 * 1000); } void Display::turn180() { @@ -36,49 +38,45 @@ void Display::activateDisplaySaveMode() { _displaySaveMode = true; } -void Display::setDisplayTimeout(time_t timeout) { - _displayTimeout.setTimeout(timeout); +void Display::setDisplaySaveTimeout(uint32_t timeout) { + _displaySaveModeTimer.setTimeout(timeout * 1000); } void Display::update() { - if (_displayUpdateRate.check()) { - if (_frameTimeout.check()) { - if (_statusFrame->isPrio()) { - Bitmap bitmap(_disp.get()); - _statusFrame->drawStatusPage(bitmap); - activateDisplay(); - _disp->display(&bitmap); - return; - } + if (_displayFrameRate.check()) { - if (_frames.size() > 0) { - std::shared_ptr frame = *_frames.begin(); - Bitmap bitmap(_disp.get()); - frame->drawStatusPage(bitmap); - activateDisplay(); - _disp->display(&bitmap); - _frames.pop_front(); + if (_frames.size() > 0) { + std::shared_ptr frame = *_frames.begin(); + Bitmap bitmap(_disp.get()); + frame->drawStatusPage(bitmap); + _disp->display(&bitmap); + + if (!_frameTimeout.isActive()) { _frameTimeout.start(); - return; + _displaySaveModeTimer.reset(); + } else if (_frameTimeout.check()) { + _frames.pop_front(); + _frameTimeout.reset(); } - - if (!_displayOff && !_displayTimeout.isActive()) { + } else { + if (_disp->isDisplayOn()) { Bitmap bitmap(_disp.get()); _statusFrame->drawStatusPage(bitmap); - activateDisplay(); _disp->display(&bitmap); + if (_displaySaveMode) { - _displayTimeout.start(); + if (_displaySaveModeTimer.isActive() && _displaySaveModeTimer.check()) { + _disp->displayOff(); + _displaySaveModeTimer.reset(); + } else if (!_displaySaveModeTimer.isActive()) { + _displaySaveModeTimer.start(); + } } - return; - } - if (_displayTimeout.check()) { - deactivateDisplay(); - _displayTimeout.reset(); } } - _displayUpdateRate.start(); - }; + + _displayFrameRate.start(); + } } void Display::addFrame(std::shared_ptr frame) { @@ -98,16 +96,11 @@ void Display::showSpashScreen(String firmwareTitle, String version) { _disp->display(&bitmap); } -void Display::activateDisplay() { - if (_displayOff) { - _disp->displayOn(); - _displayOff = false; - } -} - -void Display::deactivateDisplay() { - _disp->displayOff(); - _displayOff = true; +void Display::showStatusScreen(String header, String text) { + Bitmap bitmap(_disp.get()); + bitmap.drawString(0, 0, header); + bitmap.drawStringLF(0, 10, text); + _disp->display(&bitmap); } void TextFrame::drawStatusPage(Bitmap &bitmap) { diff --git a/lib/Display/Display.h b/lib/Display/Display.h index 3f8e35d..2259291 100644 --- a/lib/Display/Display.h +++ b/lib/Display/Display.h @@ -29,32 +29,30 @@ public: ~Display(); void setup(std::shared_ptr boardConfig); + // setup functions + void showSpashScreen(String firmwareTitle, String version); + void setStatusFrame(std::shared_ptr frame); + void showStatusScreen(String header, String text); + void turn180(); void activateDisplaySaveMode(); - void setDisplayTimeout(time_t timeout); + void setDisplaySaveTimeout(uint32_t timeout); + + // functions for update loop void update(); - void addFrame(std::shared_ptr frame); - void setStatusFrame(std::shared_ptr frame); - - void showSpashScreen(String firmwareTitle, String version); - private: std::shared_ptr _disp; + Timer _displayFrameRate; + std::shared_ptr _statusFrame; + std::list> _frames; - std::shared_ptr _statusFrame; Timer _frameTimeout; - Timer _displayTimeout; - bool _displayOff; bool _displaySaveMode; - - Timer _displayUpdateRate; - - void activateDisplay(); - void deactivateDisplay(); + Timer _displaySaveModeTimer; }; class TextFrame : public DisplayFrame { diff --git a/lib/Display/OLEDDisplay.cpp b/lib/Display/OLEDDisplay.cpp index 2bc7db8..98117f4 100644 --- a/lib/Display/OLEDDisplay.cpp +++ b/lib/Display/OLEDDisplay.cpp @@ -31,181 +31,171 @@ #include "OLEDDisplay.h" -OLEDDisplay::OLEDDisplay(OLEDDISPLAY_GEOMETRY g) - : _geometry(g) -{ +OLEDDisplay::OLEDDisplay(OLEDDISPLAY_GEOMETRY g) : _geometry(g), _displayIsOn(false) { } -OLEDDisplay::~OLEDDisplay() -{ +OLEDDisplay::~OLEDDisplay() { } // cppcheck-suppress unusedFunction -void OLEDDisplay::displayOn() -{ - sendCommand(DISPLAYON); +void OLEDDisplay::displayOn() { + sendCommand(DISPLAYON); + _displayIsOn = true; } // cppcheck-suppress unusedFunction -void OLEDDisplay::displayOff() -{ - sendCommand(DISPLAYOFF); +bool OLEDDisplay::isDisplayOn() const { + return _displayIsOn; } // cppcheck-suppress unusedFunction -void OLEDDisplay::invertDisplay() -{ - sendCommand(INVERTDISPLAY); +void OLEDDisplay::displayOff() { + sendCommand(DISPLAYOFF); + _displayIsOn = false; } // cppcheck-suppress unusedFunction -void OLEDDisplay::normalDisplay() -{ - sendCommand(NORMALDISPLAY); +bool OLEDDisplay::isDisplayOff() const { + return !_displayIsOn; } // cppcheck-suppress unusedFunction -void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comdetect) -{ - sendCommand(SETPRECHARGE); //0xD9 - sendCommand(precharge); //0xF1 default, to lower the contrast, put 1-1F - sendCommand(SETCONTRAST); - sendCommand(contrast); // 0-255 - sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast) - sendCommand(comdetect); //0x40 default, to lower the contrast, put 0 - sendCommand(DISPLAYALLON_RESUME); - sendCommand(NORMALDISPLAY); - sendCommand(DISPLAYON); +void OLEDDisplay::invertDisplay() { + sendCommand(INVERTDISPLAY); } // cppcheck-suppress unusedFunction -void OLEDDisplay::setBrightness(uint8_t brightness) -{ - uint8_t contrast = brightness * 1.171 - 43; - if (brightness < 128) - { - // Magic values to get a smooth/ step-free transition - contrast = brightness * 1.171; - } - - uint8_t precharge = 241; - if (brightness == 0) - { - precharge = 0; - } - uint8_t comdetect = brightness / 8; - setContrast(contrast, precharge, comdetect); +void OLEDDisplay::normalDisplay() { + sendCommand(NORMALDISPLAY); } // cppcheck-suppress unusedFunction -void OLEDDisplay::resetOrientation() -{ - sendCommand(SEGREMAP); - sendCommand(COMSCANINC); +void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comdetect) { + sendCommand(SETPRECHARGE); // 0xD9 + sendCommand(precharge); // 0xF1 default, to lower the contrast, put 1-1F + sendCommand(SETCONTRAST); + sendCommand(contrast); // 0-255 + sendCommand(SETVCOMDETECT); // 0xDB, (additionally needed to lower the contrast) + sendCommand(comdetect); // 0x40 default, to lower the contrast, put 0 + sendCommand(DISPLAYALLON_RESUME); + sendCommand(NORMALDISPLAY); + sendCommand(DISPLAYON); } // cppcheck-suppress unusedFunction -void OLEDDisplay::flipScreenVertically() -{ - sendCommand(SEGREMAP | 0x01); - sendCommand(COMSCANDEC); +void OLEDDisplay::setBrightness(uint8_t brightness) { + uint8_t contrast = brightness * 1.171 - 43; + if (brightness < 128) { + // Magic values to get a smooth/ step-free transition + contrast = brightness * 1.171; + } + + uint8_t precharge = 241; + if (brightness == 0) { + precharge = 0; + } + uint8_t comdetect = brightness / 8; + setContrast(contrast, precharge, comdetect); } // cppcheck-suppress unusedFunction -void OLEDDisplay::mirrorScreen() -{ - sendCommand(SEGREMAP); - sendCommand(COMSCANDEC); +void OLEDDisplay::resetOrientation() { + sendCommand(SEGREMAP); + sendCommand(COMSCANINC); } // cppcheck-suppress unusedFunction -void OLEDDisplay::clear() -{ +void OLEDDisplay::flipScreenVertically() { + sendCommand(SEGREMAP | 0x01); + sendCommand(COMSCANDEC); } // cppcheck-suppress unusedFunction -uint OLEDDisplay::getWidth() -{ - switch(_geometry) - { - case GEOMETRY_128_64: - case GEOMETRY_128_32: - return 128; - case GEOMETRY_64_48: - case GEOMETRY_64_32: - return 64; - } - return 0; +void OLEDDisplay::mirrorScreen() { + sendCommand(SEGREMAP); + sendCommand(COMSCANDEC); +} + +void OLEDDisplay::display(Bitmap *bitmap) { + if (isDisplayOff()) { + displayOn(); + } + internDisplay(bitmap); } // cppcheck-suppress unusedFunction -uint OLEDDisplay::getHeight() -{ - switch(_geometry) - { - case GEOMETRY_128_64: - return 64; - case GEOMETRY_64_48: - return 48; - case GEOMETRY_128_32: - case GEOMETRY_64_32: - return 32; - } - return 0; +void OLEDDisplay::clear() { } // cppcheck-suppress unusedFunction -void OLEDDisplay::sendInitCommands() -{ - sendCommand(DISPLAYOFF); - sendCommand(SETDISPLAYCLOCKDIV); - sendCommand(0xF0); // Increase speed of the display max ~96Hz - sendCommand(SETMULTIPLEX); - sendCommand(this->getHeight() - 1); - sendCommand(SETDISPLAYOFFSET); - sendCommand(0x00); - if(_geometry == GEOMETRY_64_32) - { - sendCommand(0x00); - } - else - { - sendCommand(SETSTARTLINE); - } - sendCommand(CHARGEPUMP); - sendCommand(0x14); - sendCommand(MEMORYMODE); - sendCommand(0x00); - sendCommand(SEGREMAP); - sendCommand(COMSCANINC); - sendCommand(SETCOMPINS); - - if (_geometry == GEOMETRY_128_64 || _geometry == GEOMETRY_64_48 || _geometry == GEOMETRY_64_32) - { - sendCommand(0x12); - } - else if (_geometry == GEOMETRY_128_32) - { - sendCommand(0x02); - } - - sendCommand(SETCONTRAST); - - if (_geometry == GEOMETRY_128_64 || _geometry == GEOMETRY_64_48 || _geometry == GEOMETRY_64_32) - { - sendCommand(0xCF); - } - else if (_geometry == GEOMETRY_128_32) - { - sendCommand(0x8F); - } - - sendCommand(SETPRECHARGE); - sendCommand(0xF1); - sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast) - sendCommand(0x40); //0x40 default, to lower the contrast, put 0 - sendCommand(DISPLAYALLON_RESUME); - sendCommand(NORMALDISPLAY); - sendCommand(0x2e); // stop scroll - sendCommand(DISPLAYON); +uint OLEDDisplay::getWidth() { + switch (_geometry) { + case GEOMETRY_128_64: + case GEOMETRY_128_32: + return 128; + case GEOMETRY_64_48: + case GEOMETRY_64_32: + return 64; + } + return 0; +} + +// cppcheck-suppress unusedFunction +uint OLEDDisplay::getHeight() { + switch (_geometry) { + case GEOMETRY_128_64: + return 64; + case GEOMETRY_64_48: + return 48; + case GEOMETRY_128_32: + case GEOMETRY_64_32: + return 32; + } + return 0; +} + +// cppcheck-suppress unusedFunction +void OLEDDisplay::sendInitCommands() { + sendCommand(DISPLAYOFF); + sendCommand(SETDISPLAYCLOCKDIV); + sendCommand(0xF0); // Increase speed of the display max ~96Hz + sendCommand(SETMULTIPLEX); + sendCommand(this->getHeight() - 1); + sendCommand(SETDISPLAYOFFSET); + sendCommand(0x00); + if (_geometry == GEOMETRY_64_32) { + sendCommand(0x00); + } else { + sendCommand(SETSTARTLINE); + } + sendCommand(CHARGEPUMP); + sendCommand(0x14); + sendCommand(MEMORYMODE); + sendCommand(0x00); + sendCommand(SEGREMAP); + sendCommand(COMSCANINC); + sendCommand(SETCOMPINS); + + if (_geometry == GEOMETRY_128_64 || _geometry == GEOMETRY_64_48 || _geometry == GEOMETRY_64_32) { + sendCommand(0x12); + } else if (_geometry == GEOMETRY_128_32) { + sendCommand(0x02); + } + + sendCommand(SETCONTRAST); + + if (_geometry == GEOMETRY_128_64 || _geometry == GEOMETRY_64_48 || _geometry == GEOMETRY_64_32) { + sendCommand(0xCF); + } else if (_geometry == GEOMETRY_128_32) { + sendCommand(0x8F); + } + + sendCommand(SETPRECHARGE); + sendCommand(0xF1); + sendCommand(SETVCOMDETECT); // 0xDB, (additionally needed to lower the contrast) + sendCommand(0x40); // 0x40 default, to lower the contrast, put 0 + sendCommand(DISPLAYALLON_RESUME); + sendCommand(NORMALDISPLAY); + sendCommand(0x2e); // stop scroll + sendCommand(DISPLAYON); } diff --git a/lib/Display/OLEDDisplay.h b/lib/Display/OLEDDisplay.h index 44c0ada..d679753 100644 --- a/lib/Display/OLEDDisplay.h +++ b/lib/Display/OLEDDisplay.h @@ -32,100 +32,109 @@ #ifndef OLEDDISPLAY_h #define OLEDDISPLAY_h -#include #include "Bitmap.h" +#include //#include "OLEDDisplayFonts.h" // Display commands -#define CHARGEPUMP 0x8D -#define COLUMNADDR 0x21 -#define COMSCANDEC 0xC8 -#define COMSCANINC 0xC0 -#define DISPLAYALLON 0xA5 +#define CHARGEPUMP 0x8D +#define COLUMNADDR 0x21 +#define COMSCANDEC 0xC8 +#define COMSCANINC 0xC0 +#define DISPLAYALLON 0xA5 #define DISPLAYALLON_RESUME 0xA4 -#define DISPLAYOFF 0xAE -#define DISPLAYON 0xAF -#define EXTERNALVCC 0x1 -#define INVERTDISPLAY 0xA7 -#define MEMORYMODE 0x20 -#define NORMALDISPLAY 0xA6 -#define PAGEADDR 0x22 -#define SEGREMAP 0xA0 -#define SETCOMPINS 0xDA -#define SETCONTRAST 0x81 -#define SETDISPLAYCLOCKDIV 0xD5 -#define SETDISPLAYOFFSET 0xD3 -#define SETHIGHCOLUMN 0x10 -#define SETLOWCOLUMN 0x00 -#define SETMULTIPLEX 0xA8 -#define SETPRECHARGE 0xD9 -#define SETSEGMENTREMAP 0xA1 -#define SETSTARTLINE 0x40 -#define SETVCOMDETECT 0xDB -#define SWITCHCAPVCC 0x2 +#define DISPLAYOFF 0xAE +#define DISPLAYON 0xAF +#define EXTERNALVCC 0x1 +#define INVERTDISPLAY 0xA7 +#define MEMORYMODE 0x20 +#define NORMALDISPLAY 0xA6 +#define PAGEADDR 0x22 +#define SEGREMAP 0xA0 +#define SETCOMPINS 0xDA +#define SETCONTRAST 0x81 +#define SETDISPLAYCLOCKDIV 0xD5 +#define SETDISPLAYOFFSET 0xD3 +#define SETHIGHCOLUMN 0x10 +#define SETLOWCOLUMN 0x00 +#define SETMULTIPLEX 0xA8 +#define SETPRECHARGE 0xD9 +#define SETSEGMENTREMAP 0xA1 +#define SETSTARTLINE 0x40 +#define SETVCOMDETECT 0xDB +#define SWITCHCAPVCC 0x2 enum OLEDDISPLAY_GEOMETRY { - GEOMETRY_128_64 = 0, - GEOMETRY_128_32 = 1, - GEOMETRY_64_48 = 2, - GEOMETRY_64_32 = 3 + GEOMETRY_128_64 = 0, + GEOMETRY_128_32 = 1, + GEOMETRY_64_48 = 2, + GEOMETRY_64_32 = 3 }; -class OLEDDisplay -{ +class OLEDDisplay { public: - OLEDDisplay(OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64); - virtual ~OLEDDisplay(); + OLEDDisplay(OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64); + virtual ~OLEDDisplay(); - // Turn the display on - void displayOn(); + // Turn the display on + void displayOn(); - // Turn the display offs - void displayOff(); + // Is the Display on? + bool isDisplayOn() const; - // Inverted display mode - void invertDisplay(); + // Turn the display offs + void displayOff(); - // Normal display mode - void normalDisplay(); + // Is the Display off? + bool isDisplayOff() const; - // Set display contrast - // really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0 - // normal brightness & contrast: contrast = 100 - void setContrast(uint8_t contrast, uint8_t precharge = 241, uint8_t comdetect = 64); + // Inverted display mode + void invertDisplay(); - // Convenience method to access - void setBrightness(uint8_t brightness); + // Normal display mode + void normalDisplay(); - // Reset display rotation or mirroring - void resetOrientation(); + // Set display contrast + // really low brightness & contrast: contrast = 10, precharge = 5, comdetect = 0 + // normal brightness & contrast: contrast = 100 + void setContrast(uint8_t contrast, uint8_t precharge = 241, uint8_t comdetect = 64); - // Turn the display upside down - void flipScreenVertically(); + // Convenience method to access + void setBrightness(uint8_t brightness); - // Mirror the display (to be used in a mirror or as a projector) - void mirrorScreen(); + // Reset display rotation or mirroring + void resetOrientation(); - // Write the buffer to the display memory - virtual void display(Bitmap * bitmap) = 0; + // Turn the display upside down + void flipScreenVertically(); - // Clear the local pixel buffer - void clear(); + // Mirror the display (to be used in a mirror or as a projector) + void mirrorScreen(); - // Get screen geometry - uint getWidth(); - uint getHeight(); + // Write the buffer to the display memory + void display(Bitmap *bitmap); + + // Clear the local pixel buffer + void clear(); + + // Get screen geometry + uint getWidth(); + uint getHeight(); protected: - // Send all the init commands - void sendInitCommands(); + // Send all the init commands + void sendInitCommands(); private: - OLEDDISPLAY_GEOMETRY _geometry; + OLEDDISPLAY_GEOMETRY _geometry; - // Send a command to the display (low level function) - virtual void sendCommand(uint8_t com) = 0; + // Send a command to the display (low level function) + virtual void sendCommand(uint8_t com) = 0; + + virtual void internDisplay(Bitmap *bitmap) = 0; + + bool _displayIsOn; }; #endif diff --git a/lib/Display/SSD1306.cpp b/lib/Display/SSD1306.cpp index 869d18c..63672fe 100644 --- a/lib/Display/SSD1306.cpp +++ b/lib/Display/SSD1306.cpp @@ -1,42 +1,35 @@ #include "SSD1306.h" -SSD1306::SSD1306(TwoWire * wire, uint8_t address, OLEDDISPLAY_GEOMETRY g) - : OLEDDisplay(g), _wire(wire), _address(address) -{ - sendInitCommands(); +SSD1306::SSD1306(TwoWire *wire, uint8_t address, OLEDDISPLAY_GEOMETRY g) : OLEDDisplay(g), _wire(wire), _address(address) { + sendInitCommands(); } -SSD1306::~SSD1306() -{ +SSD1306::~SSD1306() { } -void SSD1306::display(Bitmap * bitmap) -{ - sendCommand(PAGEADDR); - sendCommand(0x0); - sendCommand(0xFF); +void SSD1306::internDisplay(Bitmap *bitmap) { + sendCommand(PAGEADDR); + sendCommand(0x0); + sendCommand(0xFF); - sendCommand(COLUMNADDR); - sendCommand(0x0); - sendCommand(getWidth() - 1); + sendCommand(COLUMNADDR); + sendCommand(0x0); + sendCommand(getWidth() - 1); - for (int i = 0; i < getWidth() * getHeight() / 8; ) - { - Wire.beginTransmission(_address); - Wire.write(0x40); - for (uint8_t x = 0; x < 16; x++) - { - Wire.write(bitmap->_buffer[i]); - i++; - } - Wire.endTransmission(); - } + for (int i = 0; i < getWidth() * getHeight() / 8;) { + Wire.beginTransmission(_address); + Wire.write(0x40); + for (uint8_t x = 0; x < 16; x++) { + Wire.write(bitmap->_buffer[i]); + i++; + } + Wire.endTransmission(); + } } -void SSD1306::sendCommand(uint8_t command) -{ - _wire->beginTransmission(_address); - _wire->write(0x80); - _wire->write(command); - _wire->endTransmission(); +void SSD1306::sendCommand(uint8_t command) { + _wire->beginTransmission(_address); + _wire->write(0x80); + _wire->write(command); + _wire->endTransmission(); } diff --git a/lib/Display/SSD1306.h b/lib/Display/SSD1306.h index 01d2032..f9802e1 100644 --- a/lib/Display/SSD1306.h +++ b/lib/Display/SSD1306.h @@ -34,20 +34,19 @@ #include "OLEDDisplay.h" #include -class SSD1306 : public OLEDDisplay -{ +class SSD1306 : public OLEDDisplay { public: - SSD1306(TwoWire * wire, uint8_t address, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64); - virtual ~SSD1306(); + SSD1306(TwoWire *wire, uint8_t address, OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64); + virtual ~SSD1306(); - virtual void display(Bitmap * bitmap) override; + virtual void internDisplay(Bitmap *bitmap) override; private: - TwoWire * _wire = NULL; - uint8_t _address; - bool _doI2cAutoInit = false; + TwoWire *_wire = NULL; + uint8_t _address; + bool _doI2cAutoInit = false; - virtual void sendCommand(uint8_t command) override; + virtual void sendCommand(uint8_t command) override; }; #endif diff --git a/lib/System/System.cpp b/lib/System/System.cpp index 031b753..3ecb43a 100644 --- a/lib/System/System.cpp +++ b/lib/System/System.cpp @@ -22,3 +22,11 @@ TaskManager &System::getTaskManager() { Display &System::getDisplay() { return _display; } + +bool System::isWifiEthConnected() const { + return _isWifiEthConnected; +} + +void System::connectedViaWifiEth(bool status) { + _isWifiEthConnected = status; +} diff --git a/lib/System/System.h b/lib/System/System.h index d65feac..ab3d655 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -17,12 +17,15 @@ public: std::shared_ptr getUserConfig() const; TaskManager & getTaskManager(); Display & getDisplay(); + bool isWifiEthConnected() const; + void connectedViaWifiEth(bool status); private: std::shared_ptr _boardConfig; std::shared_ptr _userConfig; TaskManager _taskManager; Display _display; + bool _isWifiEthConnected; }; #endif diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index f2cbbe8..be0fdce 100644 --- a/lib/System/TaskManager.cpp +++ b/lib/System/TaskManager.cpp @@ -75,9 +75,3 @@ void StatusFrame::drawStatusPage(Bitmap &bitmap) { y += getSystemFont()->heightInPixel; } } - -bool StatusFrame::isPrio() const { - return std::any_of(_tasks.begin(), _tasks.end(), [](std::shared_ptr task) { - return task->getState() != Okay; - }); -} diff --git a/lib/System/TaskManager.h b/lib/System/TaskManager.h index 6851fc7..f1925a9 100644 --- a/lib/System/TaskManager.h +++ b/lib/System/TaskManager.h @@ -81,8 +81,6 @@ public: } void drawStatusPage(Bitmap &bitmap) override; - bool isPrio() const; - private: std::list> _tasks; }; diff --git a/lib/System/Timer.cpp b/lib/System/Timer.cpp index b57d673..c22e34a 100644 --- a/lib/System/Timer.cpp +++ b/lib/System/Timer.cpp @@ -1,28 +1,28 @@ #include "Timer.h" -Timer::Timer() : _timeout_sec(0), _timeout(0) { +Timer::Timer() : _timeout_ms(0), _nextTimeout(0) { } -void Timer::setTimeout(const time_t timeout_sec) { - _timeout_sec = timeout_sec; +void Timer::setTimeout(const uint32_t timeout_ms) { + _timeout_ms = timeout_ms; } -time_t Timer::getTriggerTime() const { - return _timeout; +time_t Timer::getTriggerTimeInSec() const { + return (_nextTimeout - millis()) / 1000; } bool Timer::isActive() const { - return _timeout != 0; + return _nextTimeout != 0; } void Timer::reset() { - _timeout = 0; + _nextTimeout = 0; } bool Timer::check() { - return now() > _timeout; + return millis() > _nextTimeout; } void Timer::start() { - _timeout = now() + _timeout_sec; + _nextTimeout = millis() + _timeout_ms; } diff --git a/lib/System/Timer.h b/lib/System/Timer.h index 77fe158..239f995 100644 --- a/lib/System/Timer.h +++ b/lib/System/Timer.h @@ -7,8 +7,8 @@ class Timer { public: Timer(); - void setTimeout(const time_t timeout_sec); - time_t getTriggerTime() const; + void setTimeout(const uint32_t timeout_ms); + time_t getTriggerTimeInSec() const; bool isActive() const; @@ -18,8 +18,8 @@ public: void start(); private: - time_t _timeout_sec; - time_t _timeout; + uint32_t _timeout_ms; + uint32_t _nextTimeout; }; #endif diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index eacfac0..4f5059c 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -34,9 +34,6 @@ void setup() { logPrintlnW("LoRa APRS iGate by OE5BPA (Peter Buchegger)"); logPrintlnW("Version: " VERSION); - ProjectConfigurationManagement confmg; - std::shared_ptr userConfig = confmg.readConfiguration(); - std::list> boardConfigs; // clang-format off boardConfigs.push_back(std::shared_ptr(new BoardConfig("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26))); @@ -49,8 +46,10 @@ void setup() { boardConfigs.push_back(std::shared_ptr(new BoardConfig("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26))); // clang-format on - BoardFinder finder(boardConfigs); - std::shared_ptr boardConfig = finder.getBoardConfig(userConfig->board); + ProjectConfigurationManagement confmg; + std::shared_ptr userConfig = confmg.readConfiguration(); + BoardFinder finder(boardConfigs); + std::shared_ptr boardConfig = finder.getBoardConfig(userConfig->board); if (boardConfig == 0) { boardConfig = finder.searchBoardConfig(); if (boardConfig == 0) { @@ -80,9 +79,7 @@ void setup() { powerManagement->deactivateGPS(); } - load_config(boardConfig); LoRaSystem = std::shared_ptr(new System(boardConfig, userConfig)); - LoRaSystem->getTaskManager().addTask(std::shared_ptr(new DisplayTask())); LoRaSystem->getTaskManager().addTask(std::shared_ptr(new LoraTask())); if (boardConfig->Type == eETH_BOARD) { @@ -101,6 +98,13 @@ void setup() { LoRaSystem->getDisplay().showSpashScreen("LoRa APRS iGate", VERSION); + if (userConfig->callsign == "NOCALL-10") { + logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + LoRaSystem->getDisplay().showStatusScreen("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + while (true) + ; + } + if (userConfig->display.overwritePin != 0) { pinMode(userConfig->display.overwritePin, INPUT); pinMode(userConfig->display.overwritePin, INPUT_PULLUP); diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 1d3daf1..d060043 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -15,7 +15,7 @@ AprsIsTask::~AprsIsTask() { } bool AprsIsTask::setup(std::shared_ptr system) { - _beacon_timer.setTimeout(minutesToTime_t(system->getUserConfig()->beacon.timeout)); + _beacon_timer.setTimeout(system->getUserConfig()->beacon.timeout * 60 * 1000); _aprs_is = std::shared_ptr(new APRS_IS(system->getUserConfig()->callsign, system->getUserConfig()->aprs_is.passcode, "ESP32-APRS-IS", "0.2")); _beaconMsg = std::shared_ptr(new APRSMessage()); @@ -29,6 +29,9 @@ bool AprsIsTask::setup(std::shared_ptr system) { } bool AprsIsTask::loop(std::shared_ptr system) { + if (!system->isWifiEthConnected()) { + return false; + } if (!_aprs_is->connected()) { if (!connect(system)) { _stateInfo = "not connected"; @@ -54,8 +57,8 @@ bool AprsIsTask::loop(std::shared_ptr system) { system->getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); _beacon_timer.start(); } - time_t diff = _beacon_timer.getTriggerTime() - now(); - _stateInfo = "beacon " + String(minute(diff)) + ":" + String(second(diff)); + time_t diff = _beacon_timer.getTriggerTimeInSec(); + _stateInfo = "beacon " + String(diff / 60) + ":" + String(diff % 60); _state = Okay; return true; } diff --git a/src/TaskDisplay.cpp b/src/TaskDisplay.cpp index 699e450..06d74ec 100644 --- a/src/TaskDisplay.cpp +++ b/src/TaskDisplay.cpp @@ -19,7 +19,7 @@ bool DisplayTask::setup(std::shared_ptr system) { system->getDisplay().setStatusFrame(statusFrame); if (!system->getUserConfig()->display.alwaysOn) { system->getDisplay().activateDisplaySaveMode(); - system->getDisplay().setDisplayTimeout(system->getUserConfig()->display.timeout); + system->getDisplay().setDisplaySaveTimeout(system->getUserConfig()->display.timeout); } _stateInfo = system->getUserConfig()->callsign; return true; diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index bbb6346..77ef9c6 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -75,10 +75,12 @@ bool EthTask::setup(std::shared_ptr system) { bool EthTask::loop(std::shared_ptr system) { if (!eth_connected) { + system->connectedViaWifiEth(false); _stateInfo = "Ethernet not connected"; _state = Error; return false; } + system->connectedViaWifiEth(true); _stateInfo = ETH.localIP().toString(); _state = Okay; return true; diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index d5d0f74..8bac58f 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -17,6 +17,9 @@ bool NTPTask::setup(std::shared_ptr system) { } bool NTPTask::loop(std::shared_ptr system) { + if (!system->isWifiEthConnected()) { + return false; + } if (!_beginCalled) { _ntpClient->begin(); _beginCalled = true; diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index 177fc36..db0cce9 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -27,6 +27,7 @@ bool WifiTask::setup(std::shared_ptr system) { bool WifiTask::loop(std::shared_ptr system) { const uint8_t wifi_status = _wiFiMulti->run(); if (wifi_status != WL_CONNECTED) { + system->connectedViaWifiEth(false); logPrintlnE("WiFi not connected!"); _oldWifiStatus = wifi_status; _stateInfo = "WiFi not connected"; @@ -38,6 +39,7 @@ bool WifiTask::loop(std::shared_ptr system) { _oldWifiStatus = wifi_status; return false; } + system->connectedViaWifiEth(true); _stateInfo = WiFi.localIP().toString(); _state = Okay; return true; diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index f34410a..57a23c7 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -97,21 +97,3 @@ void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptrboard; } - -std::shared_ptr load_config(std::shared_ptr boardConfig) { - ProjectConfigurationManagement confmg; - std::shared_ptr config = confmg.readConfiguration(); - if (config->callsign == "NOCALL-10") { - logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); - // show_display("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); - while (true) { - } - } - - /*if(KEY_BUILTIN != 0 && Config->display.overwritePin == 0) - { - Config->display.overwritePin = KEY_BUILTIN; - }*/ - logPrintlnI("Configuration loaded!"); - return config; -}