diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 66eace0..c8eb972 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -6,14 +6,14 @@ BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t o : 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> &boardConfigs) : _boardConfigs(boardConfigs) { +BoardFinder::BoardFinder(std::list boardConfigs) : _boardConfigs(boardConfigs) { } -std::shared_ptr BoardFinder::searchBoardConfig() { +BoardConfig const *BoardFinder::searchBoardConfig() { logPrintlnI("looking for a board config."); logPrintlnI("searching for OLED..."); - for (std::shared_ptr boardconf : _boardConfigs) { + for (BoardConfig const *boardconf : _boardConfigs) { if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); @@ -31,7 +31,7 @@ std::shared_ptr BoardFinder::searchBoardConfig() { logPrintlnI("could not find OLED, will search for the modem now..."); - for (std::shared_ptr boardconf : _boardConfigs) { + for (BoardConfig const *boardconf : _boardConfigs) { if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); @@ -50,8 +50,8 @@ std::shared_ptr BoardFinder::searchBoardConfig() { return 0; } -std::shared_ptr BoardFinder::getBoardConfig(String name) { - std::_List_iterator> elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](std::shared_ptr conf) { +BoardConfig const *BoardFinder::getBoardConfig(String name) { + std::_List_iterator elem = std::find_if(_boardConfigs.begin(), _boardConfigs.end(), [&](BoardConfig const *conf) { return conf->Name == name; }); if (elem == _boardConfigs.end()) { @@ -60,7 +60,7 @@ std::shared_ptr BoardFinder::getBoardConfig(String name) { return *elem; } -bool BoardFinder::checkOledConfig(std::shared_ptr boardConfig) { +bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) { if (boardConfig->OledReset > 0) { pinMode(boardConfig->OledReset, OUTPUT); digitalWrite(boardConfig->OledReset, HIGH); @@ -80,7 +80,7 @@ bool BoardFinder::checkOledConfig(std::shared_ptr boardConfig) { return false; } -bool BoardFinder::checkModemConfig(std::shared_ptr boardConfig) { +bool BoardFinder::checkModemConfig(BoardConfig const *boardConfig) { pinMode(boardConfig->LoraReset, OUTPUT); digitalWrite(boardConfig->LoraReset, LOW); delay(10); @@ -107,7 +107,7 @@ bool BoardFinder::checkModemConfig(std::shared_ptr boardConfig) { return false; } -bool BoardFinder::checkPowerConfig(std::shared_ptr boardConfig) { +bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) { logPrintlnW("issue with wire"); return false; @@ -128,3 +128,14 @@ bool BoardFinder::checkPowerConfig(std::shared_ptr boardConfig) { logPrintlnD("power chip NOT found"); return false; } + +// clang-format off +BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26); +BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true); +BoardConfig TTGO_T_Beam_V0_7 ("TTGO_T_Beam_V0_7", eTTGO_T_Beam_V0_7, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true); +BoardConfig TTGO_T_Beam_V1_0 ("TTGO_T_Beam_V1_0", eTTGO_T_Beam_V1_0, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, true, true); +BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36); +BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26); +BoardConfig HELTEC_WIFI_LORA_32_V1("HELTEC_WIFI_LORA_32_V1", eHELTEC_WIFI_LORA_32_V1, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26); +BoardConfig HELTEC_WIFI_LORA_32_V2("HELTEC_WIFI_LORA_32_V2", eHELTEC_WIFI_LORA_32_V2, 4, 15, 0x3C, 16, 5, 19, 27, 18, 14, 26); +// clang-format on diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index 04dc8a4..a18f674 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -45,18 +45,27 @@ public: class BoardFinder { public: - explicit BoardFinder(std::list> &boardConfigs); + explicit BoardFinder(std::list boardConfigs); - std::shared_ptr searchBoardConfig(); + BoardConfig const *searchBoardConfig(); - std::shared_ptr getBoardConfig(String name); + BoardConfig const *getBoardConfig(String name); private: - std::list> _boardConfigs; + std::list _boardConfigs; - bool checkOledConfig(std::shared_ptr boardConfig); - bool checkModemConfig(std::shared_ptr boardConfig); - bool checkPowerConfig(std::shared_ptr boardConfig); + bool checkOledConfig(BoardConfig const *boardConfig); + bool checkModemConfig(BoardConfig const *boardConfig); + bool checkPowerConfig(BoardConfig const *boardConfig); }; +extern BoardConfig TTGO_LORA32_V1; +extern BoardConfig TTGO_LORA32_V2; +extern BoardConfig TTGO_T_Beam_V0_7; +extern BoardConfig TTGO_T_Beam_V1_0; +extern BoardConfig ETH_BOARD; +extern BoardConfig TRACKERD; +extern BoardConfig HELTEC_WIFI_LORA_32_V1; +extern BoardConfig HELTEC_WIFI_LORA_32_V2; + #endif diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index e02448e..7d73a04 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -37,24 +37,22 @@ void setup() { logPrintlnI("LoRa APRS iGate by OE5BPA (Peter Buchegger)"); logPrintlnI("Version: " VERSION); - std::list> boardConfigs; - // clang-format off - boardConfigs.push_back(std::shared_ptr(new BoardConfig("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26))); - boardConfigs.push_back(std::shared_ptr(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(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(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(new BoardConfig("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36))); - boardConfigs.push_back(std::shared_ptr(new BoardConfig("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26))); - boardConfigs.push_back(std::shared_ptr(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(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 + std::list boardConfigs; + boardConfigs.push_back(&TTGO_LORA32_V1); + boardConfigs.push_back(&TTGO_LORA32_V2); + boardConfigs.push_back(&TTGO_T_Beam_V0_7); + boardConfigs.push_back(&TTGO_T_Beam_V1_0); + boardConfigs.push_back(Ð_BOARD); + boardConfigs.push_back(&TRACKERD); + boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1); + boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2); ProjectConfigurationManagement confmg; Configuration userConfig; confmg.readConfiguration(userConfig); - BoardFinder finder(boardConfigs); - std::shared_ptr boardConfig = finder.getBoardConfig(userConfig.board); + BoardFinder finder(boardConfigs); + BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board); if (boardConfig == 0) { boardConfig = finder.searchBoardConfig(); if (boardConfig == 0) { @@ -84,7 +82,7 @@ void setup() { powerManagement->deactivateGPS(); } - LoRaSystem.setBoardConfig(boardConfig.get()); + LoRaSystem.setBoardConfig(boardConfig); LoRaSystem.setUserConfig(&userConfig); LoRaSystem.getTaskManager().addTask(std::shared_ptr(new DisplayTask())); LoRaSystem.getTaskManager().addTask(std::shared_ptr(new ModemTask(fromModem)));