big update:

- display update
- timer changed to ms
- allow connections just when connected
This commit is contained in:
Peter Buchegger 2021-03-27 22:02:43 +01:00
parent c96a0310ae
commit 2c78a002ab
19 changed files with 332 additions and 351 deletions

View file

@ -2,7 +2,7 @@
#include <TaskManager.h>
#include <logger.h>
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> 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<DisplayFrame> frame = *_frames.begin();
Bitmap bitmap(_disp.get());
frame->drawStatusPage(bitmap);
activateDisplay();
_disp->display(&bitmap);
_frames.pop_front();
if (_frames.size() > 0) {
std::shared_ptr<DisplayFrame> 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<DisplayFrame> 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) {

View file

@ -29,32 +29,30 @@ public:
~Display();
void setup(std::shared_ptr<BoardConfig> boardConfig);
// setup functions
void showSpashScreen(String firmwareTitle, String version);
void setStatusFrame(std::shared_ptr<StatusFrame> 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<DisplayFrame> frame);
void setStatusFrame(std::shared_ptr<StatusFrame> frame);
void showSpashScreen(String firmwareTitle, String version);
private:
std::shared_ptr<OLEDDisplay> _disp;
Timer _displayFrameRate;
std::shared_ptr<StatusFrame> _statusFrame;
std::list<std::shared_ptr<DisplayFrame>> _frames;
std::shared_ptr<StatusFrame> _statusFrame;
Timer _frameTimeout;
Timer _displayTimeout;
bool _displayOff;
bool _displaySaveMode;
Timer _displayUpdateRate;
void activateDisplay();
void deactivateDisplay();
Timer _displaySaveModeTimer;
};
class TextFrame : public DisplayFrame {

View file

@ -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);
}

View file

@ -32,100 +32,109 @@
#ifndef OLEDDISPLAY_h
#define OLEDDISPLAY_h
#include <Arduino.h>
#include "Bitmap.h"
#include <Arduino.h>
//#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

View file

@ -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();
}

View file

@ -34,20 +34,19 @@
#include "OLEDDisplay.h"
#include <Wire.h>
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

View file

@ -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;
}

View file

@ -17,12 +17,15 @@ public:
std::shared_ptr<Configuration> getUserConfig() const;
TaskManager & getTaskManager();
Display & getDisplay();
bool isWifiEthConnected() const;
void connectedViaWifiEth(bool status);
private:
std::shared_ptr<BoardConfig> _boardConfig;
std::shared_ptr<Configuration> _userConfig;
TaskManager _taskManager;
Display _display;
bool _isWifiEthConnected;
};
#endif

View file

@ -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> task) {
return task->getState() != Okay;
});
}

View file

@ -81,8 +81,6 @@ public:
}
void drawStatusPage(Bitmap &bitmap) override;
bool isPrio() const;
private:
std::list<std::shared_ptr<Task>> _tasks;
};

View file

@ -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;
}

View file

@ -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

View file

@ -34,9 +34,6 @@ void setup() {
logPrintlnW("LoRa APRS iGate by OE5BPA (Peter Buchegger)");
logPrintlnW("Version: " VERSION);
ProjectConfigurationManagement confmg;
std::shared_ptr<Configuration> userConfig = confmg.readConfiguration();
std::list<std::shared_ptr<BoardConfig>> boardConfigs;
// clang-format off
boardConfigs.push_back(std::shared_ptr<BoardConfig>(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<BoardConfig>(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> boardConfig = finder.getBoardConfig(userConfig->board);
ProjectConfigurationManagement confmg;
std::shared_ptr<Configuration> userConfig = confmg.readConfiguration();
BoardFinder finder(boardConfigs);
std::shared_ptr<BoardConfig> 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<System>(new System(boardConfig, userConfig));
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(new DisplayTask()));
LoRaSystem->getTaskManager().addTask(std::shared_ptr<Task>(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);

View file

@ -15,7 +15,7 @@ AprsIsTask::~AprsIsTask() {
}
bool AprsIsTask::setup(std::shared_ptr<System> system) {
_beacon_timer.setTimeout(minutesToTime_t(system->getUserConfig()->beacon.timeout));
_beacon_timer.setTimeout(system->getUserConfig()->beacon.timeout * 60 * 1000);
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(system->getUserConfig()->callsign, system->getUserConfig()->aprs_is.passcode, "ESP32-APRS-IS", "0.2"));
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
@ -29,6 +29,9 @@ bool AprsIsTask::setup(std::shared_ptr<System> system) {
}
bool AprsIsTask::loop(std::shared_ptr<System> 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) {
system->getDisplay().addFrame(std::shared_ptr<DisplayFrame>(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;
}

View file

@ -19,7 +19,7 @@ bool DisplayTask::setup(std::shared_ptr<System> 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;

View file

@ -75,10 +75,12 @@ bool EthTask::setup(std::shared_ptr<System> system) {
bool EthTask::loop(std::shared_ptr<System> 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;

View file

@ -17,6 +17,9 @@ bool NTPTask::setup(std::shared_ptr<System> system) {
}
bool NTPTask::loop(std::shared_ptr<System> system) {
if (!system->isWifiEthConnected()) {
return false;
}
if (!_beginCalled) {
_ntpClient->begin();
_beginCalled = true;

View file

@ -27,6 +27,7 @@ bool WifiTask::setup(std::shared_ptr<System> system) {
bool WifiTask::loop(std::shared_ptr<System> 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> system) {
_oldWifiStatus = wifi_status;
return false;
}
system->connectedViaWifiEth(true);
_stateInfo = WiFi.localIP().toString();
_state = Okay;
return true;

View file

@ -97,21 +97,3 @@ void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptr<C
data["board"] = conf->board;
}
std::shared_ptr<Configuration> load_config(std::shared_ptr<BoardConfig> boardConfig) {
ProjectConfigurationManagement confmg;
std::shared_ptr<Configuration> 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;
}