mirror of
https://github.com/lora-aprs/LoRa_APRS_iGate.git
synced 2025-12-06 07:42:00 +01:00
board finder fixed
This commit is contained in:
parent
c1fc1c5cbf
commit
121f90b59c
|
|
@ -2,6 +2,8 @@
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
#include <power_management.h>
|
#include <power_management.h>
|
||||||
|
|
||||||
|
#define MODULE_NAME "BoardFinder"
|
||||||
|
|
||||||
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)
|
BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus)
|
||||||
: Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) {
|
: 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) {
|
||||||
}
|
}
|
||||||
|
|
@ -9,12 +11,12 @@ BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t o
|
||||||
BoardFinder::BoardFinder(const std::list<BoardConfig const *> &boardConfigs) : _boardConfigs(boardConfigs) {
|
BoardFinder::BoardFinder(const std::list<BoardConfig const *> &boardConfigs) : _boardConfigs(boardConfigs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BoardConfig const *BoardFinder::searchBoardConfig() {
|
BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) {
|
||||||
logPrintlnI("looking for a board config.");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "looking for a board config.");
|
||||||
logPrintlnI("searching for OLED...");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "searching for OLED...");
|
||||||
|
|
||||||
for (BoardConfig const *boardconf : _boardConfigs) {
|
for (BoardConfig const *boardconf : _boardConfigs) {
|
||||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
|
||||||
PowerManagement powerManagement;
|
PowerManagement powerManagement;
|
||||||
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||||
powerManagement.begin(Wire);
|
powerManagement.begin(Wire);
|
||||||
|
|
@ -22,30 +24,28 @@ BoardConfig const *BoardFinder::searchBoardConfig() {
|
||||||
} else if (boardconf->needCheckPowerChip) {
|
} else if (boardconf->needCheckPowerChip) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (checkOledConfig(boardconf)) {
|
if (checkOledConfig(boardconf, logger)) {
|
||||||
logPrintI("found a board config: ");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name);
|
||||||
logPrintlnI(boardconf->Name);
|
|
||||||
return boardconf;
|
return boardconf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logPrintlnI("could not find OLED, will search for the modem now...");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "could not find OLED, will search for the modem now...");
|
||||||
|
|
||||||
for (BoardConfig const *boardconf : _boardConfigs) {
|
for (BoardConfig const *boardconf : _boardConfigs) {
|
||||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
|
||||||
PowerManagement powerManagement;
|
PowerManagement powerManagement;
|
||||||
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||||
powerManagement.begin(Wire);
|
powerManagement.begin(Wire);
|
||||||
powerManagement.activateLoRa();
|
powerManagement.activateLoRa();
|
||||||
}
|
}
|
||||||
if (checkModemConfig(boardconf)) {
|
if (checkModemConfig(boardconf)) {
|
||||||
logPrintI("found a board config: ");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name);
|
||||||
logPrintlnI(boardconf->Name);
|
|
||||||
return boardconf;
|
return boardconf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logPrintlnE("could not find a board config!");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "could not find a board config!");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +60,7 @@ BoardConfig const *BoardFinder::getBoardConfig(String name) {
|
||||||
return *elem;
|
return *elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) {
|
bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger) {
|
||||||
if (boardConfig->OledReset > 0) {
|
if (boardConfig->OledReset > 0) {
|
||||||
pinMode(boardConfig->OledReset, OUTPUT);
|
pinMode(boardConfig->OledReset, OUTPUT);
|
||||||
digitalWrite(boardConfig->OledReset, HIGH);
|
digitalWrite(boardConfig->OledReset, HIGH);
|
||||||
|
|
@ -70,7 +70,7 @@ bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) {
|
||||||
digitalWrite(boardConfig->OledReset, HIGH);
|
digitalWrite(boardConfig->OledReset, HIGH);
|
||||||
}
|
}
|
||||||
if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||||
logPrintlnW("issue with wire");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Wire.beginTransmission(boardConfig->OledAddr);
|
Wire.beginTransmission(boardConfig->OledAddr);
|
||||||
|
|
@ -107,9 +107,9 @@ bool BoardFinder::checkModemConfig(BoardConfig const *boardConfig) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) {
|
bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger) {
|
||||||
if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) {
|
||||||
logPrintlnW("issue with wire");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Wire.beginTransmission(0x34);
|
Wire.beginTransmission(0x34);
|
||||||
|
|
@ -120,12 +120,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) {
|
||||||
int response = Wire.read();
|
int response = Wire.read();
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
|
|
||||||
logPrintlnD(String(response));
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "wire response: %d", response);
|
||||||
if (response == 0x03) {
|
if (response == 0x03) {
|
||||||
logPrintlnD("power chip found!");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logPrintlnD("power chip NOT found");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip NOT found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
enum BoardType
|
enum BoardType
|
||||||
{
|
{
|
||||||
eHELTEC_WIFI_LORA_32_V1,
|
eHELTEC_WIFI_LORA_32_V1,
|
||||||
|
|
@ -47,16 +49,16 @@ class BoardFinder {
|
||||||
public:
|
public:
|
||||||
explicit BoardFinder(const std::list<BoardConfig const *> &boardConfigs);
|
explicit BoardFinder(const std::list<BoardConfig const *> &boardConfigs);
|
||||||
|
|
||||||
BoardConfig const *searchBoardConfig();
|
BoardConfig const *searchBoardConfig(logging::Logger &logger);
|
||||||
|
|
||||||
BoardConfig const *getBoardConfig(String name);
|
BoardConfig const *getBoardConfig(String name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::list<BoardConfig const *> &_boardConfigs;
|
const std::list<BoardConfig const *> &_boardConfigs;
|
||||||
|
|
||||||
bool checkOledConfig(BoardConfig const *boardConfig);
|
bool checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger);
|
||||||
bool checkModemConfig(BoardConfig const *boardConfig);
|
bool checkModemConfig(BoardConfig const *boardConfig);
|
||||||
bool checkPowerConfig(BoardConfig const *boardConfig);
|
bool checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern BoardConfig TTGO_LORA32_V1;
|
extern BoardConfig TTGO_LORA32_V1;
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ void setup() {
|
||||||
BoardFinder finder(boardConfigs);
|
BoardFinder finder(boardConfigs);
|
||||||
BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board);
|
BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board);
|
||||||
if (!boardConfig) {
|
if (!boardConfig) {
|
||||||
boardConfig = finder.searchBoardConfig();
|
boardConfig = finder.searchBoardConfig(LoRaSystem.getLogger());
|
||||||
if (!boardConfig) {
|
if (!boardConfig) {
|
||||||
LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!");
|
LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!");
|
||||||
while (true)
|
while (true)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue