diff options
author | Mike Fiore <mfiore@multitech.com> | 2015-12-10 15:03:53 -0600 |
---|---|---|
committer | Mike Fiore <mfiore@multitech.com> | 2015-12-10 15:03:53 -0600 |
commit | 7cee146eab4f3666980e0688c1d5a96993517bfb (patch) | |
tree | ddd45a15c705fb48ec0a4f086fcf2430edd3c916 | |
parent | a2e7ad209ca28b69e88c96c1def2a63d1581be6c (diff) | |
download | mtdot-box-evb-factory-firmware-7cee146eab4f3666980e0688c1d5a96993517bfb.tar.gz mtdot-box-evb-factory-firmware-7cee146eab4f3666980e0688c1d5a96993517bfb.tar.bz2 mtdot-box-evb-factory-firmware-7cee146eab4f3666980e0688c1d5a96993517bfb.zip |
preserve configured data rate and power when entering and exiting modes
-rw-r--r-- | Mode/Mode.h | 4 | ||||
-rw-r--r-- | Mode/ModeDemo.cpp | 11 | ||||
-rw-r--r-- | Mode/ModeJoin.cpp | 11 | ||||
-rw-r--r-- | Mode/ModeSingle.cpp | 5 | ||||
-rw-r--r-- | Mode/ModeSweep.cpp | 5 |
5 files changed, 32 insertions, 4 deletions
diff --git a/Mode/Mode.h b/Mode/Mode.h index d647b88..e552732 100644 --- a/Mode/Mode.h +++ b/Mode/Mode.h @@ -71,7 +71,7 @@ class Mode { uint8_t _band; uint8_t _sub_band; uint8_t _data_rate; - uint8_t _power; + uint32_t _power; uint32_t _next_tx; ButtonHandler::ButtonEvent _be; LoRaHandler::LoRaStatus _ls; @@ -79,6 +79,8 @@ class Mode { uint8_t _state; bool _send_data; bool _gps_available; + uint8_t _initial_data_rate; + uint8_t _initial_power; }; #endif diff --git a/Mode/ModeDemo.cpp b/Mode/ModeDemo.cpp index f9ea69d..3fc7961 100644 --- a/Mode/ModeDemo.cpp +++ b/Mode/ModeDemo.cpp @@ -20,9 +20,13 @@ bool ModeDemo::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); - // set spreading factor and power - _dot->setTxDataRate(mDot::SF_9); - _dot->setTxPower(20); + _initial_data_rate = _dot->getTxDataRate(); + + // use configured data rate and power if possible + if (_band == mDot::FB_915 && _initial_data_rate == mDot::SF_10) { + logInfo("using SF_9 instead of SF_10 - SF_10 max packet size is too small for data"); + _dot->setTxDataRate(mDot::SF_9); + } _state = show_help; displayHelp(); @@ -74,6 +78,7 @@ bool ModeDemo::start() { case ButtonHandler::sw1_hold: _send_timer.stop(); _send_timer.reset(); + _dot->setTxDataRate(_initial_data_rate); return true; } } diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index 18d18bc..681147b 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -16,6 +16,9 @@ bool ModeJoin::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + _data_rate = (_band == mDot::FB_915) ? mDot::SF_10 : mDot::SF_12; _power = 20; _joined = false; @@ -45,10 +48,14 @@ bool ModeJoin::start() { _be = _buttons->getButtonEvent(); switch (_be) { case ButtonHandler::sw1_press: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; case ButtonHandler::sw2_press: break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; } } @@ -61,6 +68,8 @@ bool ModeJoin::start() { logInfo("joined"); _joined = true; osDelay(2000); + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; case LoRaHandler::join_failure: @@ -72,6 +81,8 @@ bool ModeJoin::start() { } } + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return false; } diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp index 98284be..52eb64a 100644 --- a/Mode/ModeSingle.cpp +++ b/Mode/ModeSingle.cpp @@ -23,6 +23,9 @@ bool ModeSingle::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + // see if we're supposed to send the data packet after success // that item is stored in the mDot::StartUpMode config field _send_data = _dot->getStartUpMode(); @@ -118,6 +121,8 @@ bool ModeSingle::start() { } break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; } } diff --git a/Mode/ModeSweep.cpp b/Mode/ModeSweep.cpp index d6da12e..45fdee0 100644 --- a/Mode/ModeSweep.cpp +++ b/Mode/ModeSweep.cpp @@ -24,6 +24,9 @@ bool ModeSweep::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + _initial_data_rate = _dot->getTxDataRate(); + _initial_power = _dot->getTxPower(); + // see if we're supposed to send the data packet after success // that item is stored in the mDot::StartUpMode config field _send_data = _dot->getStartUpMode(); @@ -151,6 +154,8 @@ bool ModeSweep::start() { } break; case ButtonHandler::sw1_hold: + _dot->setTxDataRate(_initial_data_rate); + _dot->setTxPower(_initial_power); return true; } } |