Skip to content

Commit

Permalink
Merge pull request #174 from toyo/master
Browse files Browse the repository at this point in the history
Push button to send beacon immediately.
  • Loading branch information
peterus authored Mar 27, 2022
2 parents 228171c + 01b0839 commit 133e32e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/BoardFinder/BoardFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BoardConfig const *> &boardConfigs) : _boardConfigs(boardConfigs) {
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/BoardFinder/BoardFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +42,7 @@ class BoardConfig {
uint8_t LoraIRQ;
uint8_t GpsRx;
uint8_t GpsTx;
uint8_t Button;

bool needCheckPowerChip;
bool powerCheckStatus;
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/TaskBeacon.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <logger.h>

#include <OneButton.h>
#include <TimeLib.h>

#include "Task.h"
Expand All @@ -12,7 +13,21 @@ BeaconTask::BeaconTask(TaskQueue<std::shared_ptr<APRSMessage>> &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) {
Expand Down Expand Up @@ -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();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/TaskBeacon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef TASK_BEACON_H_
#define TASK_BEACON_H_

#include <OneButton.h>
#include <TinyGPS++.h>

#include <APRSMessage.h>
Expand All @@ -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

0 comments on commit 133e32e

Please sign in to comment.