kopia lustrzana https://github.com/lora-aprs/LoRa_APRS_iGate
board finder fixed
rodzic
c1fc1c5cbf
commit
121f90b59c
|
@ -2,6 +2,8 @@
|
|||
#include <logger.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)
|
||||
: 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) {
|
||||
}
|
||||
|
||||
BoardConfig const *BoardFinder::searchBoardConfig() {
|
||||
logPrintlnI("looking for a board config.");
|
||||
logPrintlnI("searching for OLED...");
|
||||
BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "looking for a board config.");
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "searching for OLED...");
|
||||
|
||||
for (BoardConfig const *boardconf : _boardConfigs) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
|
||||
PowerManagement powerManagement;
|
||||
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(Wire);
|
||||
|
@ -22,30 +24,28 @@ BoardConfig const *BoardFinder::searchBoardConfig() {
|
|||
} else if (boardconf->needCheckPowerChip) {
|
||||
continue;
|
||||
}
|
||||
if (checkOledConfig(boardconf)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
if (checkOledConfig(boardconf, logger)) {
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name);
|
||||
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) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) {
|
||||
if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) {
|
||||
PowerManagement powerManagement;
|
||||
Wire.begin(boardconf->OledSda, boardconf->OledScl);
|
||||
powerManagement.begin(Wire);
|
||||
powerManagement.activateLoRa();
|
||||
}
|
||||
if (checkModemConfig(boardconf)) {
|
||||
logPrintI("found a board config: ");
|
||||
logPrintlnI(boardconf->Name);
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name);
|
||||
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;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ BoardConfig const *BoardFinder::getBoardConfig(String name) {
|
|||
return *elem;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) {
|
||||
bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger) {
|
||||
if (boardConfig->OledReset > 0) {
|
||||
pinMode(boardConfig->OledReset, OUTPUT);
|
||||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
|
@ -70,7 +70,7 @@ bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) {
|
|||
digitalWrite(boardConfig->OledReset, HIGH);
|
||||
}
|
||||
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;
|
||||
}
|
||||
Wire.beginTransmission(boardConfig->OledAddr);
|
||||
|
@ -107,9 +107,9 @@ bool BoardFinder::checkModemConfig(BoardConfig const *boardConfig) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) {
|
||||
bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger) {
|
||||
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;
|
||||
}
|
||||
Wire.beginTransmission(0x34);
|
||||
|
@ -120,12 +120,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) {
|
|||
int response = Wire.read();
|
||||
Wire.endTransmission();
|
||||
|
||||
logPrintlnD(String(response));
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "wire response: %d", response);
|
||||
if (response == 0x03) {
|
||||
logPrintlnD("power chip found!");
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip found!");
|
||||
return true;
|
||||
}
|
||||
logPrintlnD("power chip NOT found");
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip NOT found");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include <logger.h>
|
||||
|
||||
enum BoardType
|
||||
{
|
||||
eHELTEC_WIFI_LORA_32_V1,
|
||||
|
@ -47,16 +49,16 @@ class BoardFinder {
|
|||
public:
|
||||
explicit BoardFinder(const std::list<BoardConfig const *> &boardConfigs);
|
||||
|
||||
BoardConfig const *searchBoardConfig();
|
||||
BoardConfig const *searchBoardConfig(logging::Logger &logger);
|
||||
|
||||
BoardConfig const *getBoardConfig(String name);
|
||||
|
||||
private:
|
||||
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 checkPowerConfig(BoardConfig const *boardConfig);
|
||||
bool checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger);
|
||||
};
|
||||
|
||||
extern BoardConfig TTGO_LORA32_V1;
|
||||
|
|
|
@ -67,7 +67,7 @@ void setup() {
|
|||
BoardFinder finder(boardConfigs);
|
||||
BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board);
|
||||
if (!boardConfig) {
|
||||
boardConfig = finder.searchBoardConfig();
|
||||
boardConfig = finder.searchBoardConfig(LoRaSystem.getLogger());
|
||||
if (!boardConfig) {
|
||||
LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!");
|
||||
while (true)
|
||||
|
|
Ładowanie…
Reference in New Issue