diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 8a39ae64..833008e6 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -4,8 +4,8 @@ #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, uint8_t gpsrx, uint8_t gpstx, 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), GpsRx(gpsrx), GpsTx(gpstx), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { +BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, uint8_t button, 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), GpsRx(gpsrx), GpsTx(gpstx), Button(button), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { } BoardFinder::BoardFinder(const std::list &boardConfigs) : _boardConfigs(boardConfigs) { @@ -130,12 +130,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logg } // clang-format off -BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0); -BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, 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, 15, 12, 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, 12, 34, true, true); -BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36, 0, 0); -BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26, 0, 0); -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, 0, 0); -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, 0, 0); +BoardConfig TTGO_LORA32_V1 ("TTGO_LORA32_V1", eTTGO_LORA32_V1, 4, 15, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, 0); +BoardConfig TTGO_LORA32_V2 ("TTGO_LORA32_V2", eTTGO_LORA32_V2, 21, 22, 0x3C, 0, 5, 19, 27, 18, 14, 26, 0, 0, 0, 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, 15, 12, 38, 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, 12, 34, 38, true, true); +BoardConfig ETH_BOARD ("ETH_BOARD", eETH_BOARD, 33, 32, 0x3C, 0, 14, 2, 15, 12, 4, 36, 0, 0, 0); +BoardConfig TRACKERD ("TRACKERD", eTRACKERD, 5, 4, 0x3C, 0, 18, 19, 23, 16, 14, 26, 0, 0, 0); +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, 0, 0, 0); +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, 0, 0, 0); // clang-format on diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index c833fab5..73b5ff9f 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -24,7 +24,7 @@ enum BoardType class BoardConfig { public: - explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, bool needcheckpowerchip = false, bool powercheckstatus = false); + explicit BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, uint8_t gpsrx, uint8_t gpstx, uint8_t button, bool needcheckpowerchip = false, bool powercheckstatus = false); String Name; BoardType Type; @@ -42,6 +42,7 @@ class BoardConfig { uint8_t LoraIRQ; uint8_t GpsRx; uint8_t GpsTx; + uint8_t Button; bool needCheckPowerChip; bool powerCheckStatus; diff --git a/platformio.ini b/platformio.ini index 81ddad3e..a2f5cb3b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,6 +15,7 @@ lib_deps = peterus/ESP-FTP-Server-Lib @ 0.9.5 knolleary/PubSubClient@^2.8 mikalhart/TinyGPSPlus @ 1.0.2 + shaggydog/OneButton @ 1.5.0 check_tool = cppcheck check_flags = cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK --force lib -ilib/TimeLib -ilib/LoRa -ilib/NTPClient diff --git a/src/TaskBeacon.cpp b/src/TaskBeacon.cpp index 50025e24..e356920e 100644 --- a/src/TaskBeacon.cpp +++ b/src/TaskBeacon.cpp @@ -1,5 +1,6 @@ #include +#include #include #include "Task.h" @@ -12,7 +13,21 @@ BeaconTask::BeaconTask(TaskQueue> &toModem, TaskQue BeaconTask::~BeaconTask() { } +OneButton BeaconTask::_userButton; +bool BeaconTask::_send_update; +uint BeaconTask::_instances; + +void BeaconTask::pushButton() { + _send_update = true; +} + bool BeaconTask::setup(System &system) { + if (_instances++ == 0 && system.getBoardConfig()->Button > 0) { + _userButton = OneButton(system.getBoardConfig()->Button, true, true); + _userButton.attachClick(pushButton); + _send_update = false; + } + _useGps = system.getUserConfig()->beacon.use_gps; if (_useGps) { @@ -41,9 +56,12 @@ bool BeaconTask::loop(System &system) { } } + _userButton.tick(); + // check for beacon - if (_beacon_timer.check()) { + if (_beacon_timer.check() || _send_update) { if (sendBeacon(system)) { + _send_update = false; _beacon_timer.start(); } } diff --git a/src/TaskBeacon.h b/src/TaskBeacon.h index 9927dd67..ba0ff22f 100644 --- a/src/TaskBeacon.h +++ b/src/TaskBeacon.h @@ -1,6 +1,7 @@ #ifndef TASK_BEACON_H_ #define TASK_BEACON_H_ +#include #include #include @@ -26,6 +27,11 @@ class BeaconTask : public Task { HardwareSerial _ss; TinyGPSPlus _gps; bool _useGps; + + static uint _instances; + static OneButton _userButton; + static bool _send_update; + static void pushButton(); }; #endif