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,167 +1,135 @@
|
|||
#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()
|
||||
{
|
||||
logPrintlnI("looking for a board config.");
|
||||
logPrintlnI("searching for OLED...");
|
||||
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)
|
||||
{
|
||||
PowerManagement powerManagement;
|
||||
TwoWire wire(0);
|
||||
wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(wire);
|
||||
powerManagement.activateOLED();
|
||||
}
|
||||
else if(boardconf->needCheckPowerChip)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(checkOledConfig(boardconf))
|
||||
{
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
continue;
|
||||
}
|
||||
if (checkOledConfig(boardconf)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
}
|
||||
}
|
||||
|
||||
logPrintlnW("could not find OLED, will search for the modem now...");
|
||||
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)
|
||||
{
|
||||
PowerManagement powerManagement;
|
||||
TwoWire wire(0);
|
||||
wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(wire);
|
||||
powerManagement.activateLoRa();
|
||||
}
|
||||
if(checkModemConfig(boardconf))
|
||||
{
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
return boardconf;
|
||||
}
|
||||
}
|
||||
|
||||
logPrintlnW("could not find a board config!");
|
||||
logPrintlnW("could not find a board config!");
|
||||
|
||||
return 0;
|
||||
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)
|
||||
{
|
||||
return conf->Name == name;
|
||||
});
|
||||
if(elem == _boardConfigs.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
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()) {
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
if(boardConfig->OledReset > 0)
|
||||
{
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(boardConfig->OledReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
TwoWire wire(0);
|
||||
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
|
||||
{
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
wire.beginTransmission(boardConfig->OledAddr);
|
||||
if(!wire.endTransmission())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
bool BoardFinder::checkOledConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
if (boardConfig->OledReset > 0) {
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(boardConfig->OledReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
TwoWire wire(0);
|
||||
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
wire.beginTransmission(boardConfig->OledAddr);
|
||||
if (!wire.endTransmission()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
pinMode(boardConfig->LoraReset, OUTPUT);
|
||||
digitalWrite(boardConfig->LoraReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->LoraReset, HIGH);
|
||||
delay(10);
|
||||
bool BoardFinder::checkModemConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
pinMode(boardConfig->LoraReset, OUTPUT);
|
||||
digitalWrite(boardConfig->LoraReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->LoraReset, HIGH);
|
||||
delay(10);
|
||||
|
||||
pinMode(boardConfig->LoraCS, OUTPUT);
|
||||
digitalWrite(boardConfig->LoraCS, HIGH);
|
||||
pinMode(boardConfig->LoraCS, OUTPUT);
|
||||
digitalWrite(boardConfig->LoraCS, HIGH);
|
||||
|
||||
SPIClass spi;
|
||||
spi.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
|
||||
SPIClass spi;
|
||||
spi.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
|
||||
|
||||
digitalWrite(boardConfig->LoraCS, LOW);
|
||||
digitalWrite(boardConfig->LoraCS, LOW);
|
||||
|
||||
spi.beginTransaction(SPISettings(8E6, MSBFIRST, SPI_MODE0));
|
||||
spi.transfer(0x42);
|
||||
uint8_t response = spi.transfer(0x00);
|
||||
spi.endTransaction();
|
||||
spi.beginTransaction(SPISettings(8E6, MSBFIRST, SPI_MODE0));
|
||||
spi.transfer(0x42);
|
||||
uint8_t response = spi.transfer(0x00);
|
||||
spi.endTransaction();
|
||||
|
||||
digitalWrite(boardConfig->LoraCS, HIGH);
|
||||
digitalWrite(boardConfig->LoraCS, HIGH);
|
||||
|
||||
if(response == 0x12)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (response == 0x12) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig)
|
||||
{
|
||||
TwoWire wire(0);
|
||||
if(!wire.begin(boardConfig->OledSda, boardConfig->OledScl))
|
||||
{
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
wire.beginTransmission(0x34);
|
||||
wire.write(0x03);
|
||||
wire.endTransmission();
|
||||
|
||||
wire.requestFrom(0x34, 1);
|
||||
int response = wire.read();
|
||||
wire.endTransmission();
|
||||
bool BoardFinder::checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
TwoWire wire(0);
|
||||
if (!wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||
logPrintlnW("issue with wire");
|
||||
return false;
|
||||
}
|
||||
wire.beginTransmission(0x34);
|
||||
wire.write(0x03);
|
||||
wire.endTransmission();
|
||||
|
||||
logPrintlnD(String(response));
|
||||
if(response == 0x03)
|
||||
{
|
||||
logPrintlnD("power chip found!");
|
||||
return true;
|
||||
}
|
||||
logPrintlnD("power chip NOT found");
|
||||
return false;
|
||||
wire.requestFrom(0x34, 1);
|
||||
int response = wire.read();
|
||||
wire.endTransmission();
|
||||
|
||||
logPrintlnD(String(response));
|
||||
if (response == 0x03) {
|
||||
logPrintlnD("power chip found!");
|
||||
return true;
|
||||
}
|
||||
logPrintlnD("power chip NOT found");
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -5,64 +5,58 @@
|
|||
#include <memory>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
enum BoardType
|
||||
{
|
||||
eHELTEC_WIFI_LORA_32_V1,
|
||||
eHELTEC_WIFI_LORA_32_V2,
|
||||
eTTGO_LORA32_V1,
|
||||
eTTGO_LORA32_V2,
|
||||
eTTGO_T_Beam_V0_7,
|
||||
eTTGO_T_Beam_V1_0,
|
||||
eETH_BOARD,
|
||||
eTRACKERD
|
||||
eHELTEC_WIFI_LORA_32_V1,
|
||||
eHELTEC_WIFI_LORA_32_V2,
|
||||
eTTGO_LORA32_V1,
|
||||
eTTGO_LORA32_V2,
|
||||
eTTGO_T_Beam_V0_7,
|
||||
eTTGO_T_Beam_V1_0,
|
||||
eETH_BOARD,
|
||||
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;
|
||||
String Name;
|
||||
BoardType Type;
|
||||
|
||||
uint8_t OledSda;
|
||||
uint8_t OledScl;
|
||||
uint8_t OledAddr;
|
||||
uint8_t OledReset;
|
||||
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;
|
||||
uint8_t LoraSck;
|
||||
uint8_t LoraMiso;
|
||||
uint8_t LoraMosi;
|
||||
uint8_t LoraCS;
|
||||
uint8_t LoraReset;
|
||||
uint8_t LoraIRQ;
|
||||
|
||||
bool needCheckPowerChip;
|
||||
bool powerCheckStatus;
|
||||
bool needCheckPowerChip;
|
||||
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();
|
||||
std::shared_ptr<BoardConfig> searchBoardConfig();
|
||||
|
||||
std::shared_ptr<BoardConfig> getBoardConfig(String name);
|
||||
std::shared_ptr<BoardConfig> getBoardConfig(String name);
|
||||
|
||||
private:
|
||||
std::list<std::shared_ptr<BoardConfig>> _boardConfigs;
|
||||
std::list<std::shared_ptr<BoardConfig>> _boardConfigs;
|
||||
|
||||
bool checkOledConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool checkModemConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool checkOledConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool checkModemConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool checkPowerConfig(std::shared_ptr<BoardConfig> boardConfig);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,65 +1,55 @@
|
|||
#include "configuration.h"
|
||||
#include <SPIFFS.h>
|
||||
#include <logger.h>
|
||||
#include "configuration.h"
|
||||
|
||||
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())
|
||||
{
|
||||
logPrintlnE("Formating SPIFFS was not okay!");
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
logPrintlnE("Formating SPIFFS was not okay!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationManagement::~ConfigurationManagement()
|
||||
{
|
||||
ConfigurationManagement::~ConfigurationManagement() {
|
||||
}
|
||||
|
||||
std::shared_ptr<Configuration> ConfigurationManagement::readConfiguration()
|
||||
{
|
||||
File file = SPIFFS.open(mFilePath);
|
||||
if(!file)
|
||||
{
|
||||
logPrintlnE("Failed to open file for reading...");
|
||||
return 0;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
DeserializationError error = deserializeJson(data, file);
|
||||
if(error)
|
||||
{
|
||||
logPrintlnW("Failed to read file, using default configuration.");
|
||||
}
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
file.close();
|
||||
std::shared_ptr<Configuration> ConfigurationManagement::readConfiguration() {
|
||||
File file = SPIFFS.open(mFilePath);
|
||||
if (!file) {
|
||||
logPrintlnE("Failed to open file for reading...");
|
||||
return 0;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
DeserializationError error = deserializeJson(data, file);
|
||||
if (error) {
|
||||
logPrintlnW("Failed to read file, using default configuration.");
|
||||
}
|
||||
// serializeJson(data, Serial);
|
||||
// Serial.println();
|
||||
file.close();
|
||||
|
||||
std::shared_ptr<Configuration> conf = readProjectConfiguration(data);
|
||||
std::shared_ptr<Configuration> conf = readProjectConfiguration(data);
|
||||
|
||||
// update config in memory to get the new fields:
|
||||
writeConfiguration(conf);
|
||||
// update config in memory to get the new fields:
|
||||
writeConfiguration(conf);
|
||||
|
||||
return conf;
|
||||
return conf;
|
||||
}
|
||||
|
||||
void ConfigurationManagement::writeConfiguration(std::shared_ptr<Configuration> conf)
|
||||
{
|
||||
File file = SPIFFS.open(mFilePath, "w");
|
||||
if(!file)
|
||||
{
|
||||
logPrintlnE("Failed to open file for writing...");
|
||||
return;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
void ConfigurationManagement::writeConfiguration(std::shared_ptr<Configuration> conf) {
|
||||
File file = SPIFFS.open(mFilePath, "w");
|
||||
if (!file) {
|
||||
logPrintlnE("Failed to open file for writing...");
|
||||
return;
|
||||
}
|
||||
DynamicJsonDocument data(2048);
|
||||
|
||||
writeProjectConfiguration(conf, data);
|
||||
writeProjectConfiguration(conf, data);
|
||||
|
||||
serializeJson(data, file);
|
||||
//serializeJson(data, Serial);
|
||||
//Serial.println();
|
||||
file.close();
|
||||
serializeJson(data, file);
|
||||
// serializeJson(data, Serial);
|
||||
// Serial.println();
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
class Configuration;
|
||||
|
||||
class ConfigurationManagement
|
||||
{
|
||||
class ConfigurationManagement {
|
||||
public:
|
||||
explicit ConfigurationManagement(String FilePath);
|
||||
virtual ~ConfigurationManagement();
|
||||
explicit ConfigurationManagement(String FilePath);
|
||||
virtual ~ConfigurationManagement();
|
||||
|
||||
std::shared_ptr<Configuration> readConfiguration();
|
||||
void writeConfiguration(std::shared_ptr<Configuration> conf);
|
||||
std::shared_ptr<Configuration> readConfiguration();
|
||||
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;
|
||||
const String mFilePath;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,424 +1,353 @@
|
|||
#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)
|
||||
{
|
||||
allocateBuffer();
|
||||
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)
|
||||
{
|
||||
allocateBuffer();
|
||||
Bitmap::Bitmap(OLEDDisplay *display) : _width(display->getWidth()), _height(display->getHeight()), _buffer(0) {
|
||||
allocateBuffer();
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
Bitmap::~Bitmap()
|
||||
{
|
||||
if(_buffer != 0)
|
||||
{
|
||||
delete _buffer;
|
||||
}
|
||||
Bitmap::~Bitmap() {
|
||||
if (_buffer != 0) {
|
||||
delete _buffer;
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
uint Bitmap::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
uint Bitmap::getWidth() const {
|
||||
return _width;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
uint Bitmap::getHeight() const
|
||||
{
|
||||
return _height;
|
||||
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)
|
||||
{
|
||||
_buffer[x + (y / 8) * _width] |= (1 << (y % 8));
|
||||
}
|
||||
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)
|
||||
{
|
||||
_buffer[x + (y / 8) * _width] &= ~(1 << (y % 8));
|
||||
}
|
||||
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)
|
||||
{
|
||||
return _buffer[x + (y / 8) * _width] & (1 << (y % 8));
|
||||
}
|
||||
return false;
|
||||
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()
|
||||
{
|
||||
memset(_buffer, 0, _width * _height / 8);
|
||||
void Bitmap::clear() {
|
||||
memset(_buffer, 0, _width * _height / 8);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
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;
|
||||
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)
|
||||
{
|
||||
setPixel(x0, y0);
|
||||
if(x0 == x1 && y0 == y1)
|
||||
break;
|
||||
while (true) {
|
||||
setPixel(x0, y0);
|
||||
if (x0 == x1 && y0 == y1)
|
||||
break;
|
||||
|
||||
int e2 = err;
|
||||
if(e2 > -dx)
|
||||
{
|
||||
err -= dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if(e2 < dy)
|
||||
{
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
int e2 = err;
|
||||
if (e2 > -dx) {
|
||||
err -= dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if (e2 < dy) {
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawHorizontalLine(int x, int y, int length)
|
||||
{
|
||||
if(y < 0 || y >= _height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void Bitmap::drawHorizontalLine(int x, int y, int length) {
|
||||
if (y < 0 || y >= _height) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
setPixel(x + i, y);
|
||||
}
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void Bitmap::drawVerticalLine(int x, int y, int length) {
|
||||
if (x < 0 || x >= _width) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(int i = 0; i < length; i++)
|
||||
{
|
||||
setPixel(x, y + 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)
|
||||
{
|
||||
drawHorizontalLine(x, y, width);
|
||||
drawVerticalLine(x, y, height);
|
||||
drawVerticalLine(x + width - 1, y, height);
|
||||
drawHorizontalLine(x, y + height - 1, width);
|
||||
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);
|
||||
drawHorizontalLine(x, y + height - 1, width);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::fillRect(int x, int y, int width, int height)
|
||||
{
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
drawVerticalLine(x + i, y, height);
|
||||
}
|
||||
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)
|
||||
{
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
void Bitmap::drawCircle(int x0, int y0, int radius) {
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
|
||||
do
|
||||
{
|
||||
if (dp < 0)
|
||||
{
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
do {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
setPixel(x0 + x, y0 + y); //For the 8 octants
|
||||
setPixel(x0 - x, y0 + y);
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
setPixel(x0 - y, y0 - x);
|
||||
}
|
||||
while (x < y);
|
||||
setPixel(x0 + x, y0 + y); // For the 8 octants
|
||||
setPixel(x0 - x, y0 + y);
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
setPixel(x0 - y, y0 - x);
|
||||
} while (x < y);
|
||||
|
||||
setPixel(x0 + radius, y0);
|
||||
setPixel(x0, y0 + radius);
|
||||
setPixel(x0 - radius, y0);
|
||||
setPixel(x0, y0 - radius);
|
||||
setPixel(x0 + radius, y0);
|
||||
setPixel(x0, y0 + radius);
|
||||
setPixel(x0 - radius, y0);
|
||||
setPixel(x0, y0 - radius);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::fillCircle(int x0, int y0, int radius)
|
||||
{
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
void Bitmap::fillCircle(int x0, int y0, int radius) {
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
|
||||
do
|
||||
{
|
||||
if (dp < 0)
|
||||
{
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
do {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
drawHorizontalLine(x0 - x, y0 - y, 2 * x);
|
||||
drawHorizontalLine(x0 - x, y0 + y, 2 * x);
|
||||
drawHorizontalLine(x0 - y, y0 - x, 2 * y);
|
||||
drawHorizontalLine(x0 - y, y0 + x, 2 * y);
|
||||
}
|
||||
while (x < y);
|
||||
|
||||
drawHorizontalLine(x0 - radius, y0, 2 * radius);
|
||||
drawHorizontalLine(x0 - x, y0 - y, 2 * x);
|
||||
drawHorizontalLine(x0 - x, y0 + y, 2 * x);
|
||||
drawHorizontalLine(x0 - y, y0 - x, 2 * y);
|
||||
drawHorizontalLine(x0 - y, y0 + x, 2 * y);
|
||||
} while (x < y);
|
||||
|
||||
drawHorizontalLine(x0 - radius, y0, 2 * radius);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawCircleQuads(int x0, int y0, int radius, int quads)
|
||||
{
|
||||
int x = 0;
|
||||
int y = radius;
|
||||
int dp = 1 - radius;
|
||||
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)
|
||||
{
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
while (x < y) {
|
||||
if (dp < 0) {
|
||||
dp = dp + (x++) * 2 + 3;
|
||||
} else {
|
||||
dp = dp + (x++) * 2 - (y--) * 2 + 5;
|
||||
}
|
||||
|
||||
if (quads & 0x1)
|
||||
{
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
}
|
||||
if (quads & 0x2)
|
||||
{
|
||||
setPixel(x0 - y, y0 - x);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
}
|
||||
if (quads & 0x4)
|
||||
{
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 - x, y0 + y);
|
||||
}
|
||||
if (quads & 0x8)
|
||||
{
|
||||
setPixel(x0 + x, y0 + y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
}
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x8)
|
||||
{
|
||||
setPixel(x0 + radius, y0);
|
||||
}
|
||||
if (quads & 0x4 && quads & 0x8)
|
||||
{
|
||||
setPixel(x0, y0 + radius);
|
||||
}
|
||||
if (quads & 0x2 && quads & 0x4)
|
||||
{
|
||||
setPixel(x0 - radius, y0);
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x2)
|
||||
{
|
||||
setPixel(x0, y0 - radius);
|
||||
}
|
||||
if (quads & 0x1) {
|
||||
setPixel(x0 + x, y0 - y);
|
||||
setPixel(x0 + y, y0 - x);
|
||||
}
|
||||
if (quads & 0x2) {
|
||||
setPixel(x0 - y, y0 - x);
|
||||
setPixel(x0 - x, y0 - y);
|
||||
}
|
||||
if (quads & 0x4) {
|
||||
setPixel(x0 - y, y0 + x);
|
||||
setPixel(x0 - x, y0 + y);
|
||||
}
|
||||
if (quads & 0x8) {
|
||||
setPixel(x0 + x, y0 + y);
|
||||
setPixel(x0 + y, y0 + x);
|
||||
}
|
||||
}
|
||||
if (quads & 0x1 && quads & 0x8) {
|
||||
setPixel(x0 + radius, y0);
|
||||
}
|
||||
if (quads & 0x4 && quads & 0x8) {
|
||||
setPixel(x0, y0 + radius);
|
||||
}
|
||||
if (quads & 0x2 && quads & 0x4) {
|
||||
setPixel(x0 - radius, y0);
|
||||
}
|
||||
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)
|
||||
{
|
||||
int radius = height / 2;
|
||||
int xRadius = x + radius;
|
||||
int yRadius = y + radius;
|
||||
int doubleRadius = 2 * radius;
|
||||
int innerRadius = radius - 2;
|
||||
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;
|
||||
int doubleRadius = 2 * radius;
|
||||
int innerRadius = radius - 2;
|
||||
|
||||
drawCircleQuads(xRadius, yRadius, radius, 0b00000110);
|
||||
drawHorizontalLine(xRadius, y, width - doubleRadius + 1);
|
||||
drawHorizontalLine(xRadius, y + height, width - doubleRadius + 1);
|
||||
drawCircleQuads(x + width - radius, yRadius, radius, 0b00001001);
|
||||
drawCircleQuads(xRadius, yRadius, radius, 0b00000110);
|
||||
drawHorizontalLine(xRadius, y, width - doubleRadius + 1);
|
||||
drawHorizontalLine(xRadius, y + height, width - doubleRadius + 1);
|
||||
drawCircleQuads(x + width - radius, yRadius, radius, 0b00001001);
|
||||
|
||||
uint16_t maxProgressWidth = (width - doubleRadius + 1) * progress / 100;
|
||||
uint16_t maxProgressWidth = (width - doubleRadius + 1) * progress / 100;
|
||||
|
||||
fillCircle(xRadius, yRadius, innerRadius);
|
||||
fillRect(xRadius + 1, y + 2, maxProgressWidth, height - 3);
|
||||
fillCircle(xRadius + maxProgressWidth, yRadius, innerRadius);
|
||||
fillCircle(xRadius, yRadius, innerRadius);
|
||||
fillRect(xRadius + 1, y + 2, maxProgressWidth, height - 3);
|
||||
fillCircle(xRadius + maxProgressWidth, yRadius, innerRadius);
|
||||
}
|
||||
|
||||
// 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 == ' ')
|
||||
{
|
||||
return x + font->widthInPixel * 4 / 10;
|
||||
}
|
||||
if (c == ' ') {
|
||||
return x + font->widthInPixel * 4 / 10;
|
||||
}
|
||||
|
||||
unsigned char cu = (unsigned char)c;
|
||||
if(cu < font->firstChar || cu > font->lastChar)
|
||||
{
|
||||
cu = '?';
|
||||
}
|
||||
unsigned char cu = (unsigned char)c;
|
||||
if (cu < font->firstChar || cu > font->lastChar) {
|
||||
cu = '?';
|
||||
}
|
||||
|
||||
int firstPixelBitPos = 0;
|
||||
for(int i = 0; i < (cu - font->firstChar); i++)
|
||||
{
|
||||
firstPixelBitPos = firstPixelBitPos + font->pData[i];
|
||||
}
|
||||
firstPixelBitPos = firstPixelBitPos * font->heightInPixel;
|
||||
int firstPixelBitPos = 0;
|
||||
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]);
|
||||
const int top = y;
|
||||
const int widthInPixel = font->pData[cu - font->firstChar];
|
||||
for(int i = 0; i < widthInPixel * font->heightInPixel; i++ )
|
||||
{
|
||||
int bytePos = firstPixelBitPos / 8;
|
||||
int bitPos = firstPixelBitPos % 8;
|
||||
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++) {
|
||||
int bytePos = firstPixelBitPos / 8;
|
||||
int bitPos = firstPixelBitPos % 8;
|
||||
|
||||
if(pDataStart[bytePos] & ( 1 << bitPos))
|
||||
{
|
||||
setPixel(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
clearPixel(x, y);
|
||||
}
|
||||
if (pDataStart[bytePos] & (1 << bitPos)) {
|
||||
setPixel(x, y);
|
||||
} else {
|
||||
clearPixel(x, y);
|
||||
}
|
||||
|
||||
firstPixelBitPos++;
|
||||
y++;
|
||||
if(y == top + font->heightInPixel)
|
||||
{
|
||||
y = top;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
firstPixelBitPos++;
|
||||
y++;
|
||||
if (y == top + font->heightInPixel) {
|
||||
y = top;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
return x + FONT_CHAR_SPACING;
|
||||
return x + FONT_CHAR_SPACING;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
int Bitmap::drawString(int x, int y, String text)
|
||||
{
|
||||
int next_x = x;
|
||||
for(int i = 0; i < text.length(); i++)
|
||||
{
|
||||
next_x = drawChar(next_x, y, text[i]);
|
||||
}
|
||||
return next_x;
|
||||
int Bitmap::drawString(int x, int y, String text) {
|
||||
int next_x = x;
|
||||
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, ... )
|
||||
{
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
va_end(myargs);
|
||||
drawString(x, y, buffer);
|
||||
void Bitmap::drawStringf(int x, int y, char *buffer, String format, ...) {
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
va_end(myargs);
|
||||
drawString(x, y, buffer);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
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)
|
||||
{
|
||||
next_x = 0;
|
||||
y += font->heightInPixel;
|
||||
}
|
||||
next_x = drawChar(next_x, y, text[i]);
|
||||
}
|
||||
return next_x;
|
||||
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) {
|
||||
next_x = 0;
|
||||
y += font->heightInPixel;
|
||||
}
|
||||
next_x = drawChar(next_x, y, text[i]);
|
||||
}
|
||||
return next_x;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::drawStringLFf(int x, int y, char * buffer, String format, ... )
|
||||
{
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
va_end(myargs);
|
||||
drawStringLF(x, y, buffer);
|
||||
void Bitmap::drawStringLFf(int x, int y, char *buffer, String format, ...) {
|
||||
va_list myargs;
|
||||
va_start(myargs, format);
|
||||
vsprintf(buffer, format.c_str(), myargs);
|
||||
va_end(myargs);
|
||||
drawStringLF(x, y, buffer);
|
||||
}
|
||||
|
||||
/*void Bitmap::drawBitmap(int x, int y, const Bitmap & bitmap)
|
||||
{
|
||||
if(_width < x + bitmap.getWidth() || _height < y + bitmap.getHeight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(_width < x + bitmap.getWidth() || _height < y + bitmap.getHeight())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(int _x = 0; _x < bitmap.getWidth(); _x++)
|
||||
{
|
||||
for(int _y = 0; _y < bitmap.getHeight(); _y++)
|
||||
{
|
||||
if(bitmap.getPixel(_x, _y))
|
||||
{
|
||||
// _buffer[x + (y / 8) * _width] |= (1 << (y % 8));
|
||||
// return _buffer[x + (y / 8) * _width] & (1 << (y % 8));
|
||||
Serial.print(_x);
|
||||
Serial.print(" ");
|
||||
Serial.println(_y);
|
||||
setPixel(x + _x, y + _y);
|
||||
}
|
||||
else
|
||||
{
|
||||
clearPixel(x + _x, y + _y);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int _x = 0; _x < bitmap.getWidth(); _x++)
|
||||
{
|
||||
for(int _y = 0; _y < bitmap.getHeight(); _y++)
|
||||
{
|
||||
if(bitmap.getPixel(_x, _y))
|
||||
{
|
||||
// _buffer[x + (y / 8) * _width] |= (1 << (y % 8));
|
||||
// return _buffer[x + (y / 8) * _width] & (1 << (y % 8));
|
||||
Serial.print(_x);
|
||||
Serial.print(" ");
|
||||
Serial.println(_y);
|
||||
setPixel(x + _x, y + _y);
|
||||
}
|
||||
else
|
||||
{
|
||||
clearPixel(x + _x, y + _y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void Bitmap::allocateBuffer()
|
||||
{
|
||||
_buffer = new uint8_t[_width * _height / 8];
|
||||
clear();
|
||||
void Bitmap::allocateBuffer() {
|
||||
_buffer = new uint8_t[_width * _height / 8];
|
||||
clear();
|
||||
}
|
||||
|
|
|
@ -6,51 +6,50 @@
|
|||
|
||||
class OLEDDisplay;
|
||||
|
||||
class Bitmap
|
||||
{
|
||||
class Bitmap {
|
||||
public:
|
||||
explicit Bitmap(uint width, uint height);
|
||||
explicit Bitmap(OLEDDisplay * display);
|
||||
virtual ~Bitmap();
|
||||
explicit Bitmap(uint width, uint height);
|
||||
explicit Bitmap(OLEDDisplay *display);
|
||||
virtual ~Bitmap();
|
||||
|
||||
uint getWidth() const;
|
||||
uint getHeight() const;
|
||||
uint getWidth() const;
|
||||
uint getHeight() const;
|
||||
|
||||
void setPixel(int x, int y);
|
||||
void clearPixel(int x, int y);
|
||||
bool getPixel(int x, int y) const;
|
||||
void clear();
|
||||
void setPixel(int x, int y);
|
||||
void clearPixel(int x, int y);
|
||||
bool getPixel(int x, int y) const;
|
||||
void clear();
|
||||
|
||||
void drawLine(int x0, int y0, int x1, int y1);
|
||||
void drawHorizontalLine(int x, int y, int length);
|
||||
void drawVerticalLine(int x, int y, int length);
|
||||
void drawLine(int x0, int y0, int x1, int y1);
|
||||
void drawHorizontalLine(int x, int y, int length);
|
||||
void drawVerticalLine(int x, int y, int length);
|
||||
|
||||
void drawRect(int x, int y, int width, int height);
|
||||
void fillRect(int x, int y, int width, int height);
|
||||
void drawRect(int x, int y, int width, int height);
|
||||
void fillRect(int x, int y, int width, int height);
|
||||
|
||||
void drawCircle(int x0, int y0, int radius);
|
||||
void fillCircle(int x0, int y0, int radius);
|
||||
void drawCircleQuads(int x0, int y0, int radius, int quads);
|
||||
void drawCircle(int x0, int y0, int radius);
|
||||
void fillCircle(int x0, int y0, int radius);
|
||||
void drawCircleQuads(int x0, int y0, int radius, int quads);
|
||||
|
||||
void drawProgressBar(int x, int y, int width, int height, int progress);
|
||||
void drawProgressBar(int x, int y, int width, int height, int progress);
|
||||
|
||||
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, ... );
|
||||
int drawStringLF(int x, int y, String text);
|
||||
void drawStringLFf(int x, int y, char * buffer, String format, ... );
|
||||
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, ...);
|
||||
int drawStringLF(int x, int y, String text);
|
||||
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;
|
||||
const uint _width;
|
||||
const uint _height;
|
||||
|
||||
uint8_t * _buffer;
|
||||
uint8_t *_buffer;
|
||||
|
||||
void allocateBuffer();
|
||||
void allocateBuffer();
|
||||
|
||||
friend class SSD1306;
|
||||
friend class SSD1306;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,116 +1,97 @@
|
|||
#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)
|
||||
{
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(boardConfig->OledReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
Wire.begin(boardConfig->OledSda, boardConfig->OledScl);
|
||||
_disp = std::shared_ptr<OLEDDisplay>(new SSD1306(&Wire, boardConfig->OledAddr));
|
||||
|
||||
Bitmap bitmap(_disp->getWidth(), _disp->getHeight());
|
||||
_disp->display(&bitmap);
|
||||
_displayTimeout.setTimeout(10);
|
||||
_frameTimeout.setTimeout(15);
|
||||
void Display::setup(std::shared_ptr<BoardConfig> boardConfig) {
|
||||
if (boardConfig->OledReset != 0) {
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(boardConfig->OledReset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
Wire.begin(boardConfig->OledSda, boardConfig->OledScl);
|
||||
_disp = std::shared_ptr<OLEDDisplay>(new SSD1306(&Wire, boardConfig->OledAddr));
|
||||
|
||||
Bitmap bitmap(_disp->getWidth(), _disp->getHeight());
|
||||
_disp->display(&bitmap);
|
||||
_displayTimeout.setTimeout(10);
|
||||
_frameTimeout.setTimeout(15);
|
||||
}
|
||||
|
||||
void Display::turn180()
|
||||
{
|
||||
_disp->flipScreenVertically();
|
||||
void Display::turn180() {
|
||||
_disp->flipScreenVertically();
|
||||
}
|
||||
|
||||
void Display::update()
|
||||
{
|
||||
if(_frameTimeout.check())
|
||||
{
|
||||
if(_statusFrame->isPrio())
|
||||
{
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
_disp->display(&bitmap);
|
||||
return;
|
||||
}
|
||||
void Display::update() {
|
||||
if (_frameTimeout.check()) {
|
||||
if (_statusFrame->isPrio()) {
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
_disp->display(&bitmap);
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
_frameTimeout.start();
|
||||
return;
|
||||
}
|
||||
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();
|
||||
_frameTimeout.start();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_displayOff && !_displayTimeout.isActive())
|
||||
{
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
_disp->display(&bitmap);
|
||||
_displayTimeout.start();
|
||||
}
|
||||
if(_displayTimeout.check())
|
||||
{
|
||||
deactivateDisplay();
|
||||
_displayTimeout.reset();
|
||||
}
|
||||
}
|
||||
if (!_displayOff && !_displayTimeout.isActive()) {
|
||||
Bitmap bitmap(_disp.get());
|
||||
_statusFrame->drawStatusPage(bitmap);
|
||||
activateDisplay();
|
||||
_disp->display(&bitmap);
|
||||
_displayTimeout.start();
|
||||
}
|
||||
if (_displayTimeout.check()) {
|
||||
deactivateDisplay();
|
||||
_displayTimeout.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Display::addFrame(std::shared_ptr<DisplayFrame> frame)
|
||||
{
|
||||
_frames.push_back(frame);
|
||||
void Display::addFrame(std::shared_ptr<DisplayFrame> frame) {
|
||||
_frames.push_back(frame);
|
||||
}
|
||||
|
||||
void Display::setStatusFrame(std::shared_ptr<StatusFrame> frame)
|
||||
{
|
||||
_statusFrame = frame;
|
||||
void Display::setStatusFrame(std::shared_ptr<StatusFrame> frame) {
|
||||
_statusFrame = frame;
|
||||
}
|
||||
|
||||
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(30, 45, "OE5BPA");
|
||||
_disp->display(&bitmap);
|
||||
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(30, 45, "OE5BPA");
|
||||
_disp->display(&bitmap);
|
||||
}
|
||||
|
||||
void Display::activateDisplay()
|
||||
{
|
||||
if(_displayOff)
|
||||
{
|
||||
_disp->displayOn();
|
||||
_displayOff = false;
|
||||
}
|
||||
void Display::activateDisplay() {
|
||||
if (_displayOff) {
|
||||
_disp->displayOn();
|
||||
_displayOff = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Display::deactivateDisplay()
|
||||
{
|
||||
_disp->displayOff();
|
||||
_displayOff = true;
|
||||
void Display::deactivateDisplay() {
|
||||
_disp->displayOff();
|
||||
_displayOff = true;
|
||||
}
|
||||
|
||||
|
||||
void TextFrame::drawStatusPage(Bitmap & bitmap)
|
||||
{
|
||||
bitmap.drawString(0, 0, _header);
|
||||
bitmap.drawStringLF(0, 10, _text);
|
||||
void TextFrame::drawStatusPage(Bitmap &bitmap) {
|
||||
bitmap.drawString(0, 0, _header);
|
||||
bitmap.drawStringLF(0, 10, _text);
|
||||
}
|
||||
|
|
|
@ -1,76 +1,77 @@
|
|||
#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;
|
||||
return _instance;
|
||||
}
|
||||
static Display &instance() {
|
||||
static Display _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
~Display() {}
|
||||
~Display() {
|
||||
}
|
||||
|
||||
void setup(std::shared_ptr<BoardConfig> boardConfig);
|
||||
void turn180();
|
||||
void update();
|
||||
void setup(std::shared_ptr<BoardConfig> boardConfig);
|
||||
void turn180();
|
||||
void update();
|
||||
|
||||
void addFrame(std::shared_ptr<DisplayFrame> frame);
|
||||
void addFrame(std::shared_ptr<DisplayFrame> frame);
|
||||
|
||||
void setStatusFrame(std::shared_ptr<StatusFrame> frame);
|
||||
void setStatusFrame(std::shared_ptr<StatusFrame> frame);
|
||||
|
||||
void showSpashScreen(String firmwareTitle, String version);
|
||||
void showSpashScreen(String firmwareTitle, String version);
|
||||
|
||||
private:
|
||||
std::shared_ptr<OLEDDisplay> _disp;
|
||||
std::shared_ptr<OLEDDisplay> _disp;
|
||||
|
||||
std::list<std::shared_ptr<DisplayFrame>> _frames;
|
||||
std::shared_ptr<StatusFrame> _statusFrame;
|
||||
Timer _frameTimeout;
|
||||
std::list<std::shared_ptr<DisplayFrame>> _frames;
|
||||
std::shared_ptr<StatusFrame> _statusFrame;
|
||||
Timer _frameTimeout;
|
||||
|
||||
Timer _displayTimeout;
|
||||
bool _displayOff;
|
||||
Timer _displayTimeout;
|
||||
bool _displayOff;
|
||||
|
||||
Display();
|
||||
Display(const Display &);
|
||||
Display & operator = (const Display &);
|
||||
Display();
|
||||
Display(const Display &);
|
||||
Display &operator=(const Display &);
|
||||
|
||||
void activateDisplay();
|
||||
void deactivateDisplay();
|
||||
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;
|
||||
String _text;
|
||||
String _header;
|
||||
String _text;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,81 +1,67 @@
|
|||
#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)
|
||||
{
|
||||
SPI.begin(boardConfig->LoraSck, boardConfig->LoraMiso, boardConfig->LoraMosi, boardConfig->LoraCS);
|
||||
setPins(boardConfig->LoraCS, boardConfig->LoraReset, boardConfig->LoraIRQ);
|
||||
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())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// read header:
|
||||
char dummy[4];
|
||||
readBytes(dummy, 3);
|
||||
if(dummy[0] != '<')
|
||||
{
|
||||
// is no APRS message, ignore message
|
||||
while(available())
|
||||
{
|
||||
read();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// read APRS data:
|
||||
String str;
|
||||
while(available())
|
||||
{
|
||||
str += (char)read();
|
||||
}
|
||||
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_LastReceivedMsg->decode(str);
|
||||
return true;
|
||||
bool LoRa_APRS::checkMessage() {
|
||||
if (!parsePacket()) {
|
||||
return false;
|
||||
}
|
||||
// read header:
|
||||
char dummy[4];
|
||||
readBytes(dummy, 3);
|
||||
if (dummy[0] != '<') {
|
||||
// is no APRS message, ignore message
|
||||
while (available()) {
|
||||
read();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// read APRS data:
|
||||
String str;
|
||||
while (available()) {
|
||||
str += (char)read();
|
||||
}
|
||||
_LastReceivedMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_LastReceivedMsg->decode(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage()
|
||||
{
|
||||
return _LastReceivedMsg;
|
||||
std::shared_ptr<APRSMessage> LoRa_APRS::getMessage() {
|
||||
return _LastReceivedMsg;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg)
|
||||
{
|
||||
setFrequency(_TxFrequency);
|
||||
String data = msg->encode();
|
||||
beginPacket();
|
||||
// Header:
|
||||
write('<');
|
||||
write(0xFF);
|
||||
write(0x01);
|
||||
// APRS Data:
|
||||
write((const uint8_t *)data.c_str(), data.length());
|
||||
endPacket();
|
||||
setFrequency(_RxFrequency);
|
||||
void LoRa_APRS::sendMessage(const std::shared_ptr<APRSMessage> msg) {
|
||||
setFrequency(_TxFrequency);
|
||||
String data = msg->encode();
|
||||
beginPacket();
|
||||
// Header:
|
||||
write('<');
|
||||
write(0xFF);
|
||||
write(0x01);
|
||||
// APRS Data:
|
||||
write((const uint8_t *)data.c_str(), data.length());
|
||||
endPacket();
|
||||
setFrequency(_RxFrequency);
|
||||
}
|
||||
|
||||
void LoRa_APRS::setRxFrequency(long frequency)
|
||||
{
|
||||
_RxFrequency = frequency;
|
||||
setFrequency(_RxFrequency);
|
||||
void LoRa_APRS::setRxFrequency(long frequency) {
|
||||
_RxFrequency = frequency;
|
||||
setFrequency(_RxFrequency);
|
||||
}
|
||||
|
||||
long LoRa_APRS::getRxFrequency() const
|
||||
{
|
||||
return _RxFrequency;
|
||||
long LoRa_APRS::getRxFrequency() const {
|
||||
return _RxFrequency;
|
||||
}
|
||||
|
||||
void LoRa_APRS::setTxFrequency(long frequency)
|
||||
{
|
||||
_TxFrequency = frequency;
|
||||
void LoRa_APRS::setTxFrequency(long frequency) {
|
||||
_TxFrequency = frequency;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
long LoRa_APRS::getTxFrequency() const
|
||||
{
|
||||
return _TxFrequency;
|
||||
long LoRa_APRS::getTxFrequency() const {
|
||||
return _TxFrequency;
|
||||
}
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
#ifndef LORA_H_
|
||||
#define LORA_H_
|
||||
|
||||
#include <memory>
|
||||
#include <Arduino.h>
|
||||
#include <LoRa.h>
|
||||
#include <APRS-Decoder.h>
|
||||
|
||||
#define LORA_RX_FREQUENCY (433775000)
|
||||
#define LORA_TX_FREQUENCY (433900000)
|
||||
#include <APRS-Decoder.h>
|
||||
#include <BoardFinder.h>
|
||||
#include <LoRa.h>
|
||||
#include <memory>
|
||||
|
||||
#define LORA_RX_FREQUENCY (433775000)
|
||||
#define LORA_TX_FREQUENCY (433900000)
|
||||
#define LORA_SPREADING_FACTOR (12)
|
||||
#define LORA_SIGNAL_BANDWIDTH (125E3)
|
||||
#define LORA_CODING_RATE4 (5)
|
||||
#define LORA_CODING_RATE4 (5)
|
||||
|
||||
class LoRa_APRS : public LoRaClass
|
||||
{
|
||||
class LoRa_APRS : public LoRaClass {
|
||||
public:
|
||||
explicit LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig);
|
||||
|
||||
bool checkMessage();
|
||||
std::shared_ptr<APRSMessage> getMessage();
|
||||
explicit LoRa_APRS(std::shared_ptr<BoardConfig> boardConfig);
|
||||
|
||||
void sendMessage(const std::shared_ptr<APRSMessage> msg);
|
||||
bool checkMessage();
|
||||
std::shared_ptr<APRSMessage> getMessage();
|
||||
|
||||
void setRxFrequency(long frequency);
|
||||
long getRxFrequency() const;
|
||||
void sendMessage(const std::shared_ptr<APRSMessage> msg);
|
||||
|
||||
void setTxFrequency(long frequency);
|
||||
long getTxFrequency() const;
|
||||
void setRxFrequency(long frequency);
|
||||
long getRxFrequency() const;
|
||||
|
||||
void setTxFrequency(long frequency);
|
||||
long getTxFrequency() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<APRSMessage> _LastReceivedMsg;
|
||||
long _RxFrequency;
|
||||
long _TxFrequency;
|
||||
std::shared_ptr<APRSMessage> _LastReceivedMsg;
|
||||
long _RxFrequency;
|
||||
long _TxFrequency;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,54 +2,44 @@
|
|||
#include "power_management.h"
|
||||
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
PowerManagement::PowerManagement()
|
||||
{
|
||||
PowerManagement::PowerManagement() {
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
bool PowerManagement::begin(TwoWire & port)
|
||||
{
|
||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
||||
if(!result)
|
||||
{
|
||||
axp.setDCDC1Voltage(3300);
|
||||
}
|
||||
return result;
|
||||
bool PowerManagement::begin(TwoWire &port) {
|
||||
bool result = axp.begin(port, AXP192_SLAVE_ADDRESS);
|
||||
if (!result) {
|
||||
axp.setDCDC1Voltage(3300);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateLoRa()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
void PowerManagement::activateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateLoRa()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||
void PowerManagement::deactivateLoRa() {
|
||||
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateGPS()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
void PowerManagement::activateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::deactivateGPS()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||
void PowerManagement::deactivateGPS() {
|
||||
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::activateOLED()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
void PowerManagement::activateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void PowerManagement::decativateOLED()
|
||||
{
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||
void PowerManagement::decativateOLED() {
|
||||
axp.setPowerOutPut(AXP192_DCDC1, AXP202_OFF);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,23 +4,22 @@
|
|||
#include <Arduino.h>
|
||||
#include <axp20x.h>
|
||||
|
||||
class PowerManagement
|
||||
{
|
||||
class PowerManagement {
|
||||
public:
|
||||
PowerManagement();
|
||||
bool begin(TwoWire & port);
|
||||
PowerManagement();
|
||||
bool begin(TwoWire &port);
|
||||
|
||||
void activateLoRa();
|
||||
void deactivateLoRa();
|
||||
void activateLoRa();
|
||||
void deactivateLoRa();
|
||||
|
||||
void activateGPS();
|
||||
void deactivateGPS();
|
||||
void activateGPS();
|
||||
void deactivateGPS();
|
||||
|
||||
void activateOLED();
|
||||
void decativateOLED();
|
||||
void activateOLED();
|
||||
void decativateOLED();
|
||||
|
||||
private:
|
||||
AXP20X_Class axp;
|
||||
AXP20X_Class axp;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,97 +1,77 @@
|
|||
#include <logger.h>
|
||||
#include "TaskManager.h"
|
||||
#include <FontConfig.h>
|
||||
#include <logger.h>
|
||||
|
||||
TaskManager::TaskManager()
|
||||
{
|
||||
TaskManager::TaskManager() {
|
||||
}
|
||||
|
||||
void TaskManager::addTask(std::shared_ptr<Task> task)
|
||||
{
|
||||
_tasks.push_back(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)
|
||||
{
|
||||
return task->getName() == name;
|
||||
});
|
||||
if(elem == _tasks.end())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
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()) {
|
||||
return 0;
|
||||
}
|
||||
return *elem;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<Task>> TaskManager::getTasks()
|
||||
{
|
||||
return _tasks;
|
||||
std::list<std::shared_ptr<Task>> TaskManager::getTasks() {
|
||||
return _tasks;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
logPrintW("call setup from ");
|
||||
logPrintlnW(elem->getName());
|
||||
if(!elem->setup(config, boardConfig))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
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) {
|
||||
logPrintW("call setup from ");
|
||||
logPrintlnW(elem->getName());
|
||||
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))
|
||||
{
|
||||
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)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void StatusFrame::drawStatusPage(Bitmap & bitmap)
|
||||
{
|
||||
int y = 0;
|
||||
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())
|
||||
{
|
||||
case Error:
|
||||
bitmap.drawString(x, y, "Error");
|
||||
break;
|
||||
case Warning:
|
||||
bitmap.drawString(x, y, "Warning");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bitmap.drawString(x, y, "Okay");
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap.drawString(x, y, task->getStateInfo());
|
||||
}
|
||||
y += getSystemFont()->heightInPixel;
|
||||
}
|
||||
void StatusFrame::drawStatusPage(Bitmap &bitmap) {
|
||||
int y = 0;
|
||||
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()) {
|
||||
case Error:
|
||||
bitmap.drawString(x, y, "Error");
|
||||
break;
|
||||
case Warning:
|
||||
bitmap.drawString(x, y, "Warning");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bitmap.drawString(x, y, "Okay");
|
||||
} 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)
|
||||
{
|
||||
return task->getState() != Okay;
|
||||
});
|
||||
bool StatusFrame::isPrio() const {
|
||||
return std::any_of(_tasks.begin(), _tasks.end(), [](std::shared_ptr<Task> task) {
|
||||
return task->getState() != Okay;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,84 +1,94 @@
|
|||
#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"
|
||||
|
||||
enum TaskDisplayState
|
||||
{
|
||||
Error,
|
||||
Warning,
|
||||
Okay,
|
||||
Error,
|
||||
Warning,
|
||||
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;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
|
||||
|
||||
protected:
|
||||
TaskDisplayState _state;
|
||||
String _stateInfo;
|
||||
TaskDisplayState _state;
|
||||
String _stateInfo;
|
||||
|
||||
private:
|
||||
String _name;
|
||||
int _taskId;
|
||||
String _name;
|
||||
int _taskId;
|
||||
};
|
||||
|
||||
class TaskManager
|
||||
{
|
||||
class TaskManager {
|
||||
public:
|
||||
static TaskManager & instance()
|
||||
{
|
||||
static TaskManager _instance;
|
||||
return _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::list<std::shared_ptr<Task>> getTasks();
|
||||
void addTask(std::shared_ptr<Task> task);
|
||||
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);
|
||||
bool loop(std::shared_ptr<Configuration> config);
|
||||
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
|
||||
bool loop(std::shared_ptr<Configuration> config);
|
||||
|
||||
private:
|
||||
std::list<std::shared_ptr<Task>> _tasks;
|
||||
std::list<std::shared_ptr<Task>> _tasks;
|
||||
|
||||
TaskManager();
|
||||
TaskManager(const TaskManager &);
|
||||
TaskManager & operator = (const TaskManager &);
|
||||
TaskManager();
|
||||
TaskManager(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;
|
||||
bool isPrio() const;
|
||||
|
||||
private:
|
||||
std::list<std::shared_ptr<Task>> _tasks;
|
||||
std::list<std::shared_ptr<Task>> _tasks;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,31 +3,27 @@
|
|||
|
||||
#include <list>
|
||||
|
||||
template <typename T>
|
||||
class TaskQueue
|
||||
{
|
||||
template <typename T> class TaskQueue {
|
||||
public:
|
||||
TaskQueue() {}
|
||||
TaskQueue() {
|
||||
}
|
||||
|
||||
void addElement(T elem)
|
||||
{
|
||||
_elements.push_back(elem);
|
||||
}
|
||||
void addElement(T elem) {
|
||||
_elements.push_back(elem);
|
||||
}
|
||||
|
||||
T getElement()
|
||||
{
|
||||
T elem = _elements.front();
|
||||
_elements.pop_front();
|
||||
return elem;
|
||||
}
|
||||
T getElement() {
|
||||
T elem = _elements.front();
|
||||
_elements.pop_front();
|
||||
return elem;
|
||||
}
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return _elements.empty();
|
||||
}
|
||||
bool empty() const {
|
||||
return _elements.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
std::list<T> _elements;
|
||||
std::list<T> _elements;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
_timeout_sec = timeout_sec;
|
||||
void Timer::setTimeout(const time_t timeout_sec) {
|
||||
_timeout_sec = timeout_sec;
|
||||
}
|
||||
|
||||
time_t Timer::getTriggerTime() const
|
||||
{
|
||||
return _timeout;
|
||||
time_t Timer::getTriggerTime() const {
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool Timer::isActive() const
|
||||
{
|
||||
return _timeout != 0;
|
||||
bool Timer::isActive() const {
|
||||
return _timeout != 0;
|
||||
}
|
||||
|
||||
void Timer::reset()
|
||||
{
|
||||
_timeout = 0;
|
||||
void Timer::reset() {
|
||||
_timeout = 0;
|
||||
}
|
||||
|
||||
bool Timer::check()
|
||||
{
|
||||
return now() > _timeout;
|
||||
bool Timer::check() {
|
||||
return now() > _timeout;
|
||||
}
|
||||
|
||||
void Timer::start()
|
||||
{
|
||||
_timeout = now() + _timeout_sec;
|
||||
void Timer::start() {
|
||||
_timeout = now() + _timeout_sec;
|
||||
}
|
||||
|
|
|
@ -3,24 +3,23 @@
|
|||
|
||||
#include <TimeLib.h>
|
||||
|
||||
class Timer
|
||||
{
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
Timer();
|
||||
|
||||
void setTimeout(const time_t timeout_sec);
|
||||
time_t getTriggerTime() const;
|
||||
void setTimeout(const time_t timeout_sec);
|
||||
time_t getTriggerTime() const;
|
||||
|
||||
bool isActive() const;
|
||||
bool isActive() const;
|
||||
|
||||
void reset();
|
||||
void reset();
|
||||
|
||||
bool check();
|
||||
void start();
|
||||
bool check();
|
||||
void start();
|
||||
|
||||
private:
|
||||
time_t _timeout_sec;
|
||||
time_t _timeout;
|
||||
time_t _timeout_sec;
|
||||
time_t _timeout;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -26,129 +23,116 @@ String create_lat_aprs(double lat);
|
|||
String create_long_aprs(double lng);
|
||||
|
||||
std::shared_ptr<Configuration> userConfig;
|
||||
std::shared_ptr<BoardConfig> boardConfig;
|
||||
HardwareSerial Serial(0);
|
||||
std::shared_ptr<BoardConfig> boardConfig;
|
||||
HardwareSerial Serial(0);
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Logger::instance().setSerial(&Serial);
|
||||
delay(500);
|
||||
logPrintlnW("LoRa APRS iGate by OE5BPA (Peter Buchegger)");
|
||||
logPrintlnW("Version: " VERSION);
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Logger::instance().setSerial(&Serial);
|
||||
delay(500);
|
||||
logPrintlnW("LoRa APRS iGate by OE5BPA (Peter Buchegger)");
|
||||
logPrintlnW("Version: " VERSION);
|
||||
|
||||
ProjectConfigurationManagement confmg;
|
||||
userConfig = confmg.readConfiguration();
|
||||
ProjectConfigurationManagement confmg;
|
||||
userConfig = confmg.readConfiguration();
|
||||
|
||||
std::list<std::shared_ptr<BoardConfig>> boardConfigs;
|
||||
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)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true, true)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36)));
|
||||
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)));
|
||||
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)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true, true)));
|
||||
boardConfigs.push_back(std::shared_ptr<BoardConfig>(new BoardConfig("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36)));
|
||||
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)
|
||||
{
|
||||
boardConfig = finder.searchBoardConfig();
|
||||
if(boardConfig == 0)
|
||||
{
|
||||
logPrintlnE("Board config not set and search failed!");
|
||||
while(true)
|
||||
{}
|
||||
}
|
||||
userConfig->board = boardConfig->Name;
|
||||
confmg.writeConfiguration(userConfig);
|
||||
logPrintlnI("will restart board now!");
|
||||
ESP.restart();
|
||||
}
|
||||
logPrintI("Board ");
|
||||
logPrintI(boardConfig->Name);
|
||||
logPrintlnI(" loaded.");
|
||||
BoardFinder finder(boardConfigs);
|
||||
boardConfig = finder.getBoardConfig(userConfig->board);
|
||||
if (boardConfig == 0) {
|
||||
boardConfig = finder.searchBoardConfig();
|
||||
if (boardConfig == 0) {
|
||||
logPrintlnE("Board config not set and search failed!");
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
userConfig->board = boardConfig->Name;
|
||||
confmg.writeConfiguration(userConfig);
|
||||
logPrintlnI("will restart board now!");
|
||||
ESP.restart();
|
||||
}
|
||||
logPrintI("Board ");
|
||||
logPrintI(boardConfig->Name);
|
||||
logPrintlnI(" loaded.");
|
||||
|
||||
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))
|
||||
{
|
||||
logPrintlnI("AXP192 init done!");
|
||||
}
|
||||
else
|
||||
{
|
||||
logPrintlnE("AXP192 init failed!");
|
||||
}
|
||||
powerManagement->activateLoRa();
|
||||
powerManagement->activateOLED();
|
||||
powerManagement->deactivateGPS();
|
||||
}
|
||||
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)) {
|
||||
logPrintlnI("AXP192 init done!");
|
||||
} else {
|
||||
logPrintlnE("AXP192 init failed!");
|
||||
}
|
||||
powerManagement->activateLoRa();
|
||||
powerManagement->activateOLED();
|
||||
powerManagement->deactivateGPS();
|
||||
}
|
||||
|
||||
load_config(boardConfig);
|
||||
load_config(boardConfig);
|
||||
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new DisplayTask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new LoraTask()));
|
||||
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)
|
||||
{
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new FTPTask()));
|
||||
}
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new AprsIsTask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new DisplayTask()));
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new LoraTask()));
|
||||
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) {
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new FTPTask()));
|
||||
}
|
||||
TaskManager::instance().addTask(std::shared_ptr<Task>(new AprsIsTask()));
|
||||
|
||||
TaskManager::instance().setup(userConfig, boardConfig);
|
||||
TaskManager::instance().setup(userConfig, boardConfig);
|
||||
|
||||
Display::instance().showSpashScreen("LoRa APRS iGate", VERSION);
|
||||
Display::instance().showSpashScreen("LoRa APRS iGate", VERSION);
|
||||
|
||||
if(userConfig->display.overwritePin != 0)
|
||||
{
|
||||
pinMode(userConfig->display.overwritePin, INPUT);
|
||||
pinMode(userConfig->display.overwritePin, INPUT_PULLUP);
|
||||
}
|
||||
if (userConfig->display.overwritePin != 0) {
|
||||
pinMode(userConfig->display.overwritePin, INPUT);
|
||||
pinMode(userConfig->display.overwritePin, INPUT_PULLUP);
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
logPrintlnI("setup done...");
|
||||
delay(5000);
|
||||
logPrintlnI("setup done...");
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
void loop()
|
||||
{
|
||||
TaskManager::instance().loop(userConfig);
|
||||
void loop() {
|
||||
TaskManager::instance().loop(userConfig);
|
||||
}
|
||||
|
||||
String create_lat_aprs(double lat)
|
||||
{
|
||||
char str[20];
|
||||
char n_s = 'N';
|
||||
if(lat < 0)
|
||||
{
|
||||
n_s = 'S';
|
||||
}
|
||||
lat = std::abs(lat);
|
||||
sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s);
|
||||
String lat_str(str);
|
||||
return lat_str;
|
||||
String create_lat_aprs(double lat) {
|
||||
char str[20];
|
||||
char n_s = 'N';
|
||||
if (lat < 0) {
|
||||
n_s = 'S';
|
||||
}
|
||||
lat = std::abs(lat);
|
||||
sprintf(str, "%02d%05.2f%c", (int)lat, (lat - (double)((int)lat)) * 60.0, n_s);
|
||||
String lat_str(str);
|
||||
return lat_str;
|
||||
}
|
||||
|
||||
String create_long_aprs(double lng)
|
||||
{
|
||||
char str[20];
|
||||
char e_w = 'E';
|
||||
if(lng < 0)
|
||||
{
|
||||
e_w = 'W';
|
||||
}
|
||||
lng = std::abs(lng);
|
||||
sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w);
|
||||
String lng_str(str);
|
||||
return lng_str;
|
||||
String create_long_aprs(double lng) {
|
||||
char str[20];
|
||||
char e_w = 'E';
|
||||
if (lng < 0) {
|
||||
e_w = 'W';
|
||||
}
|
||||
lng = std::abs(lng);
|
||||
sprintf(str, "%03d%05.2f%c", (int)lng, (lng - (double)((int)lng)) * 60.0, e_w);
|
||||
String lng_str(str);
|
||||
return lng_str;
|
||||
}
|
||||
|
|
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";
|
||||
}
|
||||
}*/
|
32
src/Task.h
32
src/Task.h
|
@ -3,24 +3,24 @@
|
|||
|
||||
enum TaskNames
|
||||
{
|
||||
TaskAprsIs = 1,
|
||||
TaskEth,
|
||||
TaskFtp,
|
||||
TaskLora,
|
||||
TaskNtp,
|
||||
TaskOta,
|
||||
TaskWifi,
|
||||
TaskSize,
|
||||
TaskAprsIs = 1,
|
||||
TaskEth,
|
||||
TaskFtp,
|
||||
TaskLora,
|
||||
TaskNtp,
|
||||
TaskOta,
|
||||
TaskWifi,
|
||||
TaskSize,
|
||||
};
|
||||
|
||||
//char const * const getTaskName(TaskNames task);
|
||||
// char const * const getTaskName(TaskNames task);
|
||||
|
||||
#define TASK_APRS_IS "AprsIsTask"
|
||||
#define TASK_ETH "EthTask"
|
||||
#define TASK_FTP "FTPTask"
|
||||
#define TASK_LORA "LoraTask"
|
||||
#define TASK_NTP "NTPTask"
|
||||
#define TASK_OTA "OTATask"
|
||||
#define TASK_WIFI "WifiTask"
|
||||
#define TASK_APRS_IS "AprsIsTask"
|
||||
#define TASK_ETH "EthTask"
|
||||
#define TASK_FTP "FTPTask"
|
||||
#define TASK_LORA "LoraTask"
|
||||
#define TASK_NTP "NTPTask"
|
||||
#define TASK_OTA "OTATask"
|
||||
#define TASK_WIFI "WifiTask"
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,84 +1,74 @@
|
|||
#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)
|
||||
{
|
||||
_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"));
|
||||
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"));
|
||||
|
||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_beaconMsg->setSource(config->callsign);
|
||||
_beaconMsg->setDestination("APLG1");
|
||||
String lat = create_lat_aprs(config->beacon.positionLatitude);
|
||||
String lng = create_long_aprs(config->beacon.positionLongitude);
|
||||
_beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "a" + config->beacon.message);
|
||||
_beaconMsg = std::shared_ptr<APRSMessage>(new APRSMessage());
|
||||
_beaconMsg->setSource(config->callsign);
|
||||
_beaconMsg->setDestination("APLG1");
|
||||
String lat = create_lat_aprs(config->beacon.positionLatitude);
|
||||
String lng = create_long_aprs(config->beacon.positionLongitude);
|
||||
_beaconMsg->getBody()->setData(String("=") + lat + "L" + lng + "a" + config->beacon.message);
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AprsIsTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_aprs_is->connected())
|
||||
{
|
||||
if(!connect(config))
|
||||
{
|
||||
_stateInfo = "not connected";
|
||||
_state = Error;
|
||||
return false;
|
||||
}
|
||||
_stateInfo = "connected";
|
||||
_state = Okay;
|
||||
return false;
|
||||
}
|
||||
|
||||
_aprs_is->getAPRSMessage();
|
||||
bool AprsIsTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_aprs_is->connected()) {
|
||||
if (!connect(config)) {
|
||||
_stateInfo = "not connected";
|
||||
_state = Error;
|
||||
return false;
|
||||
}
|
||||
_stateInfo = "connected";
|
||||
_state = Okay;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!inputQueue.empty())
|
||||
{
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_aprs_is->sendMessage(msg);
|
||||
}
|
||||
_aprs_is->getAPRSMessage();
|
||||
|
||||
if(_beacon_timer.check())
|
||||
{
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintlnD(_beaconMsg->encode());
|
||||
_aprs_is->sendMessage(_beaconMsg);
|
||||
Display::instance().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));
|
||||
_state = Okay;
|
||||
return true;
|
||||
if (!inputQueue.empty()) {
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_aprs_is->sendMessage(msg);
|
||||
}
|
||||
|
||||
if (_beacon_timer.check()) {
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintlnD(_beaconMsg->encode());
|
||||
_aprs_is->sendMessage(_beaconMsg);
|
||||
Display::instance().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));
|
||||
_state = Okay;
|
||||
return true;
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
logPrintlnE("Connection failed.");
|
||||
return false;
|
||||
}
|
||||
logPrintlnI("Connected to APRS-IS server!");
|
||||
return true;
|
||||
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)) {
|
||||
logPrintlnE("Connection failed.");
|
||||
return false;
|
||||
}
|
||||
logPrintlnI("Connected to APRS-IS server!");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,28 +1,27 @@
|
|||
#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();
|
||||
AprsIsTask();
|
||||
virtual ~AprsIsTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||
|
||||
private:
|
||||
std::shared_ptr<APRS_IS> _aprs_is;
|
||||
std::shared_ptr<APRSMessage> _beaconMsg;
|
||||
Timer _beacon_timer;
|
||||
std::shared_ptr<APRS_IS> _aprs_is;
|
||||
std::shared_ptr<APRSMessage> _beaconMsg;
|
||||
Timer _beacon_timer;
|
||||
|
||||
bool connect(std::shared_ptr<Configuration> config);
|
||||
bool connect(std::shared_ptr<Configuration> config);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,32 +1,27 @@
|
|||
#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)
|
||||
{
|
||||
Display::instance().setup(boardConfig);
|
||||
if(config->display.turn180)
|
||||
{
|
||||
Display::instance().turn180();
|
||||
}
|
||||
std::shared_ptr<StatusFrame> statusFrame = std::shared_ptr<StatusFrame>(new StatusFrame(TaskManager::instance().getTasks()));
|
||||
Display::instance().setStatusFrame(statusFrame);
|
||||
_stateInfo = config->callsign;
|
||||
return true;
|
||||
bool DisplayTask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
Display::instance().setup(boardConfig);
|
||||
if (config->display.turn180) {
|
||||
Display::instance().turn180();
|
||||
}
|
||||
std::shared_ptr<StatusFrame> statusFrame = std::shared_ptr<StatusFrame>(new StatusFrame(TaskManager::instance().getTasks()));
|
||||
Display::instance().setStatusFrame(statusFrame);
|
||||
_stateInfo = config->callsign;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
Display::instance().update();
|
||||
return true;
|
||||
bool DisplayTask::loop(std::shared_ptr<Configuration> config) {
|
||||
Display::instance().update();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,14 +4,13 @@
|
|||
#include <Display.h>
|
||||
#include <TaskManager.h>
|
||||
|
||||
class DisplayTask : public Task
|
||||
{
|
||||
class DisplayTask : public Task {
|
||||
public:
|
||||
DisplayTask();
|
||||
virtual ~DisplayTask();
|
||||
DisplayTask();
|
||||
virtual ~DisplayTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
132
src/TaskEth.cpp
132
src/TaskEth.cpp
|
@ -1,87 +1,81 @@
|
|||
#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)
|
||||
{
|
||||
switch (event) {
|
||||
case SYSTEM_EVENT_ETH_START:
|
||||
logPrintlnI("ETH Started");
|
||||
ETH.setHostname("esp32-ethernet");
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
logPrintlnI("ETH Connected");
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
logPrintI("ETH MAC: ");
|
||||
logPrintI(ETH.macAddress());
|
||||
logPrintI(", IPv4: ");
|
||||
logPrintI(ETH.localIP().toString());
|
||||
if (ETH.fullDuplex()) {
|
||||
logPrintI(", FULL_DUPLEX");
|
||||
}
|
||||
logPrintI(", ");
|
||||
logPrintI(String(ETH.linkSpeed()));
|
||||
logPrintlnI("Mbps");
|
||||
eth_connected = true;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
logPrintlnW("ETH Disconnected");
|
||||
eth_connected = false;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_STOP:
|
||||
logPrintlnW("ETH Stopped");
|
||||
eth_connected = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
static void WiFiEvent(WiFiEvent_t event) {
|
||||
switch (event) {
|
||||
case SYSTEM_EVENT_ETH_START:
|
||||
logPrintlnI("ETH Started");
|
||||
ETH.setHostname("esp32-ethernet");
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_CONNECTED:
|
||||
logPrintlnI("ETH Connected");
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_GOT_IP:
|
||||
logPrintI("ETH MAC: ");
|
||||
logPrintI(ETH.macAddress());
|
||||
logPrintI(", IPv4: ");
|
||||
logPrintI(ETH.localIP().toString());
|
||||
if (ETH.fullDuplex()) {
|
||||
logPrintI(", FULL_DUPLEX");
|
||||
}
|
||||
logPrintI(", ");
|
||||
logPrintI(String(ETH.linkSpeed()));
|
||||
logPrintlnI("Mbps");
|
||||
eth_connected = true;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED:
|
||||
logPrintlnW("ETH Disconnected");
|
||||
eth_connected = false;
|
||||
break;
|
||||
case SYSTEM_EVENT_ETH_STOP:
|
||||
logPrintlnW("ETH Stopped");
|
||||
eth_connected = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
WiFi.onEvent(WiFiEvent);
|
||||
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_CLK ETH_CLOCK_GPIO0_OUT // TTGO PoE V1.2
|
||||
#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);
|
||||
digitalWrite(ETH_NRST, 0);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 1);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 0);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 1);
|
||||
pinMode(ETH_NRST, OUTPUT);
|
||||
digitalWrite(ETH_NRST, 0);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 1);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 0);
|
||||
delay(200);
|
||||
digitalWrite(ETH_NRST, 1);
|
||||
|
||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK);
|
||||
while(!eth_connected)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
return true;
|
||||
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK);
|
||||
while (!eth_connected) {
|
||||
sleep(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EthTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
return true;
|
||||
bool EthTask::loop(std::shared_ptr<Configuration> config) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3,14 +3,13 @@
|
|||
|
||||
#include <TaskManager.h>
|
||||
|
||||
class EthTask : public Task
|
||||
{
|
||||
class EthTask : public Task {
|
||||
public:
|
||||
EthTask();
|
||||
virtual ~EthTask();
|
||||
EthTask();
|
||||
virtual ~EthTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
private:
|
||||
};
|
||||
|
|
|
@ -1,52 +1,44 @@
|
|||
#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)
|
||||
{
|
||||
_ftpServer = std::shared_ptr<FTPServer>(new FTPServer());
|
||||
for(Configuration::Ftp::User user : config->ftp.users)
|
||||
{
|
||||
logPrintD("Adding user to FTP Server: ");
|
||||
logPrintlnD(user.name);
|
||||
_ftpServer->addUser(user.name, user.password);
|
||||
}
|
||||
_ftpServer->addFilesystem("SPIFFS", &SPIFFS);
|
||||
_stateInfo = "waiting";
|
||||
return true;
|
||||
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) {
|
||||
logPrintD("Adding user to FTP Server: ");
|
||||
logPrintlnD(user.name);
|
||||
_ftpServer->addUser(user.name, user.password);
|
||||
}
|
||||
_ftpServer->addFilesystem("SPIFFS", &SPIFFS);
|
||||
_stateInfo = "waiting";
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
||||
logPrintlnW("");
|
||||
ESP.restart();
|
||||
}
|
||||
if(_ftpServer->countConnections() > 0)
|
||||
{
|
||||
configWasOpen = true;
|
||||
_stateInfo = "has connection";
|
||||
}
|
||||
return true;
|
||||
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) {
|
||||
logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config...");
|
||||
logPrintlnW("");
|
||||
ESP.restart();
|
||||
}
|
||||
if (_ftpServer->countConnections() > 0) {
|
||||
configWasOpen = true;
|
||||
_stateInfo = "has connection";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#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();
|
||||
FTPTask();
|
||||
virtual ~FTPTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<FTPServer> _ftpServer;
|
||||
bool _beginCalled;
|
||||
std::shared_ptr<FTPServer> _ftpServer;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,64 +1,58 @@
|
|||
#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)
|
||||
{
|
||||
_lora_aprs = std::shared_ptr<LoRa_APRS>(new LoRa_APRS(boardConfig));
|
||||
if(!_lora_aprs->begin(_lora_aprs->getRxFrequency()))
|
||||
{
|
||||
logPrintlnE("Starting LoRa failed!");
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
while(true);
|
||||
}
|
||||
_lora_aprs->setRxFrequency(config->lora.frequencyRx);
|
||||
_lora_aprs->setTxFrequency(config->lora.frequencyTx);
|
||||
_lora_aprs->setTxPower(config->lora.power);
|
||||
_lora_aprs->setSpreadingFactor(config->lora.spreadingFactor);
|
||||
_lora_aprs->setSignalBandwidth(config->lora.signalBandwidth);
|
||||
_lora_aprs->setCodingRate4(config->lora.codingRate4);
|
||||
_lora_aprs->enableCrc();
|
||||
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())) {
|
||||
logPrintlnE("Starting LoRa failed!");
|
||||
_stateInfo = "LoRa-Modem failed";
|
||||
_state = Error;
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
_lora_aprs->setRxFrequency(config->lora.frequencyRx);
|
||||
_lora_aprs->setTxFrequency(config->lora.frequencyTx);
|
||||
_lora_aprs->setTxPower(config->lora.power);
|
||||
_lora_aprs->setSpreadingFactor(config->lora.spreadingFactor);
|
||||
_lora_aprs->setSignalBandwidth(config->lora.signalBandwidth);
|
||||
_lora_aprs->setCodingRate4(config->lora.codingRate4);
|
||||
_lora_aprs->enableCrc();
|
||||
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
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");
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintD("Received packet '");
|
||||
logPrintD(msg->toString());
|
||||
logPrintD("' with RSSI ");
|
||||
logPrintD(String(_lora_aprs->packetRssi()));
|
||||
logPrintD(" and SNR ");
|
||||
logPrintlnD(String(_lora_aprs->packetSnr()));
|
||||
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(TaskManager::instance().getTask(TASK_APRS_IS));
|
||||
is_thread->inputQueue.addElement(msg);
|
||||
Display::instance().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString())));
|
||||
}
|
||||
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");
|
||||
logPrintD("[" + timeString() + "] ");
|
||||
logPrintD("Received packet '");
|
||||
logPrintD(msg->toString());
|
||||
logPrintD("' with RSSI ");
|
||||
logPrintD(String(_lora_aprs->packetRssi()));
|
||||
logPrintD(" and SNR ");
|
||||
logPrintlnD(String(_lora_aprs->packetSnr()));
|
||||
std::shared_ptr<AprsIsTask> is_thread = std::static_pointer_cast<AprsIsTask>(TaskManager::instance().getTask(TASK_APRS_IS));
|
||||
is_thread->inputQueue.addElement(msg);
|
||||
Display::instance().addFrame(std::shared_ptr<DisplayFrame>(new TextFrame("LoRa", msg->toString())));
|
||||
}
|
||||
|
||||
if(!inputQueue.empty())
|
||||
{
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_lora_aprs->sendMessage(msg);
|
||||
}
|
||||
if (!inputQueue.empty()) {
|
||||
std::shared_ptr<APRSMessage> msg = inputQueue.getElement();
|
||||
_lora_aprs->sendMessage(msg);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
#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();
|
||||
LoraTask();
|
||||
virtual ~LoraTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||
TaskQueue<std::shared_ptr<APRSMessage>> inputQueue;
|
||||
|
||||
private:
|
||||
std::shared_ptr<LoRa_APRS> _lora_aprs;
|
||||
std::shared_ptr<LoRa_APRS> _lora_aprs;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,38 +1,32 @@
|
|||
#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)
|
||||
{
|
||||
_ntpClient = std::shared_ptr<NTPClient>(new NTPClient(config->ntpServer.c_str()));
|
||||
return true;
|
||||
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)
|
||||
{
|
||||
_ntpClient->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
if(_ntpClient->update())
|
||||
{
|
||||
setTime(_ntpClient->getEpochTime());
|
||||
logPrintI("Current time: ");
|
||||
logPrintlnI(_ntpClient->getFormattedTime());
|
||||
}
|
||||
_stateInfo = _ntpClient->getFormattedTime();
|
||||
_state = Okay;
|
||||
return true;
|
||||
bool NTPTask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_beginCalled) {
|
||||
_ntpClient->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
if (_ntpClient->update()) {
|
||||
setTime(_ntpClient->getEpochTime());
|
||||
logPrintI("Current time: ");
|
||||
logPrintlnI(_ntpClient->getFormattedTime());
|
||||
}
|
||||
_stateInfo = _ntpClient->getFormattedTime();
|
||||
_state = Okay;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#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();
|
||||
NTPTask();
|
||||
virtual ~NTPTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<NTPClient> _ntpClient;
|
||||
bool _beginCalled;
|
||||
std::shared_ptr<NTPClient> _ntpClient;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
102
src/TaskOTA.cpp
102
src/TaskOTA.cpp
|
@ -1,63 +1,59 @@
|
|||
#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)
|
||||
{
|
||||
_ota = std::shared_ptr<ArduinoOTAClass>(new ArduinoOTAClass());
|
||||
_ota->onStart([&]()
|
||||
{
|
||||
String type;
|
||||
if (_ota->getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
logPrintlnI("Start updating " + type);
|
||||
})
|
||||
.onEnd([]()
|
||||
{
|
||||
logPrintlnI("");
|
||||
logPrintlnI("OTA End");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{
|
||||
logPrintI("Progress: ");
|
||||
logPrintI(String(progress / (total / 100)));
|
||||
logPrintlnI("%");
|
||||
})
|
||||
.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");
|
||||
});
|
||||
_ota->setHostname(config->callsign.c_str());
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
bool OTATask::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
|
||||
_ota = std::shared_ptr<ArduinoOTAClass>(new ArduinoOTAClass());
|
||||
_ota->onStart([&]() {
|
||||
String type;
|
||||
if (_ota->getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
logPrintlnI("Start updating " + type);
|
||||
})
|
||||
.onEnd([]() {
|
||||
logPrintlnI("");
|
||||
logPrintlnI("OTA End");
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
logPrintI("Progress: ");
|
||||
logPrintI(String(progress / (total / 100)));
|
||||
logPrintlnI("%");
|
||||
})
|
||||
.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");
|
||||
});
|
||||
_ota->setHostname(config->callsign.c_str());
|
||||
_stateInfo = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OTATask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
if(!_beginCalled)
|
||||
{
|
||||
_ota->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
_ota->handle();
|
||||
return true;
|
||||
bool OTATask::loop(std::shared_ptr<Configuration> config) {
|
||||
if (!_beginCalled) {
|
||||
_ota->begin();
|
||||
_beginCalled = true;
|
||||
}
|
||||
_ota->handle();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
#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();
|
||||
OTATask();
|
||||
virtual ~OTATask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<ArduinoOTAClass> _ota;
|
||||
bool _beginCalled;
|
||||
std::shared_ptr<ArduinoOTAClass> _ota;
|
||||
bool _beginCalled;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,51 +1,44 @@
|
|||
#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);
|
||||
WiFi.setHostname(config->callsign.c_str());
|
||||
_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());
|
||||
}
|
||||
return true;
|
||||
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) {
|
||||
logPrintD("Looking for AP: ");
|
||||
logPrintlnD(ap.SSID);
|
||||
_wiFiMulti->addAP(ap.SSID.c_str(), ap.password.c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WifiTask::loop(std::shared_ptr<Configuration> config)
|
||||
{
|
||||
const uint8_t wifi_status = _wiFiMulti->run();
|
||||
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)
|
||||
{
|
||||
logPrintD("IP address: ");
|
||||
logPrintlnD(WiFi.localIP().toString());
|
||||
_oldWifiStatus = wifi_status;
|
||||
return false;
|
||||
}
|
||||
_stateInfo = WiFi.localIP().toString();
|
||||
_state = Okay;
|
||||
return true;
|
||||
bool WifiTask::loop(std::shared_ptr<Configuration> config) {
|
||||
const uint8_t wifi_status = _wiFiMulti->run();
|
||||
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) {
|
||||
logPrintD("IP address: ");
|
||||
logPrintlnD(WiFi.localIP().toString());
|
||||
_oldWifiStatus = wifi_status;
|
||||
return false;
|
||||
}
|
||||
_stateInfo = WiFi.localIP().toString();
|
||||
_state = Okay;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -4,18 +4,17 @@
|
|||
#include <TaskManager.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
class WifiTask : public Task
|
||||
{
|
||||
class WifiTask : public Task {
|
||||
public:
|
||||
WifiTask();
|
||||
virtual ~WifiTask();
|
||||
WifiTask();
|
||||
virtual ~WifiTask();
|
||||
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) override;
|
||||
virtual bool loop(std::shared_ptr<Configuration> config) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<WiFiMulti> _wiFiMulti;
|
||||
uint8_t _oldWifiStatus;
|
||||
std::shared_ptr<WiFiMulti> _wiFiMulti;
|
||||
uint8_t _oldWifiStatus;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,125 +1,117 @@
|
|||
#include <SPIFFS.h>
|
||||
|
||||
#include <logger.h>
|
||||
|
||||
#include "project_configuration.h"
|
||||
#include "logger.h"
|
||||
|
||||
std::shared_ptr<Configuration> ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocument & data)
|
||||
{
|
||||
std::shared_ptr<Configuration> conf = std::shared_ptr<Configuration>(new Configuration);
|
||||
if(data.containsKey("callsign"))
|
||||
conf->callsign = data["callsign"].as<String>();
|
||||
std::shared_ptr<Configuration> ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocument &data) {
|
||||
std::shared_ptr<Configuration> conf = std::shared_ptr<Configuration>(new Configuration);
|
||||
if (data.containsKey("callsign"))
|
||||
conf->callsign = data["callsign"].as<String>();
|
||||
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
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"))
|
||||
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"))
|
||||
conf->aprs_is.passcode = data["aprs_is"]["passcode"].as<String>();
|
||||
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;
|
||||
JsonArray aps = data["wifi"]["AP"].as<JsonArray>();
|
||||
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"))
|
||||
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"))
|
||||
conf->aprs_is.passcode = data["aprs_is"]["passcode"].as<String>();
|
||||
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;
|
||||
|
||||
conf->lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000;
|
||||
conf->lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000;
|
||||
conf->lora.power = data["lora"]["power"] | 20;
|
||||
conf->lora.spreadingFactor = data["lora"]["spreading_factor"] | 12;
|
||||
conf->lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000;
|
||||
conf->lora.codingRate4 = data["lora"]["coding_rate4"] | 5;
|
||||
conf->display.alwaysOn = data["display"]["always_on"] | true;
|
||||
conf->display.timeout = data["display"]["timeout"] | 10;
|
||||
conf->display.overwritePin = data["display"]["overwrite_pin"] | 0;
|
||||
conf->display.turn180 = data["display"]["turn180"] | true;
|
||||
conf->lora.frequencyRx = data["lora"]["frequency_rx"] | 433775000;
|
||||
conf->lora.frequencyTx = data["lora"]["frequency_tx"] | 433775000;
|
||||
conf->lora.power = data["lora"]["power"] | 20;
|
||||
conf->lora.spreadingFactor = data["lora"]["spreading_factor"] | 12;
|
||||
conf->lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000;
|
||||
conf->lora.codingRate4 = data["lora"]["coding_rate4"] | 5;
|
||||
conf->display.alwaysOn = data["display"]["always_on"] | true;
|
||||
conf->display.timeout = data["display"]["timeout"] | 10;
|
||||
conf->display.overwritePin = data["display"]["overwrite_pin"] | 0;
|
||||
conf->display.turn180 = data["display"]["turn180"] | true;
|
||||
|
||||
conf->ftp.active = data["ftp"]["active"] | false;
|
||||
JsonArray users = data["ftp"]["user"].as<JsonArray>();
|
||||
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())
|
||||
{
|
||||
Configuration::Ftp::User us;
|
||||
us.name = "ftp";
|
||||
us.password = "ftp";
|
||||
conf->ftp.users.push_back(us);
|
||||
}
|
||||
if(data.containsKey("ntp_server"))
|
||||
conf->ntpServer = data["ntp_server"].as<String>();
|
||||
conf->ftp.active = data["ftp"]["active"] | false;
|
||||
JsonArray users = data["ftp"]["user"].as<JsonArray>();
|
||||
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()) {
|
||||
Configuration::Ftp::User us;
|
||||
us.name = "ftp";
|
||||
us.password = "ftp";
|
||||
conf->ftp.users.push_back(us);
|
||||
}
|
||||
if (data.containsKey("ntp_server"))
|
||||
conf->ntpServer = data["ntp_server"].as<String>();
|
||||
|
||||
if(data.containsKey("board"))
|
||||
conf->board = data["board"].as<String>();
|
||||
if (data.containsKey("board"))
|
||||
conf->board = data["board"].as<String>();
|
||||
|
||||
return conf;
|
||||
return conf;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
JsonObject v = aps.createNestedObject();
|
||||
v["SSID"] = ap.SSID;
|
||||
v["password"] = ap.password;
|
||||
}
|
||||
data["beacon"]["message"] = conf->beacon.message;
|
||||
data["beacon"]["position"]["latitude"] = conf->beacon.positionLatitude;
|
||||
data["beacon"]["position"]["longitude"] = conf->beacon.positionLongitude;
|
||||
data["beacon"]["timeout"] = conf->beacon.timeout;
|
||||
data["aprs_is"]["passcode"] = conf->aprs_is.passcode;
|
||||
data["aprs_is"]["server"] = conf->aprs_is.server;
|
||||
data["aprs_is"]["port"] = conf->aprs_is.port;
|
||||
data["lora"]["frequency_rx"] = conf->lora.frequencyRx;
|
||||
data["lora"]["frequency_tx"] = conf->lora.frequencyTx;
|
||||
data["lora"]["power"] = conf->lora.power;
|
||||
data["lora"]["spreading_factor"] = conf->lora.spreadingFactor;
|
||||
data["lora"]["signal_bandwidth"] = conf->lora.signalBandwidth;
|
||||
data["lora"]["coding_rate4"] = conf->lora.codingRate4;
|
||||
data["display"]["always_on"] = conf->display.alwaysOn;
|
||||
data["display"]["timeout"] = conf->display.timeout;
|
||||
data["display"]["overwrite_pin"] = conf->display.overwritePin;
|
||||
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)
|
||||
{
|
||||
JsonObject v = users.createNestedObject();
|
||||
v["name"] = u.name;
|
||||
v["password"] = u.password;
|
||||
}
|
||||
data["ntp_server"] = conf->ntpServer;
|
||||
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) {
|
||||
JsonObject v = aps.createNestedObject();
|
||||
v["SSID"] = ap.SSID;
|
||||
v["password"] = ap.password;
|
||||
}
|
||||
data["beacon"]["message"] = conf->beacon.message;
|
||||
data["beacon"]["position"]["latitude"] = conf->beacon.positionLatitude;
|
||||
data["beacon"]["position"]["longitude"] = conf->beacon.positionLongitude;
|
||||
data["beacon"]["timeout"] = conf->beacon.timeout;
|
||||
data["aprs_is"]["passcode"] = conf->aprs_is.passcode;
|
||||
data["aprs_is"]["server"] = conf->aprs_is.server;
|
||||
data["aprs_is"]["port"] = conf->aprs_is.port;
|
||||
data["lora"]["frequency_rx"] = conf->lora.frequencyRx;
|
||||
data["lora"]["frequency_tx"] = conf->lora.frequencyTx;
|
||||
data["lora"]["power"] = conf->lora.power;
|
||||
data["lora"]["spreading_factor"] = conf->lora.spreadingFactor;
|
||||
data["lora"]["signal_bandwidth"] = conf->lora.signalBandwidth;
|
||||
data["lora"]["coding_rate4"] = conf->lora.codingRate4;
|
||||
data["display"]["always_on"] = conf->display.alwaysOn;
|
||||
data["display"]["timeout"] = conf->display.timeout;
|
||||
data["display"]["overwrite_pin"] = conf->display.overwritePin;
|
||||
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) {
|
||||
JsonObject v = users.createNestedObject();
|
||||
v["name"] = u.name;
|
||||
v["password"] = u.password;
|
||||
}
|
||||
data["ntp_server"] = conf->ntpServer;
|
||||
|
||||
data["board"] = conf->board;
|
||||
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)
|
||||
{}
|
||||
}
|
||||
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;
|
||||
/*if(KEY_BUILTIN != 0 && Config->display.overwritePin == 0)
|
||||
{
|
||||
Config->display.overwritePin = KEY_BUILTIN;
|
||||
}*/
|
||||
logPrintlnI("Configuration loaded!");
|
||||
return config;
|
||||
}
|
||||
|
|
|
@ -1,110 +1,108 @@
|
|||
#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
|
||||
{
|
||||
public:
|
||||
class AP
|
||||
{
|
||||
public:
|
||||
String SSID;
|
||||
String password;
|
||||
};
|
||||
class Wifi {
|
||||
public:
|
||||
class AP {
|
||||
public:
|
||||
String SSID;
|
||||
String password;
|
||||
};
|
||||
|
||||
Wifi() {}
|
||||
Wifi() {
|
||||
}
|
||||
|
||||
std::list<AP> APs;
|
||||
};
|
||||
std::list<AP> APs;
|
||||
};
|
||||
|
||||
class Beacon
|
||||
{
|
||||
public:
|
||||
Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), timeout(15) {}
|
||||
class Beacon {
|
||||
public:
|
||||
Beacon() : message("LoRa iGATE & Digi, Info: github.com/peterus/LoRa_APRS_iGate"), positionLatitude(0.0), positionLongitude(0.0), timeout(15) {
|
||||
}
|
||||
|
||||
String message;
|
||||
double positionLatitude;
|
||||
double positionLongitude;
|
||||
int timeout;
|
||||
};
|
||||
String message;
|
||||
double positionLatitude;
|
||||
double positionLongitude;
|
||||
int timeout;
|
||||
};
|
||||
|
||||
class APRS_IS
|
||||
{
|
||||
public:
|
||||
APRS_IS() : server("euro.aprs2.net"), port(14580) {}
|
||||
class APRS_IS {
|
||||
public:
|
||||
APRS_IS() : server("euro.aprs2.net"), port(14580) {
|
||||
}
|
||||
|
||||
String passcode;
|
||||
String server;
|
||||
int port;
|
||||
};
|
||||
String passcode;
|
||||
String server;
|
||||
int port;
|
||||
};
|
||||
|
||||
class LoRa
|
||||
{
|
||||
public:
|
||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {}
|
||||
class LoRa {
|
||||
public:
|
||||
LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5) {
|
||||
}
|
||||
|
||||
long frequencyRx;
|
||||
long frequencyTx;
|
||||
int power;
|
||||
int spreadingFactor;
|
||||
long signalBandwidth;
|
||||
int codingRate4;
|
||||
};
|
||||
long frequencyRx;
|
||||
long frequencyTx;
|
||||
int power;
|
||||
int spreadingFactor;
|
||||
long signalBandwidth;
|
||||
int codingRate4;
|
||||
};
|
||||
|
||||
class Display
|
||||
{
|
||||
public:
|
||||
Display() : alwaysOn(true), timeout(10), overwritePin(0), turn180(true) {}
|
||||
class Display {
|
||||
public:
|
||||
Display() : alwaysOn(true), timeout(10), overwritePin(0), turn180(true) {
|
||||
}
|
||||
|
||||
bool alwaysOn;
|
||||
int timeout;
|
||||
int overwritePin;
|
||||
bool turn180;
|
||||
};
|
||||
bool alwaysOn;
|
||||
int timeout;
|
||||
int overwritePin;
|
||||
bool turn180;
|
||||
};
|
||||
|
||||
class Ftp
|
||||
{
|
||||
public:
|
||||
class User
|
||||
{
|
||||
public:
|
||||
String name;
|
||||
String password;
|
||||
};
|
||||
class Ftp {
|
||||
public:
|
||||
class User {
|
||||
public:
|
||||
String name;
|
||||
String password;
|
||||
};
|
||||
|
||||
Ftp() : active(false) {}
|
||||
Ftp() : active(false) {
|
||||
}
|
||||
|
||||
bool active;
|
||||
std::list<User> users;
|
||||
};
|
||||
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;
|
||||
Beacon beacon;
|
||||
APRS_IS aprs_is;
|
||||
LoRa lora;
|
||||
Display display;
|
||||
Ftp ftp;
|
||||
String board;
|
||||
String ntpServer;
|
||||
String callsign;
|
||||
Wifi wifi;
|
||||
Beacon beacon;
|
||||
APRS_IS aprs_is;
|
||||
LoRa lora;
|
||||
Display display;
|
||||
Ftp ftp;
|
||||
String board;
|
||||
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