kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
add clang-format and format all source files
rodzic
fd4e34bb6c
commit
ff25ad4696
|
@ -0,0 +1,149 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: true
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveBitFields: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortLambdasOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 500
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: false
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
...
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
"platformio.platformio-ide",
|
||||
"xaver.clang-format"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"files.insertFinalNewline": true,
|
||||
"editor.formatOnSave": true
|
||||
}
|
|
@ -1,46 +1,29 @@
|
|||
#include "BoardFinder.h"
|
||||
#include <logger.h>
|
||||
#include <power_management.h>
|
||||
#include "BoardFinder.h"
|
||||
|
||||
BoardConfig::BoardConfig(
|
||||
String name, BoardType type,
|
||||
uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset,
|
||||
uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq,
|
||||
bool needcheckpowerchip, bool powercheckstatus)
|
||||
:
|
||||
Name(name), Type(type),
|
||||
OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset),
|
||||
LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq),
|
||||
needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus)
|
||||
{
|
||||
BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus)
|
||||
: Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) {
|
||||
}
|
||||
|
||||
BoardFinder::BoardFinder(std::list<std::shared_ptr<BoardConfig>> & boardConfigs)
|
||||
: _boardConfigs(boardConfigs)
|
||||
{
|
||||
BoardFinder::BoardFinder(std::list<std::shared_ptr<BoardConfig>> &boardConfigs) : _boardConfigs(boardConfigs) {
|
||||
}
|
||||
|
||||
std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig()
|
||||
{
|
||||
std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig() {
|
||||
logPrintlnI("looking for a board config.");
|
||||
logPrintlnI("searching for OLED...");
|
||||
|
||||
for(std::shared_ptr<BoardConfig> boardconf : _boardConfigs)
|
||||
{
|
||||
if(boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus)
|
||||
{
|
||||
for (std::shared_ptr<BoardConfig> boardconf : _boardConfigs) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
||||
PowerManagement powerManagement;
|
||||
TwoWire wire(0);
|
||||
wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(wire);
|
||||
powerManagement.activateOLED();
|
||||
}
|
||||
else if(boardconf->needCheckPowerChip)
|
||||
{
|
||||
} else if (boardconf->needCheckPowerChip) {
|
||||
continue;
|
||||
}
|
||||
if(checkOledConfig(boardconf))
|
||||
{
|
||||
if (checkOledConfig(boardconf)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
|
@ -49,18 +32,15 @@ std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig()
|
|||
|
||||
logPrintlnW("could not find OLED, will search for the modem now...");
|
||||
|
||||
for(std::shared_ptr<BoardConfig> boardconf : _boardConfigs)
|
||||
{
|
||||
if(boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus)
|
||||
{
|
||||
for (std::shared_ptr<BoardConfig> boardconf : _boardConfigs) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
||||
PowerManagement powerManagement;
|
||||
TwoWire wire(0);
|
||||
wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(wire);
|
||||
powerManagement.activateLoRa();
|
||||
}
|
||||
if(checkModemConfig(boardconf))
|
||||
{
|
||||
if (checkModemConfig(boardconf)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
|
@ -72,23 +52,18 @@ std::shared_ptr<BoardConfig> BoardFinder::searchBoardConfig()
|
|||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<BoardConfig> BoardFinder::getBoardConfig(String name)
|
||||
{
|
||||
std::_List_iterator<std::shared_ptr<BoardConfig>> elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](std::shared_ptr<BoardConfig> conf)
|
||||
{
|
||||
std::shared_ptr<BoardConfig> BoardFinder::getBoardConfig(String name) {
|
||||
std::_List_iterator<std::shared_ptr<BoardConfig>> elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](std::shared_ptr<BoardConfig> conf) {
|
||||
return conf->Name == name;
|
||||
});
|
||||
if(elem == _boardConfigs.end())
|
||||
{
|
||||
if (elem == _boardConfigs.end()) {
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
if(boardConfig->OledReset > 0)
|
||||
{
|
||||
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
if (boardConfig->OledReset > 0) {
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
|
@ -97,21 +72,18 @@ bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig)
|
|||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
TwoWire wire(0);
|
||||
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
|
||||
{
|
||||
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
wire.beginTransmission(boardConfig->OledAddr);
|
||||
if(!wire.endTransmission())
|
||||
{
|
||||
if (!wire.endTransmission()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
pinMode(boardConfig->LoraReset, OUTPUT);
|
||||
digitalWrite(boardConfig->LoraReset, LOW);
|
||||
delay(10);
|
||||
|
@ -133,18 +105,15 @@ bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig)
|
|||
|
||||
digitalWrite(boardConfig->LoraCS, HIGH);
|
||||
|
||||
if(response == 0x12)
|
||||
{
|
||||
if (response == 0x12) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
TwoWire wire(0);
|
||||
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
|
||||
{
|
||||
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
|
@ -157,8 +126,7 @@ bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig)
|
|||
wire.endTransmission();
|
||||
|
||||
logPrintlnD(String(response));
|
||||
if(response == 0x03)
|
||||
{
|
||||
if (response == 0x03) {
|
||||
logPrintlnD("power chip found!");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
#include <memory>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
enum BoardType
|
||||
{
|
||||
|
@ -20,14 +20,9 @@ enum BoardType
|
|||
eTRACKERD
|
||||
};
|
||||
|
||||
class BoardConfig
|
||||
{
|
||||
class BoardConfig {
|
||||
public:
|
||||
explicit BoardConfig(
|
||||
String name, BoardType type,
|
||||
uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset,
|
||||
uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq,
|
||||
bool needcheckpowerchip = false, bool powercheckstatus = false);
|
||||
explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip = false, bool powercheckstatus = false);
|
||||
|
||||
String Name;
|
||||
BoardType Type;
|
||||
|
@ -48,10 +43,9 @@ public:
|
|||
bool powerCheckStatus;
|
||||
};
|
||||
|
||||
class BoardFinder
|
||||
{
|
||||
class BoardFinder {
|
||||
public:
|
||||
explicit BoardFinder(std::list<std::shared_ptr<BoardConfig>> & boardConfigs);
|
||||
explicit BoardFinder(std::list<std::shared_ptr<BoardConfig>> &boardConfigs);
|
||||
|
||||
std::shared_ptr<BoardConfig> searchBoardConfig();
|
||||
|
||||
|
|
|
@ -1,41 +1,33 @@
|
|||
#include "configuration.h"
|
||||
#include <SPIFFS.h>
|
||||
#include <logger.h>
|
||||
#include "configuration.h"
|
||||
|
||||
ConfigurationManagement::ConfigurationManagement(String FilePath)
|
||||
: mFilePath(FilePath)
|
||||
{
|
||||
if(!SPIFFS.begin(true))
|
||||
{
|
||||
ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) {
|
||||
if (!SPIFFS.begin(true)) {
|
||||
logPrintlnE("Mounting SPIFFS was not possible. Trying to format SPIFFS...");
|
||||
SPIFFS.format();
|
||||
if(!SPIFFS.begin())
|
||||
{
|
||||
if (!SPIFFS.begin()) {
|
||||
logPrintlnE("Formating SPIFFS was not okay!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManagement::~ConfigurationManagement()
|
||||
{
|
||||
ConfigurationManagement::~ConfigurationManagement() {
|
||||
}
|
||||
|
||||
std::shared_ptr<Configuration> ConfigurationManagement::readConfiguration()
|
||||
{
|
||||
std::shared_ptr<Configuration> ConfigurationManagement::readConfiguration() {
|
||||
File file = SPIFFS.open(mFilePath);
|
||||
if(!file)
|
||||
{
|
||||
if (!file) {
|
||||
logPrintlnE("Failed to open file for reading...");
|
||||
return 0;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
DeserializationError error = deserializeJson(data, file);
|
||||
if(error)
|
||||
{
|
||||
if (error) {
|
||||
logPrintlnW("Failed to read file, using default configuration.");
|
||||
}
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
// serializeJson(data, Serial);
|
||||
// Serial.println();
|
||||
file.close();
|
||||
|
||||
std::shared_ptr<Configuration> conf = readProjectConfiguration(data);
|
||||
|
@ -46,11 +38,9 @@ std::shared_ptr<Configuration> ConfigurationManagement::readConfiguration()
|
|||
return conf;
|
||||
}
|
||||
|
||||
void ConfigurationManagement::writeConfiguration(std::shared_ptr<Configuration> conf)
|
||||
{
|
||||
void ConfigurationManagement::writeConfiguration(std::shared_ptr<Configuration> conf) {
|
||||
File file = SPIFFS.open(mFilePath, "w");
|
||||
if(!file)
|
||||
{
|
||||
if (!file) {
|
||||
logPrintlnE("Failed to open file for writing...");
|
||||
return;
|
||||
}
|
||||
|
@ -59,7 +49,7 @@ void ConfigurationManagement::writeConfiguration(std::shared_ptr<Configuration>
|
|||
writeProjectConfiguration(conf, data);
|
||||
|
||||
serializeJson(data, file);
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
// serializeJson(data, Serial);
|
||||
// Serial.println();
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
class Configuration;
|
||||
|
||||
class ConfigurationManagement
|
||||
{
|
||||
class ConfigurationManagement {
|
||||
public:
|
||||
explicit ConfigurationManagement(String FilePath);
|
||||
virtual ~ConfigurationManagement();
|
||||
|
@ -21,8 +20,8 @@ public:
|
|||
void writeConfiguration(std::shared_ptr<Configuration> conf);
|
||||
|
||||
private:
|
||||
virtual std::shared_ptr<Configuration> readProjectConfiguration(DynamicJsonDocument & data) = 0;
|
||||
virtual void writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument & data) = 0;
|
||||
virtual std::shared_ptr<Configuration> readProjectConfiguration(DynamicJsonDocument &data) = 0;
|
||||
virtual void writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument &data) = 0;
|
||||
|
||||
const String mFilePath;
|
||||
};
|
||||
|
|
|
@ -1,100 +1,81 @@
|
|||
#include "Bitmap.h"
|
||||
#include "OLEDDisplay.h"
|
||||
#include "FontConfig.h"
|
||||
#include "OLEDDisplay.h"
|
||||
//#include "OLEDDisplayFonts.h"
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
Bitmap::Bitmap(uint width, uint height)
|
||||
: _width(width), _height(height), _buffer(0)
|
||||
{
|
||||
Bitmap::Bitmap(uint width, uint height) : _width(width), _height(height), _buffer(0) {
|
||||
allocateBuffer();
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
Bitmap::Bitmap(OLEDDisplay * display)
|
||||
: _width(display->getWidth()), _height(display->getHeight()), _buffer(0)
|
||||
{
|
||||
Bitmap::Bitmap(OLEDDisplay *display) : _width(display->getWidth()), _height(display->getHeight()), _buffer(0) {
|
||||
allocateBuffer();
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
Bitmap::~Bitmap()
|
||||
{
|
||||
if(_buffer != 0)
|
||||
{
|
||||
Bitmap::~Bitmap() {
|
||||
if (_buffer != 0) {
|
||||
delete _buffer;
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
uint Bitmap::getWidth() const
|
||||
{
|
||||
uint Bitmap::getWidth() const {
|
||||
return _width;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
uint Bitmap::getHeight() const
|
||||
{
|
||||
uint Bitmap::getHeight() const {
|
||||
return _height;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::setPixel(int x, int y)
|
||||
{
|
||||
if(x >= 0 && x < _width && y >= 0 && y < _height)
|
||||
{
|
||||
void Bitmap::setPixel(int x, int y) {
|
||||
if (x >= 0 && x < _width && y >= 0 && y < _height) {
|
||||
_buffer[x + (y / 8) * _width] |= (1 << (y % 8));
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::clearPixel(int x, int y)
|
||||
{
|
||||
if(x >= 0 && x < _width && y >= 0 && y < _height)
|
||||
{
|
||||
void Bitmap::clearPixel(int x, int y) {
|
||||
if (x >= 0 && x < _width && y >= 0 && y < _height) {
|
||||
_buffer[x + (y / 8) * _width] &= ~(1 << (y % 8));
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
bool Bitmap::getPixel(int x, int y) const
|
||||
{
|
||||
if(x >= 0 && x < _width && y >= 0 && y < _height)
|
||||
{
|
||||
bool Bitmap::getPixel(int x, int y) const {
|
||||
if (x >= 0 && x < _width && y >= 0 && y < _height) {
|
||||
return _buffer[x + (y / 8) * _width] & (1 << (y % 8));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::clear()
|
||||
{
|
||||
void Bitmap::clear() {
|
||||
memset(_buffer, 0, _width * _height / 8);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawLine(int x0, int y0, int x1, int y1)
|
||||
{
|
||||
void Bitmap::drawLine(int x0, int y0, int x1, int y1) {
|
||||
int dx = abs(x1 - x0);
|
||||
int dy = abs(y1 - y0);
|
||||
int sx = x0 < x1 ? 1 : -1;
|
||||
int sy = y0 < y1 ? 1 : -1;
|
||||
int err = (dx > dy ? dx : -dy) / 2;
|
||||
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
setPixel(x0, y0);
|
||||
if(x0 == x1 && y0 == y1)
|
||||
if (x0 == x1 && y0 == y1)
|
||||
break;
|
||||
|
||||
int e2 = err;
|
||||
if(e2 > -dx)
|
||||
{
|
||||
if (e2 > -dx) {
|
||||
err -= dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if(e2 < dy)
|
||||
{
|
||||
if (e2 < dy) {
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
|
@ -102,36 +83,29 @@ void Bitmap::drawLine(int x0, int y0, int x1, int y1)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawHorizontalLine(int x, int y, int length)
|
||||
{
|
||||
if(y < 0 || y >= _height)
|
||||
{
|
||||
void Bitmap::drawHorizontalLine(int x, int y, int length) {
|
||||
if (y < 0 || y >= _height) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
setPixel(x + i, y);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawVerticalLine(int x, int y, int length)
|
||||
{
|
||||
if (x < 0 || x >= _width)
|
||||
{
|
||||
void Bitmap::drawVerticalLine(int x, int y, int length) {
|
||||
if (x < 0 || x >= _width) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
for (int i = 0; i < length; i++) {
|
||||
setPixel(x, y + i);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawRect(int x, int y, int width, int height)
|
||||
{
|
||||
void Bitmap::drawRect(int x, int y, int width, int height) {
|
||||
drawHorizontalLine(x, y, width);
|
||||
drawVerticalLine(x, y, height);
|
||||
drawVerticalLine(x + width - 1, y, height);
|
||||
|
@ -139,33 +113,26 @@ void Bitmap::drawRect(int x, int y, int width, int height)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::fillRect(int x, int y, int width, int height)
|
||||
{
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
void Bitmap::fillRect(int x, int y, int width, int height) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
drawVerticalLine(x + i, y, height);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawCircle(int x0, int y0, int radius)
|
||||
{
|
||||
void Bitmap::drawCircle(int x0, int y0, int radius) {
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
|
||||
do
|
||||
{
|
||||
if (dp < 0)
|
||||
{
|
||||
do {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
setPixel(x0 + x, y0 + y); //For the 8 octants
|
||||
setPixel(x0 + x, y0 + y); // For the 8 octants
|
||||
setPixel(x0 - x, y0 + y);
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
|
@ -173,8 +140,7 @@ void Bitmap::drawCircle(int x0, int y0, int radius)
|
|||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
setPixel(x0 - y, y0 - x);
|
||||
}
|
||||
while (x < y);
|
||||
} while (x < y);
|
||||
|
||||
setPixel(x0 + radius, y0);
|
||||
setPixel(x0, y0 + radius);
|
||||
|
@ -183,20 +149,15 @@ void Bitmap::drawCircle(int x0, int y0, int radius)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::fillCircle(int x0, int y0, int radius)
|
||||
{
|
||||
void Bitmap::fillCircle(int x0, int y0, int radius) {
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
|
||||
do
|
||||
{
|
||||
if (dp < 0)
|
||||
{
|
||||
do {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
|
@ -204,72 +165,57 @@ void Bitmap::fillCircle(int x0, int y0, int radius)
|
|||
drawHorizontalLine(x0 - x, y0 + y, 2 * x);
|
||||
drawHorizontalLine(x0 - y, y0 - x, 2 * y);
|
||||
drawHorizontalLine(x0 - y, y0 + x, 2 * y);
|
||||
}
|
||||
while (x < y);
|
||||
} while (x < y);
|
||||
|
||||
drawHorizontalLine(x0 - radius, y0, 2 * radius);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawCircleQuads(int x0, int y0, int radius, int quads)
|
||||
{
|
||||
void Bitmap::drawCircleQuads(int x0, int y0, int radius, int quads) {
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
|
||||
while (x < y)
|
||||
{
|
||||
if (dp < 0)
|
||||
{
|
||||
while (x < y) {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
if (quads & 0x1)
|
||||
{
|
||||
if (quads & 0x1) {
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
}
|
||||
if (quads & 0x2)
|
||||
{
|
||||
if (quads & 0x2) {
|
||||
setPixel(x0 - y, y0 - x);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
}
|
||||
if (quads & 0x4)
|
||||
{
|
||||
if (quads & 0x4) {
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 - x, y0 + y);
|
||||
}
|
||||
if (quads & 0x8)
|
||||
{
|
||||
if (quads & 0x8) {
|
||||
setPixel(x0 + x, y0 + y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
}
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x8)
|
||||
{
|
||||
if (quads & 0x1 && quads & 0x8) {
|
||||
setPixel(x0 + radius, y0);
|
||||
}
|
||||
if (quads & 0x4 && quads & 0x8)
|
||||
{
|
||||
if (quads & 0x4 && quads & 0x8) {
|
||||
setPixel(x0, y0 + radius);
|
||||
}
|
||||
if (quads & 0x2 && quads & 0x4)
|
||||
{
|
||||
if (quads & 0x2 && quads & 0x4) {
|
||||
setPixel(x0 - radius, y0);
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x2)
|
||||
{
|
||||
if (quads & 0x1 && quads & 0x2) {
|
||||
setPixel(x0, y0 - radius);
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawProgressBar(int x, int y, int width, int height, int progress)
|
||||
{
|
||||
void Bitmap::drawProgressBar(int x, int y, int width, int height, int progress) {
|
||||
int radius = height / 2;
|
||||
int xRadius = x + radius;
|
||||
int yRadius = y + radius;
|
||||
|
@ -289,49 +235,40 @@ void Bitmap::drawProgressBar(int x, int y, int width, int height, int progress)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int Bitmap::drawChar(int x, int y, char c)
|
||||
{
|
||||
fontDesc_t const * font = getSystemFont();
|
||||
int Bitmap::drawChar(int x, int y, char c) {
|
||||
fontDesc_t const *font = getSystemFont();
|
||||
|
||||
if(c == ' ')
|
||||
{
|
||||
if (c == ' ') {
|
||||
return x + font->widthInPixel * 4 / 10;
|
||||
}
|
||||
|
||||
unsigned char cu = (unsigned char)c;
|
||||
if(cu < font->firstChar || cu > font->lastChar)
|
||||
{
|
||||
if (cu < font->firstChar || cu > font->lastChar) {
|
||||
cu = '?';
|
||||
}
|
||||
|
||||
int firstPixelBitPos = 0;
|
||||
for(int i = 0; i < (cu - font->firstChar); i++)
|
||||
{
|
||||
for (int i = 0; i < (cu - font->firstChar); i++) {
|
||||
firstPixelBitPos = firstPixelBitPos + font->pData[i];
|
||||
}
|
||||
firstPixelBitPos = firstPixelBitPos * font->heightInPixel;
|
||||
|
||||
unsigned char const * pDataStart = &(font->pData[font->lastChar - font->firstChar + 1]);
|
||||
unsigned char const *pDataStart = &(font->pData[font->lastChar - font->firstChar + 1]);
|
||||
const int top = y;
|
||||
const int widthInPixel = font->pData[cu - font->firstChar];
|
||||
for(int i = 0; i < widthInPixel * font->heightInPixel; i++ )
|
||||
{
|
||||
for (int i = 0; i < widthInPixel * font->heightInPixel; i++) {
|
||||
int bytePos = firstPixelBitPos / 8;
|
||||
int bitPos = firstPixelBitPos % 8;
|
||||
|
||||
if(pDataStart[bytePos] & ( 1 << bitPos))
|
||||
{
|
||||
if (pDataStart[bytePos] & (1 << bitPos)) {
|
||||
setPixel(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
clearPixel(x, y);
|
||||
}
|
||||
|
||||
firstPixelBitPos++;
|
||||
y++;
|
||||
if(y == top + font->heightInPixel)
|
||||
{
|
||||
if (y == top + font->heightInPixel) {
|
||||
y = top;
|
||||
x++;
|
||||
}
|
||||
|
@ -341,19 +278,16 @@ int Bitmap::drawChar(int x, int y, char c)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int Bitmap::drawString(int x, int y, String text)
|
||||
{
|
||||
int Bitmap::drawString(int x, int y, String text) {
|
||||
int next_x = x;
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
next_x = drawChar(next_x, y, text[i]);
|
||||
}
|
||||
return next_x;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawStringf(int x, int y, char * buffer, String format, ... )
|
||||
{
|
||||
void Bitmap::drawStringf(int x, int y, char *buffer, String format, ...) {
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
|
@ -362,14 +296,11 @@ void Bitmap::drawStringf(int x, int y, char * buffer, String format, ... )
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int Bitmap::drawStringLF(int x, int y, String text)
|
||||
{
|
||||
fontDesc_t const * font = getSystemFont();
|
||||
int Bitmap::drawStringLF(int x, int y, String text) {
|
||||
fontDesc_t const *font = getSystemFont();
|
||||
int next_x = x;
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
if(next_x + font->widthInPixel > _width)
|
||||
{
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (next_x + font->widthInPixel > _width) {
|
||||
next_x = 0;
|
||||
y += font->heightInPixel;
|
||||
}
|
||||
|
@ -379,8 +310,7 @@ int Bitmap::drawStringLF(int x, int y, String text)
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawStringLFf(int x, int y, char * buffer, String format, ... )
|
||||
{
|
||||
void Bitmap::drawStringLFf(int x, int y, char *buffer, String format, ...) {
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
|
@ -417,8 +347,7 @@ void Bitmap::drawStringLFf(int x, int y, char * buffer, String format, ... )
|
|||
}*/
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::allocateBuffer()
|
||||
{
|
||||
void Bitmap::allocateBuffer() {
|
||||
_buffer = new uint8_t[_width * _height / 8];
|
||||
clear();
|
||||
}
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
class OLEDDisplay;
|
||||
|
||||
class Bitmap
|
||||
{
|
||||
class Bitmap {
|
||||
public:
|
||||
explicit Bitmap(uint width, uint height);
|
||||
explicit Bitmap(OLEDDisplay * display);
|
||||
explicit Bitmap(OLEDDisplay *display);
|
||||
virtual ~Bitmap();
|
||||
|
||||
uint getWidth() const;
|
||||
|
@ -36,17 +35,17 @@ public:
|
|||
|
||||
int drawChar(int x, int y, char c);
|
||||
int drawString(int x, int y, String text);
|
||||
void drawStringf(int x, int y, char * buffer, String format, ... );
|
||||
void drawStringf(int x, int y, char *buffer, String format, ...);
|
||||
int drawStringLF(int x, int y, String text);
|
||||
void drawStringLFf(int x, int y, char * buffer, String format, ... );
|
||||
void drawStringLFf(int x, int y, char *buffer, String format, ...);
|
||||
|
||||
//void drawBitmap(int x, int y, const Bitmap & bitmap);
|
||||
// void drawBitmap(int x, int y, const Bitmap & bitmap);
|
||||
|
||||
private:
|
||||
const uint _width;
|
||||
const uint _height;
|
||||
|
||||
uint8_t * _buffer;
|
||||
uint8_t *_buffer;
|
||||
|
||||
void allocateBuffer();
|
||||
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
#include <logger.h>
|
||||
#include "Display.h"
|
||||
#include <TaskManager.h>
|
||||
#include <logger.h>
|
||||
|
||||
Display::Display()
|
||||
: _disp(0), _statusFrame(0), _displayOff(false)
|
||||
{
|
||||
Display::Display() : _disp(0), _statusFrame(0), _displayOff(false) {
|
||||
}
|
||||
|
||||
void Display::setup(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
if(boardConfig->OledReset != 0)
|
||||
{
|
||||
void Display::setup(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
if (boardConfig->OledReset != 0) {
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
|
@ -27,17 +23,13 @@ void Display::setup(std::shared_ptr<BoardConfig> boardConfig)
|
|||
_frameTimeout.setTimeout(15);
|
||||
}
|
||||
|
||||
void Display::turn180()
|
||||
{
|
||||
void Display::turn180() {
|
||||
_disp->flipScreenVertically();
|
||||
}
|
||||
|
||||
void Display::update()
|
||||
{
|
||||
if(_frameTimeout.check())
|
||||
{
|
||||
if(_statusFrame->isPrio())
|
||||
{
|
||||
void Display::update() {
|
||||
if (_frameTimeout.check()) {
|
||||
if (_statusFrame->isPrio()) {
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
|
@ -45,8 +37,7 @@ void Display::update()
|
|||
return;
|
||||
}
|
||||
|
||||
if(_frames.size() > 0)
|
||||
{
|
||||
if (_frames.size() > 0) {
|
||||
std::shared_ptr<DisplayFrame> frame = *_frames.begin();
|
||||
Bitmap bitmap(_disp.get());
|
||||
frame->drawStatusPage(bitmap);
|
||||
|
@ -57,60 +48,50 @@ void Display::update()
|
|||
return;
|
||||
}
|
||||
|
||||
if(!_displayOff && !_displayTimeout.isActive())
|
||||
{
|
||||
if (!_displayOff && !_displayTimeout.isActive()) {
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
_disp->display(&bitmap);
|
||||
_displayTimeout.start();
|
||||
}
|
||||
if(_displayTimeout.check())
|
||||
{
|
||||
if (_displayTimeout.check()) {
|
||||
deactivateDisplay();
|
||||
_displayTimeout.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Display::addFrame(std::shared_ptr<DisplayFrame> frame)
|
||||
{
|
||||
void Display::addFrame(std::shared_ptr<DisplayFrame> frame) {
|
||||
_frames.push_back(frame);
|
||||
}
|
||||
|
||||
void Display::setStatusFrame(std::shared_ptr<StatusFrame> frame)
|
||||
{
|
||||
void Display::setStatusFrame(std::shared_ptr<StatusFrame> frame) {
|
||||
_statusFrame = frame;
|
||||
}
|
||||
|
||||
void Display::showSpashScreen(String firmwareTitle, String version)
|
||||
{
|
||||
void Display::showSpashScreen(String firmwareTitle, String version) {
|
||||
Bitmap bitmap(_disp.get());
|
||||
bitmap.drawString( 0, 10, firmwareTitle);
|
||||
bitmap.drawString( 0, 20, version);
|
||||
bitmap.drawString( 0, 35, "by Peter Buchegger");
|
||||
bitmap.drawString(0, 10, firmwareTitle);
|
||||
bitmap.drawString(0, 20, version);
|
||||
bitmap.drawString(0, 35, "by Peter Buchegger");
|
||||
bitmap.drawString(30, 45, "OE5BPA");
|
||||
_disp->display(&bitmap);
|
||||
}
|
||||
|
||||
void Display::activateDisplay()
|
||||
{
|
||||
if(_displayOff)
|
||||
{
|
||||
void Display::activateDisplay() {
|
||||
if (_displayOff) {
|
||||
_disp->displayOn();
|
||||
_displayOff = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Display::deactivateDisplay()
|
||||
{
|
||||
void Display::deactivateDisplay() {
|
||||
_disp->displayOff();
|
||||
_displayOff = true;
|
||||
}
|
||||
|
||||
|
||||
void TextFrame::drawStatusPage(Bitmap & bitmap)
|
||||
{
|
||||
void TextFrame::drawStatusPage(Bitmap &bitmap) {
|
||||
bitmap.drawString(0, 0, _header);
|
||||
bitmap.drawStringLF(0, 10, _text);
|
||||
}
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
#ifndef DISPLAY_H_
|
||||
#define DISPLAY_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <TimeLib.h>
|
||||
#include <SSD1306.h>
|
||||
#include <BoardFinder.h>
|
||||
#include <SSD1306.h>
|
||||
#include <TimeLib.h>
|
||||
#include <Timer.h>
|
||||
#include <Wire.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class Timer;
|
||||
class StatusFrame;
|
||||
|
||||
class DisplayFrame
|
||||
{
|
||||
class DisplayFrame {
|
||||
public:
|
||||
DisplayFrame() {}
|
||||
virtual ~DisplayFrame() {}
|
||||
virtual void drawStatusPage(Bitmap & bitmap) = 0;
|
||||
DisplayFrame() {
|
||||
}
|
||||
virtual ~DisplayFrame() {
|
||||
}
|
||||
virtual void drawStatusPage(Bitmap &bitmap) = 0;
|
||||
};
|
||||
|
||||
class Display
|
||||
{
|
||||
class Display {
|
||||
public:
|
||||
static Display & instance()
|
||||
{
|
||||
static Display &instance() {
|
||||
static Display _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
~Display() {}
|
||||
~Display() {
|
||||
}
|
||||
|
||||
void setup(std::shared_ptr<BoardConfig> boardConfig);
|
||||
void turn180();
|
||||
|
@ -55,18 +55,19 @@ private:
|
|||
|
||||
Display();
|
||||
Display(const Display &);
|
||||
Display & operator = (const Display &);
|
||||
Display &operator=(const Display &);
|
||||
|
||||
void activateDisplay();
|
||||
void deactivateDisplay();
|
||||
};
|
||||
|
||||
class TextFrame : public DisplayFrame
|
||||
{
|
||||
class TextFrame : public DisplayFrame {
|
||||
public:
|
||||
TextFrame(String header, String text) : _header(header), _text(text) {}
|
||||
virtual ~TextFrame() {}
|
||||
void drawStatusPage(Bitmap & bitmap) override;
|
||||
TextFrame(String header, String text) : _header(header), _text(text) {
|
||||
}
|
||||
virtual ~TextFrame() {
|
||||
}
|
||||
void drawStatusPage(Bitmap &bitmap) override;
|
||||
|
||||
private:
|
||||
String _header;
|
||||
|
|
|
@ -1,35 +1,27 @@
|
|||
#include <BoardFinder.h>
|
||||
#include "LoRa_APRS.h"
|
||||
|
||||
LoRa_APRS::LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig)
|
||||
: _LastReceivedMsg(0), _RxFrequency(LORA_RX_FREQUENCY), _TxFrequency(LORA_TX_FREQUENCY)
|
||||
{
|
||||
LoRa_APRS::LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig) : _LastReceivedMsg(0), _RxFrequency(LORA_RX_FREQUENCY), _TxFrequency(LORA_TX_FREQUENCY) {
|
||||
SPI.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
|
||||
setPins(boardConfig->LoraCS, boardConfig->LoraReset, boardConfig->LoraIRQ);
|
||||
}
|
||||
|
||||
bool LoRa_APRS::checkMessage()
|
||||
{
|
||||
if(!parsePacket())
|
||||
{
|
||||
bool LoRa_APRS::checkMessage() {
|
||||
if (!parsePacket()) {
|
||||
return false;
|
||||
}
|
||||
// read header:
|
||||
char dummy[4];
|
||||
readBytes(dummy, 3);
|
||||
if(dummy[0] != '<')
|
||||
{
|
||||
if (dummy[0] != '<') {
|
||||
// is no APRS message, ignore message
|
||||
while(available())
|
||||
{
|
||||
while (available()) {
|
||||
read();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// read APRS data:
|
||||
String str;
|
||||
while(available())
|
||||
{
|
||||
while (available()) {
|
||||
str += (char)read();
|
||||
}
|
||||
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
|
@ -37,14 +29,12 @@ bool LoRa_APRS::checkMessage()
|
|||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage()
|
||||
{
|
||||
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage() {
|
||||
return _LastReceivedMsg;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg)
|
||||
{
|
||||
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg) {
|
||||
setFrequency(_TxFrequency);
|
||||
String data = msg->encode();
|
||||
beginPacket();
|
||||
|
@ -58,24 +48,20 @@ void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg)
|
|||
setFrequency(_RxFrequency);
|
||||
}
|
||||
|
||||
void LoRa_APRS::setRxFrequency(long frequency)
|
||||
{
|
||||
void LoRa_APRS::setRxFrequency(long frequency) {
|
||||
_RxFrequency = frequency;
|
||||
setFrequency(_RxFrequency);
|
||||
}
|
||||
|
||||
long LoRa_APRS::getRxFrequency() const
|
||||
{
|
||||
long LoRa_APRS::getRxFrequency() const {
|
||||
return _RxFrequency;
|
||||
}
|
||||
|
||||
void LoRa_APRS::setTxFrequency(long frequency)
|
||||
{
|
||||
void LoRa_APRS::setTxFrequency(long frequency) {
|
||||
_TxFrequency = frequency;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
long LoRa_APRS::getTxFrequency() const
|
||||
{
|
||||
long LoRa_APRS::getTxFrequency() const {
|
||||
return _TxFrequency;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#ifndef LORA_H_
|
||||
#define LORA_H_
|
||||
|
||||
#include <memory>
|
||||
#include <Arduino.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
#include <APRS-Decoder.h>
|
||||
#include <BoardFinder.h>
|
||||
#include <LoRa.h>
|
||||
#include <memory>
|
||||
|
||||
#define LORA_RX_FREQUENCY (433775000)
|
||||
#define LORA_TX_FREQUENCY (433900000)
|
||||
|
@ -12,8 +14,7 @@
|
|||
#define LORA_SIGNAL_BANDWIDTH (125E3)
|
||||
#define LORA_CODING_RATE4 (5)
|
||||
|
||||
class LoRa_APRS : public LoRaClass
|
||||
{
|
||||
class LoRa_APRS : public LoRaClass {
|
||||
public:
|
||||
explicit LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig);
|
||||
|
||||
|
|
|
@ -2,54 +2,44 @@
|
|||
#include "power_management.h"
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PowerManagement::PowerManagement()
|
||||
{
|
||||
PowerManagement::PowerManagement() {
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
bool PowerManagement::begin(TwoWire & port)
|
||||
{
|
||||
bool PowerManagement::begin(TwoWire &port) {
|
||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
||||
if(!result)
|
||||
{
|
||||
if (!result) {
|
||||
axp.setDCDC1Voltage(3300);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateLoRa()
|
||||
{
|
||||
void PowerManagement::activateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateLoRa()
|
||||
{
|
||||
void PowerManagement::deactivateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateGPS()
|
||||
{
|
||||
void PowerManagement::activateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateGPS()
|
||||
{
|
||||
void PowerManagement::deactivateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateOLED()
|
||||
{
|
||||
void PowerManagement::activateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::decativateOLED()
|
||||
{
|
||||
void PowerManagement::decativateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
#include <Arduino.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
class PowerManagement
|
||||
{
|
||||
class PowerManagement {
|
||||
public:
|
||||
PowerManagement();
|
||||
bool begin(TwoWire & port);
|
||||
bool begin(TwoWire &port);
|
||||
|
||||
void activateLoRa();
|
||||
void deactivateLoRa();
|
||||
|
|
|
@ -1,75 +1,59 @@
|
|||
#include <logger.h>
|
||||
#include "TaskManager.h"
|
||||
#include <FontConfig.h>
|
||||
#include <logger.h>
|
||||
|
||||
TaskManager::TaskManager()
|
||||
{
|
||||
TaskManager::TaskManager() {
|
||||
}
|
||||
|
||||
void TaskManager::addTask(std::shared_ptr<Task> task)
|
||||
{
|
||||
void TaskManager::addTask(std::shared_ptr<Task> task) {
|
||||
_tasks.push_back(task);
|
||||
}
|
||||
|
||||
std::shared_ptr<Task> TaskManager::getTask(const char * name)
|
||||
{
|
||||
std::_List_iterator<std::shared_ptr<Task>> elem = std::find_if(_tasks.begin(), _tasks.end(), [&](std::shared_ptr<Task> task)
|
||||
{
|
||||
std::shared_ptr<Task> TaskManager::getTask(const char *name) {
|
||||
std::_List_iterator<std::shared_ptr<Task>> elem = std::find_if(_tasks.begin(), _tasks.end(), [&](std::shared_ptr<Task> task) {
|
||||
return task->getName() == name;
|
||||
});
|
||||
if(elem == _tasks.end())
|
||||
{
|
||||
if (elem == _tasks.end()) {
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<Task>> TaskManager::getTasks()
|
||||
{
|
||||
std::list<std::shared_ptr<Task>> TaskManager::getTasks() {
|
||||
return _tasks;
|
||||
}
|
||||
|
||||
bool TaskManager::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool TaskManager::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
logPrintlnV("will setup all tasks...");
|
||||
for(std::shared_ptr<Task> & elem : _tasks)
|
||||
{
|
||||
for (std::shared_ptr<Task> &elem : _tasks) {
|
||||
logPrintW("call setup from ");
|
||||
logPrintlnW(elem->getName());
|
||||
if(!elem->setup(config, boardConfig))
|
||||
{
|
||||
if (!elem->setup(config, boardConfig)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskManager::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
//logPrintlnD("will loop all tasks...");
|
||||
for(std::shared_ptr<Task> & elem : _tasks)
|
||||
{
|
||||
//logPrintD("call loop from ");
|
||||
//logPrintlnD(elem->getName());
|
||||
if(!elem->loop(config))
|
||||
{
|
||||
bool TaskManager::loop(std::shared_ptr<Configuration> config) {
|
||||
// logPrintlnD("will loop all tasks...");
|
||||
for (std::shared_ptr<Task> &elem : _tasks) {
|
||||
// logPrintD("call loop from ");
|
||||
// logPrintlnD(elem->getName());
|
||||
if (!elem->loop(config)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void StatusFrame::drawStatusPage(Bitmap & bitmap)
|
||||
{
|
||||
void StatusFrame::drawStatusPage(Bitmap &bitmap) {
|
||||
int y = 0;
|
||||
for(std::shared_ptr<Task> task : _tasks)
|
||||
{
|
||||
for (std::shared_ptr<Task> task : _tasks) {
|
||||
int x = bitmap.drawString(0, y, (task->getName()).substring(0, task->getName().indexOf("Task")));
|
||||
x = bitmap.drawString(x, y, ": ");
|
||||
if(task->getStateInfo() == "")
|
||||
{
|
||||
switch (task->getState())
|
||||
{
|
||||
if (task->getStateInfo() == "") {
|
||||
switch (task->getState()) {
|
||||
case Error:
|
||||
bitmap.drawString(x, y, "Error");
|
||||
break;
|
||||
|
@ -79,19 +63,15 @@ void StatusFrame::drawStatusPage(Bitmap & bitmap)
|
|||
break;
|
||||
}
|
||||
bitmap.drawString(x, y, "Okay");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
bitmap.drawString(x, y, task->getStateInfo());
|
||||
}
|
||||
y += getSystemFont()->heightInPixel;
|
||||
}
|
||||
}
|
||||
|
||||
bool StatusFrame::isPrio() const
|
||||
{
|
||||
return std::any_of(_tasks.begin(), _tasks.end(), [](std::shared_ptr<Task> task)
|
||||
{
|
||||
bool StatusFrame::isPrio() const {
|
||||
return std::any_of(_tasks.begin(), _tasks.end(), [](std::shared_ptr<Task> task) {
|
||||
return task->getState() != Okay;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef TASK_MANAGER_H_
|
||||
#define TASK_MANAGER_H_
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <Arduino.h>
|
||||
#include <configuration.h>
|
||||
#include <BoardFinder.h>
|
||||
#include <Display.h>
|
||||
#include <configuration.h>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "TaskQueue.h"
|
||||
|
||||
|
@ -17,18 +17,28 @@ enum TaskDisplayState
|
|||
Okay,
|
||||
};
|
||||
|
||||
class Task
|
||||
{
|
||||
class Task {
|
||||
public:
|
||||
Task(String & name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {}
|
||||
Task(const char * name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {}
|
||||
virtual ~Task() {}
|
||||
Task(String &name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {
|
||||
}
|
||||
Task(const char *name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {
|
||||
}
|
||||
virtual ~Task() {
|
||||
}
|
||||
|
||||
String getName() const { return _name; }
|
||||
int getTaskId() const { return _taskId; }
|
||||
String getName() const {
|
||||
return _name;
|
||||
}
|
||||
int getTaskId() const {
|
||||
return _taskId;
|
||||
}
|
||||
|
||||
TaskDisplayState getState() const { return _state; }
|
||||
String getStateInfo() const { return _stateInfo; }
|
||||
TaskDisplayState getState() const {
|
||||
return _state;
|
||||
}
|
||||
String getStateInfo() const {
|
||||
return _stateInfo;
|
||||
}
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
|
||||
|
@ -42,19 +52,18 @@ private:
|
|||
int _taskId;
|
||||
};
|
||||
|
||||
class TaskManager
|
||||
{
|
||||
class TaskManager {
|
||||
public:
|
||||
static TaskManager & instance()
|
||||
{
|
||||
static TaskManager &instance() {
|
||||
static TaskManager _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
~TaskManager() {}
|
||||
~TaskManager() {
|
||||
}
|
||||
|
||||
void addTask(std::shared_ptr<Task> task);
|
||||
std::shared_ptr<Task> getTask(const char * name);
|
||||
std::shared_ptr<Task> getTask(const char *name);
|
||||
std::list<std::shared_ptr<Task>> getTasks();
|
||||
|
||||
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
|
||||
|
@ -65,15 +74,16 @@ private:
|
|||
|
||||
TaskManager();
|
||||
TaskManager(const TaskManager &);
|
||||
TaskManager & operator = (const TaskManager &);
|
||||
TaskManager &operator=(const TaskManager &);
|
||||
};
|
||||
|
||||
class StatusFrame : public DisplayFrame
|
||||
{
|
||||
class StatusFrame : public DisplayFrame {
|
||||
public:
|
||||
explicit StatusFrame(const std::list<std::shared_ptr<Task>> & tasks) : _tasks(tasks) {}
|
||||
virtual ~StatusFrame() {}
|
||||
void drawStatusPage(Bitmap & bitmap) override;
|
||||
explicit StatusFrame(const std::list<std::shared_ptr<Task>> &tasks) : _tasks(tasks) {
|
||||
}
|
||||
virtual ~StatusFrame() {
|
||||
}
|
||||
void drawStatusPage(Bitmap &bitmap) override;
|
||||
|
||||
bool isPrio() const;
|
||||
|
||||
|
|
|
@ -3,26 +3,22 @@
|
|||
|
||||
#include <list>
|
||||
|
||||
template <typename T>
|
||||
class TaskQueue
|
||||
{
|
||||
template <typename T> class TaskQueue {
|
||||
public:
|
||||
TaskQueue() {}
|
||||
TaskQueue() {
|
||||
}
|
||||
|
||||
void addElement(T elem)
|
||||
{
|
||||
void addElement(T elem) {
|
||||
_elements.push_back(elem);
|
||||
}
|
||||
|
||||
T getElement()
|
||||
{
|
||||
T getElement() {
|
||||
T elem = _elements.front();
|
||||
_elements.pop_front();
|
||||
return elem;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
bool empty() const {
|
||||
return _elements.empty();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,36 +1,28 @@
|
|||
#include "Timer.h"
|
||||
|
||||
Timer::Timer()
|
||||
: _timeout_sec(0), _timeout(0)
|
||||
{
|
||||
Timer::Timer() : _timeout_sec(0), _timeout(0) {
|
||||
}
|
||||
|
||||
void Timer::setTimeout(const time_t timeout_sec)
|
||||
{
|
||||
void Timer::setTimeout(const time_t timeout_sec) {
|
||||
_timeout_sec = timeout_sec;
|
||||
}
|
||||
|
||||
time_t Timer::getTriggerTime() const
|
||||
{
|
||||
time_t Timer::getTriggerTime() const {
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool Timer::isActive() const
|
||||
{
|
||||
bool Timer::isActive() const {
|
||||
return _timeout != 0;
|
||||
}
|
||||
|
||||
void Timer::reset()
|
||||
{
|
||||
void Timer::reset() {
|
||||
_timeout = 0;
|
||||
}
|
||||
|
||||
bool Timer::check()
|
||||
{
|
||||
bool Timer::check() {
|
||||
return now() > _timeout;
|
||||
}
|
||||
|
||||
void Timer::start()
|
||||
{
|
||||
void Timer::start() {
|
||||
_timeout = now() + _timeout_sec;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include <TimeLib.h>
|
||||
|
||||
class Timer
|
||||
{
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
#include <map>
|
||||
|
||||
#include <logger.h>
|
||||
#include <APRS-IS.h>
|
||||
#include <TimeLib.h>
|
||||
|
||||
#include <BoardFinder.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
#include "BoardFinder.h"
|
||||
//#include "display.h"
|
||||
#include "power_management.h"
|
||||
#include "project_configuration.h"
|
||||
#include <TimeLib.h>
|
||||
#include <logger.h>
|
||||
#include <power_management.h>
|
||||
|
||||
#include "TaskAprsIs.h"
|
||||
#include "TaskDisplay.h"
|
||||
|
@ -19,6 +15,7 @@
|
|||
#include "TaskNTP.h"
|
||||
#include "TaskOTA.h"
|
||||
#include "TaskWifi.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
#define VERSION "21.06.0-dev"
|
||||
|
||||
|
@ -30,8 +27,7 @@ std::shared_ptr<BoardConfig> boardConfig;
|
|||
HardwareSerial Serial(0);
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Logger::instance().setSerial(&Serial);
|
||||
delay(500);
|
||||
|
@ -42,6 +38,7 @@ void setup()
|
|||
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)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true)));
|
||||
|
@ -50,17 +47,16 @@ void setup()
|
|||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26)));
|
||||
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);
|
||||
boardConfig = finder.getBoardConfig(userConfig->board);
|
||||
if(boardConfig == 0)
|
||||
{
|
||||
if (boardConfig == 0) {
|
||||
boardConfig = finder.searchBoardConfig();
|
||||
if(boardConfig == 0)
|
||||
{
|
||||
if (boardConfig == 0) {
|
||||
logPrintlnE("Board config not set and search failed!");
|
||||
while(true)
|
||||
{}
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
userConfig->board = boardConfig->Name;
|
||||
confmg.writeConfiguration(userConfig);
|
||||
|
@ -71,16 +67,12 @@ void setup()
|
|||
logPrintI(boardConfig->Name);
|
||||
logPrintlnI(" loaded.");
|
||||
|
||||
if(boardConfig->Type == eTTGO_T_Beam_V1_0)
|
||||
{
|
||||
if (boardConfig->Type == eTTGO_T_Beam_V1_0) {
|
||||
Wire.begin(boardConfig->OledSda, boardConfig->OledScl);
|
||||
std::shared_ptr<PowerManagement> powerManagement = std::shared_ptr<PowerManagement>(new PowerManagement);
|
||||
if (!powerManagement->begin(Wire))
|
||||
{
|
||||
if (!powerManagement->begin(Wire)) {
|
||||
logPrintlnI("AXP192 init done!");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
logPrintlnE("AXP192 init failed!");
|
||||
}
|
||||
powerManagement->activateLoRa();
|
||||
|
@ -92,15 +84,13 @@ void setup()
|
|||
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new DisplayTask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new LoraTask()));
|
||||
if(boardConfig->Type == eETH_BOARD)
|
||||
{
|
||||
if (boardConfig->Type == eETH_BOARD) {
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new EthTask()));
|
||||
}
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new WifiTask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new OTATask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new NTPTask()));
|
||||
if(userConfig->ftp.active)
|
||||
{
|
||||
if (userConfig->ftp.active) {
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new FTPTask()));
|
||||
}
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new AprsIsTask()));
|
||||
|
@ -109,8 +99,7 @@ void setup()
|
|||
|
||||
Display::instance().showSpashScreen("LoRa APRS iGate", VERSION);
|
||||
|
||||
if(userConfig->display.overwritePin != 0)
|
||||
{
|
||||
if (userConfig->display.overwritePin != 0) {
|
||||
pinMode(userConfig->display.overwritePin, INPUT);
|
||||
pinMode(userConfig->display.overwritePin, INPUT_PULLUP);
|
||||
}
|
||||
|
@ -120,17 +109,14 @@ void setup()
|
|||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
TaskManager::instance().loop(userConfig);
|
||||
}
|
||||
|
||||
String create_lat_aprs(double lat)
|
||||
{
|
||||
String create_lat_aprs(double lat) {
|
||||
char str[20];
|
||||
char n_s = 'N';
|
||||
if(lat < 0)
|
||||
{
|
||||
if (lat < 0) {
|
||||
n_s = 'S';
|
||||
}
|
||||
lat = std::abs(lat);
|
||||
|
@ -139,12 +125,10 @@ String create_lat_aprs(double lat)
|
|||
return lat_str;
|
||||
}
|
||||
|
||||
String create_long_aprs(double lng)
|
||||
{
|
||||
String create_long_aprs(double lng) {
|
||||
char str[20];
|
||||
char e_w = 'E';
|
||||
if(lng < 0)
|
||||
{
|
||||
if (lng < 0) {
|
||||
e_w = 'W';
|
||||
}
|
||||
lng = std::abs(lng);
|
||||
|
|
26
src/Task.cpp
26
src/Task.cpp
|
@ -1,26 +0,0 @@
|
|||
#include "Task.h"
|
||||
|
||||
/*char const * const getTaskName(TaskNames task)
|
||||
{
|
||||
switch (task)
|
||||
{
|
||||
case TaskDisplay:
|
||||
return "Display";
|
||||
case TaskAprsIs:
|
||||
return "APRS-IS";
|
||||
case TaskEth:
|
||||
return "ETH";
|
||||
case TaskFtp:
|
||||
return "FTP";
|
||||
case TaskLora:
|
||||
return "LORA";
|
||||
case TaskNtp:
|
||||
return "NTP";
|
||||
case TaskOta:
|
||||
return "OTA";
|
||||
case TaskWifi:
|
||||
return "WIFI";
|
||||
default:
|
||||
return "error";
|
||||
}
|
||||
}*/
|
|
@ -13,7 +13,7 @@ enum TaskNames
|
|||
TaskSize,
|
||||
};
|
||||
|
||||
//char const * const getTaskName(TaskNames task);
|
||||
// char const * const getTaskName(TaskNames task);
|
||||
|
||||
#define TASK_APRS_IS "AprsIsTask"
|
||||
#define TASK_ETH "EthTask"
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
#include <logger.h>
|
||||
#include <TimeLib.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskAprsIs.h"
|
||||
#include <logger.h>
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskAprsIs.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
String create_lat_aprs(double lat);
|
||||
String create_long_aprs(double lng);
|
||||
|
||||
AprsIsTask::AprsIsTask()
|
||||
: Task(TASK_APRS_IS, TaskAprsIs)
|
||||
{
|
||||
AprsIsTask::AprsIsTask() : Task(TASK_APRS_IS, TaskAprsIs) {
|
||||
}
|
||||
|
||||
AprsIsTask::~AprsIsTask()
|
||||
{
|
||||
AprsIsTask::~AprsIsTask() {
|
||||
}
|
||||
|
||||
bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_beacon_timer.setTimeout(minutesToTime_t(config->beacon.timeout));
|
||||
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(config->callsign, config->aprs_is.passcode , "ESP32-APRS-IS", "0.2"));
|
||||
_aprs_is = std::shared_ptr<APRS_IS>(new APRS_IS(config->callsign, config->aprs_is.passcode, "ESP32-APRS-IS", "0.2"));
|
||||
|
||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_beaconMsg->setSource(config->callsign);
|
||||
|
@ -31,12 +28,9 @@ bool AprsIsTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Bo
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_aprs_is->connected())
|
||||
{
|
||||
if(!connect(config))
|
||||
{
|
||||
bool AprsIsTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_aprs_is->connected()) {
|
||||
if (!connect(config)) {
|
||||
_stateInfo = "not connected";
|
||||
_state = Error;
|
||||
return false;
|
||||
|
@ -48,14 +42,12 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
|||
|
||||
_aprs_is->getAPRSMessage();
|
||||
|
||||
if(!inputQueue.empty())
|
||||
{
|
||||
if (!inputQueue.empty()) {
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_aprs_is->sendMessage(msg);
|
||||
}
|
||||
|
||||
if(_beacon_timer.check())
|
||||
{
|
||||
if (_beacon_timer.check()) {
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintlnD(_beaconMsg->encode());
|
||||
_aprs_is->sendMessage(_beaconMsg);
|
||||
|
@ -68,14 +60,12 @@ bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AprsIsTask::connect(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
bool AprsIsTask::connect(std::shared_ptr<Configuration> config) {
|
||||
logPrintI("connecting to APRS-IS server: ");
|
||||
logPrintI(config->aprs_is.server);
|
||||
logPrintI(" on port: ");
|
||||
logPrintlnI(String(config->aprs_is.port));
|
||||
if(!_aprs_is->connect(config->aprs_is.server, config->aprs_is.port))
|
||||
{
|
||||
if (!_aprs_is->connect(config->aprs_is.server, config->aprs_is.port)) {
|
||||
logPrintlnE("Connection failed.");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef TASK_APRS_IS_H_
|
||||
#define TASK_APRS_IS_H_
|
||||
|
||||
#include <TaskManager.h>
|
||||
#include <APRS-IS.h>
|
||||
#include <APRSMessage.h>
|
||||
#include <TaskManager.h>
|
||||
#include <Timer.h>
|
||||
|
||||
class AprsIsTask : public Task
|
||||
{
|
||||
class AprsIsTask : public Task {
|
||||
public:
|
||||
AprsIsTask();
|
||||
virtual ~AprsIsTask();
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
#include <logger.h>
|
||||
#include <TimeLib.h>
|
||||
#include "project_configuration.h"
|
||||
#include <logger.h>
|
||||
|
||||
#include "TaskDisplay.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
DisplayTask::DisplayTask()
|
||||
: Task("DisplayTask", 0)
|
||||
{
|
||||
DisplayTask::DisplayTask() : Task("DisplayTask", 0) {
|
||||
}
|
||||
|
||||
DisplayTask::~DisplayTask()
|
||||
{
|
||||
DisplayTask::~DisplayTask() {
|
||||
}
|
||||
|
||||
bool DisplayTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool DisplayTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
Display::instance().setup(boardConfig);
|
||||
if(config->display.turn180)
|
||||
{
|
||||
if (config->display.turn180) {
|
||||
Display::instance().turn180();
|
||||
}
|
||||
std::shared_ptr<StatusFrame> statusFrame = std::shared_ptr<StatusFrame>(new StatusFrame(TaskManager::instance().getTasks()));
|
||||
|
@ -25,8 +21,7 @@ bool DisplayTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<B
|
|||
return true;
|
||||
}
|
||||
|
||||
bool DisplayTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
bool DisplayTask::loop(std::shared_ptr<Configuration> config) {
|
||||
Display::instance().update();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include <Display.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class DisplayTask : public Task
|
||||
{
|
||||
class DisplayTask : public Task {
|
||||
public:
|
||||
DisplayTask();
|
||||
virtual ~DisplayTask();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <WiFi.h>
|
||||
#include <ETH.h>
|
||||
#include <WiFi.h>
|
||||
#include <logger.h>
|
||||
#include "TaskEth.h"
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskEth.h"
|
||||
|
||||
volatile bool eth_connected = false;
|
||||
|
||||
static void WiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
static void WiFiEvent(WiFiEvent_t event) {
|
||||
switch (event) {
|
||||
case SYSTEM_EVENT_ETH_START:
|
||||
logPrintlnI("ETH Started");
|
||||
|
@ -42,26 +42,22 @@ static void WiFiEvent(WiFiEvent_t event)
|
|||
}
|
||||
}
|
||||
|
||||
EthTask::EthTask()
|
||||
: Task(TASK_ETH, TaskEth)
|
||||
{
|
||||
EthTask::EthTask() : Task(TASK_ETH, TaskEth) {
|
||||
}
|
||||
|
||||
EthTask::~EthTask()
|
||||
{
|
||||
EthTask::~EthTask() {
|
||||
}
|
||||
|
||||
bool EthTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool EthTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
|
||||
#define ETH_POWER_PIN -1
|
||||
#define ETH_TYPE ETH_PHY_LAN8720
|
||||
#define ETH_ADDR 0
|
||||
#define ETH_MDC_PIN 23
|
||||
#define ETH_MDIO_PIN 18
|
||||
#define ETH_NRST 5
|
||||
#define ETH_CLK ETH_CLOCK_GPIO17_OUT // TTGO PoE V1.0
|
||||
#define ETH_POWER_PIN -1
|
||||
#define ETH_TYPE ETH_PHY_LAN8720
|
||||
#define ETH_ADDR 0
|
||||
#define ETH_MDC_PIN 23
|
||||
#define ETH_MDIO_PIN 18
|
||||
#define ETH_NRST 5
|
||||
#define ETH_CLK ETH_CLOCK_GPIO17_OUT // TTGO PoE V1.0
|
||||
//#define ETH_CLK ETH_CLOCK_GPIO0_OUT // TTGO PoE V1.2
|
||||
|
||||
pinMode(ETH_NRST, OUTPUT);
|
||||
|
@ -74,14 +70,12 @@ bool EthTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
|||
digitalWrite(ETH_NRST, 1);
|
||||
|
||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK);
|
||||
while(!eth_connected)
|
||||
{
|
||||
while (!eth_connected) {
|
||||
sleep(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EthTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
bool EthTask::loop(std::shared_ptr<Configuration> config) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include <TaskManager.h>
|
||||
|
||||
class EthTask : public Task
|
||||
{
|
||||
class EthTask : public Task {
|
||||
public:
|
||||
EthTask();
|
||||
virtual ~EthTask();
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
#include <SPIFFS.h>
|
||||
#include <FTPFilesystem.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <logger.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskFTP.h"
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskFTP.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
FTPTask::FTPTask()
|
||||
: Task(TASK_FTP, TaskFtp), _beginCalled(false)
|
||||
{
|
||||
FTPTask::FTPTask() : Task(TASK_FTP, TaskFtp), _beginCalled(false) {
|
||||
}
|
||||
|
||||
FTPTask::~FTPTask()
|
||||
{
|
||||
FTPTask::~FTPTask() {
|
||||
}
|
||||
|
||||
bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_ftpServer = std::shared_ptr<FTPServer>(new FTPServer());
|
||||
for(Configuration::Ftp::User user : config->ftp.users)
|
||||
{
|
||||
for (Configuration::Ftp::User user : config->ftp.users) {
|
||||
logPrintD("Adding user to FTP Server: ");
|
||||
logPrintlnD(user.name);
|
||||
_ftpServer->addUser(user.name, user.password);
|
||||
|
@ -28,23 +24,19 @@ bool FTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
|||
return true;
|
||||
}
|
||||
|
||||
bool FTPTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
bool FTPTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_beginCalled) {
|
||||
_ftpServer->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
_ftpServer->handle();
|
||||
static bool configWasOpen = false;
|
||||
if(configWasOpen && _ftpServer->countConnections() == 0)
|
||||
{
|
||||
if (configWasOpen && _ftpServer->countConnections() == 0) {
|
||||
logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
||||
logPrintlnW("");
|
||||
ESP.restart();
|
||||
}
|
||||
if(_ftpServer->countConnections() > 0)
|
||||
{
|
||||
if (_ftpServer->countConnections() > 0) {
|
||||
configWasOpen = true;
|
||||
_stateInfo = "has connection";
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef TASK_FTP_H_
|
||||
#define TASK_FTP_H_
|
||||
|
||||
#include <TaskManager.h>
|
||||
#include <ESP-FTP-Server-Lib.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class FTPTask : public Task
|
||||
{
|
||||
class FTPTask : public Task {
|
||||
public:
|
||||
FTPTask();
|
||||
virtual ~FTPTask();
|
||||
|
|
|
@ -1,28 +1,25 @@
|
|||
#include <logger.h>
|
||||
#include <TimeLib.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskLora.h"
|
||||
#include "TaskAprsIs.h"
|
||||
#include <logger.h>
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskAprsIs.h"
|
||||
#include "TaskLora.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
LoraTask::LoraTask()
|
||||
: Task(TASK_LORA, TaskLora)
|
||||
{
|
||||
LoraTask::LoraTask() : Task(TASK_LORA, TaskLora) {
|
||||
}
|
||||
|
||||
LoraTask::~LoraTask()
|
||||
{
|
||||
LoraTask::~LoraTask() {
|
||||
}
|
||||
|
||||
bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_lora_aprs = std::shared_ptr<LoRa_APRS>(new LoRa_APRS(boardConfig));
|
||||
if(!_lora_aprs->begin(_lora_aprs->getRxFrequency()))
|
||||
{
|
||||
if (!_lora_aprs->begin(_lora_aprs->getRxFrequency())) {
|
||||
logPrintlnE("Starting LoRa failed!");
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
while(true);
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
_lora_aprs->setRxFrequency(config->lora.frequencyRx);
|
||||
_lora_aprs->setTxFrequency(config->lora.frequencyTx);
|
||||
|
@ -36,12 +33,10 @@ bool LoraTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
|||
return true;
|
||||
}
|
||||
|
||||
bool LoraTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(_lora_aprs->checkMessage())
|
||||
{
|
||||
bool LoraTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (_lora_aprs->checkMessage()) {
|
||||
std::shared_ptr<APRSMessage> msg = _lora_aprs->getMessage();
|
||||
//msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123");
|
||||
// msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123");
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintD("Received packet '");
|
||||
logPrintD(msg->toString());
|
||||
|
@ -54,8 +49,7 @@ bool LoraTask::loop(std::shared_ptr<Configuration> config)
|
|||
Display::instance().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString())));
|
||||
}
|
||||
|
||||
if(!inputQueue.empty())
|
||||
{
|
||||
if (!inputQueue.empty()) {
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_lora_aprs->sendMessage(msg);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#ifndef TASK_LORA_H_
|
||||
#define TASK_LORA_H_
|
||||
|
||||
#include <TaskManager.h>
|
||||
#include <BoardFinder.h>
|
||||
#include <LoRa_APRS.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class LoraTask : public Task
|
||||
{
|
||||
class LoraTask : public Task {
|
||||
public:
|
||||
LoraTask();
|
||||
virtual ~LoraTask();
|
||||
|
|
|
@ -1,33 +1,27 @@
|
|||
#include <logger.h>
|
||||
#include <TimeLib.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskNTP.h"
|
||||
#include <logger.h>
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskNTP.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
NTPTask::NTPTask()
|
||||
: Task(TASK_NTP, TaskNtp), _beginCalled(false)
|
||||
{
|
||||
NTPTask::NTPTask() : Task(TASK_NTP, TaskNtp), _beginCalled(false) {
|
||||
}
|
||||
|
||||
NTPTask::~NTPTask()
|
||||
{
|
||||
NTPTask::~NTPTask() {
|
||||
}
|
||||
|
||||
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool NTPTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NTPTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
bool NTPTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_beginCalled) {
|
||||
_ntpClient->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
if(_ntpClient->update())
|
||||
{
|
||||
if (_ntpClient->update()) {
|
||||
setTime(_ntpClient->getEpochTime());
|
||||
logPrintI("Current time: ");
|
||||
logPrintlnI(_ntpClient->getFormattedTime());
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef TASK_NTP_H_
|
||||
#define TASK_NTP_H_
|
||||
|
||||
#include <TaskManager.h>
|
||||
#include <NTPClient.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class NTPTask : public Task
|
||||
{
|
||||
class NTPTask : public Task {
|
||||
public:
|
||||
NTPTask();
|
||||
virtual ~NTPTask();
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
#include <logger.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskOTA.h"
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskOTA.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
OTATask::OTATask()
|
||||
: Task(TASK_OTA, TaskOta), _beginCalled(false)
|
||||
{
|
||||
OTATask::OTATask() : Task(TASK_OTA, TaskOta), _beginCalled(false) {
|
||||
}
|
||||
|
||||
OTATask::~OTATask()
|
||||
{
|
||||
OTATask::~OTATask() {
|
||||
}
|
||||
|
||||
bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_ota = std::shared_ptr<ArduinoOTAClass>(new ArduinoOTAClass());
|
||||
_ota->onStart([&]()
|
||||
{
|
||||
_ota->onStart([&]() {
|
||||
String type;
|
||||
if (_ota->getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
|
@ -24,37 +20,37 @@ bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Board
|
|||
type = "filesystem";
|
||||
logPrintlnI("Start updating " + type);
|
||||
})
|
||||
.onEnd([]()
|
||||
{
|
||||
.onEnd([]() {
|
||||
logPrintlnI("");
|
||||
logPrintlnI("OTA End");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
logPrintI("Progress: ");
|
||||
logPrintI(String(progress / (total / 100)));
|
||||
logPrintlnI("%");
|
||||
})
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
.onError([](ota_error_t error) {
|
||||
logPrintE("Error[");
|
||||
logPrintE(String(error));
|
||||
logPrintE("]: ");
|
||||
if (error == OTA_AUTH_ERROR) logPrintlnE("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR) logPrintlnE("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR) logPrintlnE("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR) logPrintlnE("Receive Failed");
|
||||
else if (error == OTA_END_ERROR) logPrintlnE("End Failed");
|
||||
if (error == OTA_AUTH_ERROR)
|
||||
logPrintlnE("Auth Failed");
|
||||
else if (error == OTA_BEGIN_ERROR)
|
||||
logPrintlnE("Begin Failed");
|
||||
else if (error == OTA_CONNECT_ERROR)
|
||||
logPrintlnE("Connect Failed");
|
||||
else if (error == OTA_RECEIVE_ERROR)
|
||||
logPrintlnE("Receive Failed");
|
||||
else if (error == OTA_END_ERROR)
|
||||
logPrintlnE("End Failed");
|
||||
});
|
||||
_ota->setHostname(config->callsign.c_str());
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OTATask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
bool OTATask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_beginCalled) {
|
||||
_ota->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#ifndef TASK_OTA_H_
|
||||
#define TASK_OTA_H_
|
||||
|
||||
#include <TaskManager.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class OTATask : public Task
|
||||
{
|
||||
class OTATask : public Task {
|
||||
public:
|
||||
OTATask();
|
||||
virtual ~OTATask();
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
#include <WiFi.h>
|
||||
#include <logger.h>
|
||||
#include "project_configuration.h"
|
||||
#include "TaskWifi.h"
|
||||
|
||||
#include "Task.h"
|
||||
#include "TaskWifi.h"
|
||||
#include "project_configuration.h"
|
||||
|
||||
WifiTask::WifiTask()
|
||||
: Task(TASK_WIFI, TaskWifi), _oldWifiStatus(WL_IDLE_STATUS)
|
||||
{
|
||||
WifiTask::WifiTask() : Task(TASK_WIFI, TaskWifi), _oldWifiStatus(WL_IDLE_STATUS) {
|
||||
}
|
||||
|
||||
WifiTask::~WifiTask()
|
||||
{
|
||||
WifiTask::~WifiTask() {
|
||||
}
|
||||
|
||||
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
//WiFi.onEvent(WiFiEvent);
|
||||
bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
// WiFi.onEvent(WiFiEvent);
|
||||
WiFi.setHostname(config->callsign.c_str());
|
||||
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());;
|
||||
for(Configuration::Wifi::AP ap : config->wifi.APs)
|
||||
{
|
||||
_wiFiMulti = std::shared_ptr<WiFiMulti>(new WiFiMulti());
|
||||
;
|
||||
for (Configuration::Wifi::AP ap : config->wifi.APs) {
|
||||
logPrintD("Looking for AP: ");
|
||||
logPrintlnD(ap.SSID);
|
||||
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
||||
|
@ -27,19 +24,15 @@ bool WifiTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<Boar
|
|||
return true;
|
||||
}
|
||||
|
||||
bool WifiTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
bool WifiTask::loop(std::shared_ptr<Configuration> config) {
|
||||
const uint8_t wifi_status = _wiFiMulti->run();
|
||||
if(wifi_status != WL_CONNECTED)
|
||||
{
|
||||
if (wifi_status != WL_CONNECTED) {
|
||||
logPrintlnE("WiFi not connected!");
|
||||
_oldWifiStatus = wifi_status;
|
||||
_stateInfo = "WiFi not connected";
|
||||
_state = Error;
|
||||
return false;
|
||||
}
|
||||
else if(wifi_status != _oldWifiStatus)
|
||||
{
|
||||
} else if (wifi_status != _oldWifiStatus) {
|
||||
logPrintD("IP address: ");
|
||||
logPrintlnD(WiFi.localIP().toString());
|
||||
_oldWifiStatus = wifi_status;
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
#include <TaskManager.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
class WifiTask : public Task
|
||||
{
|
||||
class WifiTask : public Task {
|
||||
public:
|
||||
WifiTask();
|
||||
virtual ~WifiTask();
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
#include <SPIFFS.h>
|
||||
|
||||
#include "project_configuration.h"
|
||||
#include "logger.h"
|
||||
#include <logger.h>
|
||||
|
||||
std::shared_ptr<Configuration> ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocument & data)
|
||||
{
|
||||
#include "project_configuration.h"
|
||||
|
||||
std::shared_ptr<Configuration> ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocument &data) {
|
||||
std::shared_ptr<Configuration> conf = std::shared_ptr<Configuration>(new Configuration);
|
||||
if(data.containsKey("callsign"))
|
||||
if (data.containsKey("callsign"))
|
||||
conf->callsign = data["callsign"].as<String>();
|
||||
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
for(JsonVariant v : aps)
|
||||
{
|
||||
for (JsonVariant v : aps) {
|
||||
Configuration::Wifi::AP ap;
|
||||
ap.SSID = v["SSID"].as<String>();
|
||||
ap.password = v["password"].as<String>();
|
||||
conf->wifi.APs.push_back(ap);
|
||||
}
|
||||
if(data.containsKey("beacon") && data["beacon"].containsKey("message"))
|
||||
if (data.containsKey("beacon") && data["beacon"].containsKey("message"))
|
||||
conf->beacon.message = data["beacon"]["message"].as<String>();
|
||||
conf->beacon.positionLatitude = data["beacon"]["position"]["latitude"] | 0.0;
|
||||
conf->beacon.positionLongitude = data["beacon"]["position"]["longitude"] | 0.0;
|
||||
conf->beacon.timeout = data["beacon"]["timeout"] | 15;
|
||||
if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode"))
|
||||
if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("passcode"))
|
||||
conf->aprs_is.passcode = data["aprs_is"]["passcode"].as<String>();
|
||||
if(data.containsKey("aprs_is") && data["aprs_is"].containsKey("server"))
|
||||
if (data.containsKey("aprs_is") && data["aprs_is"].containsKey("server"))
|
||||
conf->aprs_is.server = data["aprs_is"]["server"].as<String>();
|
||||
conf->aprs_is.port = data["aprs_is"]["port"] | 14580;
|
||||
|
||||
|
@ -41,35 +40,31 @@ std::shared_ptr<Configuration> ProjectConfigurationManagement::readProjectConfig
|
|||
|
||||
conf->ftp.active = data["ftp"]["active"] | false;
|
||||
JsonArray users = data["ftp"]["user"].as<JsonArray>();
|
||||
for(JsonVariant u : users)
|
||||
{
|
||||
for (JsonVariant u : users) {
|
||||
Configuration::Ftp::User us;
|
||||
us.name = u["name"].as<String>();
|
||||
us.password = u["password"].as<String>();
|
||||
conf->ftp.users.push_back(us);
|
||||
}
|
||||
if(conf->ftp.users.empty())
|
||||
{
|
||||
if (conf->ftp.users.empty()) {
|
||||
Configuration::Ftp::User us;
|
||||
us.name = "ftp";
|
||||
us.password = "ftp";
|
||||
conf->ftp.users.push_back(us);
|
||||
}
|
||||
if(data.containsKey("ntp_server"))
|
||||
if (data.containsKey("ntp_server"))
|
||||
conf->ntpServer = data["ntp_server"].as<String>();
|
||||
|
||||
if(data.containsKey("board"))
|
||||
if (data.containsKey("board"))
|
||||
conf->board = data["board"].as<String>();
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument & data)
|
||||
{
|
||||
void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument &data) {
|
||||
data["callsign"] = conf->callsign;
|
||||
JsonArray aps = data["wifi"].createNestedArray("AP");
|
||||
for(Configuration::Wifi::AP ap : conf->wifi.APs)
|
||||
{
|
||||
for (Configuration::Wifi::AP ap : conf->wifi.APs) {
|
||||
JsonObject v = aps.createNestedObject();
|
||||
v["SSID"] = ap.SSID;
|
||||
v["password"] = ap.password;
|
||||
|
@ -93,8 +88,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptr<C
|
|||
data["display"]["turn180"] = conf->display.turn180;
|
||||
data["ftp"]["active"] = conf->ftp.active;
|
||||
JsonArray users = data["ftp"].createNestedArray("user");
|
||||
for(Configuration::Ftp::User u : conf->ftp.users)
|
||||
{
|
||||
for (Configuration::Ftp::User u : conf->ftp.users) {
|
||||
JsonObject v = users.createNestedObject();
|
||||
v["name"] = u.name;
|
||||
v["password"] = u.password;
|
||||
|
@ -104,16 +98,14 @@ void ProjectConfigurationManagement::writeProjectConfiguration(std::shared_ptr<C
|
|||
data["board"] = conf->board;
|
||||
}
|
||||
|
||||
std::shared_ptr<Configuration> load_config(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
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")
|
||||
{
|
||||
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)
|
||||
{}
|
||||
// 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)
|
||||
|
|
|
@ -1,31 +1,29 @@
|
|||
#ifndef PROJECT_CONFIGURATION_H_
|
||||
#define PROJECT_CONFIGURATION_H_
|
||||
|
||||
#include "configuration.h"
|
||||
#include "BoardFinder.h"
|
||||
#include <BoardFinder.h>
|
||||
#include <configuration.h>
|
||||
|
||||
class Configuration
|
||||
{
|
||||
class Configuration {
|
||||
public:
|
||||
class Wifi
|
||||
{
|
||||
class Wifi {
|
||||
public:
|
||||
class AP
|
||||
{
|
||||
class AP {
|
||||
public:
|
||||
String SSID;
|
||||
String password;
|
||||
};
|
||||
|
||||
Wifi() {}
|
||||
Wifi() {
|
||||
}
|
||||
|
||||
std::list<AP> APs;
|
||||
};
|
||||
|
||||
class Beacon
|
||||
{
|
||||
class Beacon {
|
||||
public:
|
||||
Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), timeout(15) {}
|
||||
Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), timeout(15) {
|
||||
}
|
||||
|
||||
String message;
|
||||
double positionLatitude;
|
||||
|
@ -33,20 +31,20 @@ public:
|
|||
int timeout;
|
||||
};
|
||||
|
||||
class APRS_IS
|
||||
{
|
||||
class APRS_IS {
|
||||
public:
|
||||
APRS_IS() : server("euro.aprs2.net"), port(14580) {}
|
||||
APRS_IS() : server("euro.aprs2.net"), port(14580) {
|
||||
}
|
||||
|
||||
String passcode;
|
||||
String server;
|
||||
int port;
|
||||
};
|
||||
|
||||
class LoRa
|
||||
{
|
||||
class LoRa {
|
||||
public:
|
||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
|
||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {
|
||||
}
|
||||
|
||||
long frequencyRx;
|
||||
long frequencyTx;
|
||||
|
@ -56,10 +54,10 @@ public:
|
|||
int codingRate4;
|
||||
};
|
||||
|
||||
class Display
|
||||
{
|
||||
class Display {
|
||||
public:
|
||||
Display() : alwaysOn(true), timeout(10), overwritePin(0), turn180(true) {}
|
||||
Display() : alwaysOn(true), timeout(10), overwritePin(0), turn180(true) {
|
||||
}
|
||||
|
||||
bool alwaysOn;
|
||||
int timeout;
|
||||
|
@ -67,23 +65,22 @@ public:
|
|||
bool turn180;
|
||||
};
|
||||
|
||||
class Ftp
|
||||
{
|
||||
class Ftp {
|
||||
public:
|
||||
class User
|
||||
{
|
||||
class User {
|
||||
public:
|
||||
String name;
|
||||
String password;
|
||||
};
|
||||
|
||||
Ftp() : active(false) {}
|
||||
Ftp() : active(false) {
|
||||
}
|
||||
|
||||
bool active;
|
||||
std::list<User> users;
|
||||
};
|
||||
|
||||
Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org") {};
|
||||
Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){};
|
||||
|
||||
String callsign;
|
||||
Wifi wifi;
|
||||
|
@ -96,15 +93,16 @@ public:
|
|||
String ntpServer;
|
||||
};
|
||||
|
||||
class ProjectConfigurationManagement : public ConfigurationManagement
|
||||
{
|
||||
class ProjectConfigurationManagement : public ConfigurationManagement {
|
||||
public:
|
||||
explicit ProjectConfigurationManagement() : ConfigurationManagement("/is-cfg.json") {}
|
||||
virtual ~ProjectConfigurationManagement() {}
|
||||
explicit ProjectConfigurationManagement() : ConfigurationManagement("/is-cfg.json") {
|
||||
}
|
||||
virtual ~ProjectConfigurationManagement() {
|
||||
}
|
||||
|
||||
private:
|
||||
virtual std::shared_ptr<Configuration> readProjectConfiguration(DynamicJsonDocument & data) override;
|
||||
virtual void writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument & data) override;
|
||||
virtual std::shared_ptr<Configuration> readProjectConfiguration(DynamicJsonDocument &data) override;
|
||||
virtual void writeProjectConfiguration(std::shared_ptr<Configuration> conf, DynamicJsonDocument &data) override;
|
||||
};
|
||||
|
||||
std::shared_ptr<Configuration> load_config(std::shared_ptr<BoardConfig> boardConfig);
|
||||
|
|
Ładowanie…
Reference in New Issue