diff options
Diffstat (limited to 'Mode/ModeJoin.cpp')
-rw-r--r-- | Mode/ModeJoin.cpp | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index 5af4dcd..a39643f 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -17,42 +17,31 @@ ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* ModeJoin::~ModeJoin() {} bool ModeJoin::start() { + bool joining = false; + // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); _joined = false; - _index = 1; - _join.display(); - _join.updateStatus("Joining..."); - if (_dot->getJoinMode() == mDot::MANUAL) { - _join.updateId(mts::Text::bin2hexString(_dot->getNetworkId())); - _join.updateKey(mts::Text::bin2hexString(_dot->getNetworkKey())); - } else { - _join.updateId(_dot->getNetworkName()); - _join.updateKey(_dot->getNetworkPassphrase()); - } - if (_band == mDot::FB_915) { - _sub_band = _dot->getFrequencySubBand(); - _join.updateFsb(_sub_band); - } - // mDot::DataRateStr returns format SF_XX - we only want to display the XX part - _join.updateRate(_dot->DataRateStr(_data_rate).substr(3)); - _join.updatePower(_power); + display(); _lora->setDataRate(_data_rate); _lora->setPower(_power); + _lora->resetJoinAttempts(); while (! _joined) { _next_tx = _lora->getNextTx(); if (_next_tx) { + logInfo("next tx %lu ms", _next_tx); _join.updateCountdown(_next_tx / 1000); - } else { - _join.updateStatus("Joining..."); - if (_lora->join()) - _join.updateAttempt(_index++); + } else if (! joining) { + logInfo("attempting to join"); + joining = true; + display(); + _lora->join(); } - osEvent e = Thread::signal_wait(0, 500); + osEvent e = Thread::signal_wait(0, 250); if (e.status == osEventSignal) { if (e.value.signals & buttonSignal) { _be = _buttons->getButtonEvent(); @@ -78,6 +67,7 @@ bool ModeJoin::start() { case LoRaHandler::join_failure: logInfo("failed to join"); + joining = false; break; } } @@ -86,3 +76,20 @@ bool ModeJoin::start() { return false; } + +void ModeJoin::display() { + _join.display(); + _join.updateStatus("Joining..."); + if (_dot->getJoinMode() == mDot::MANUAL) { + _join.updateId(mts::Text::bin2hexString(_dot->getNetworkId())); + _join.updateKey(mts::Text::bin2hexString(_dot->getNetworkKey())); + } else { + _join.updateId(_dot->getNetworkName()); + _join.updateKey(_dot->getNetworkPassphrase()); + } + // mDot::DataRateStr returns format SF_XX - we only want to display the XX part + _join.updateRate(_dot->DataRateStr(_data_rate).substr(3)); + _join.updatePower(_power); + _join.updateAttempt(_lora->getJoinAttempts()); +} + |