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