From 4166bbd0ff84397f31d4928c2ebe6d9a57c3694d Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Fri, 20 Nov 2015 10:08:28 -0600 Subject: refactor more common elements into Mode template class --- Mode/Mode.cpp | 12 ++++++++++-- Mode/Mode.h | 17 +++++++++++++++-- Mode/ModeJoin.cpp | 16 +++++++--------- Mode/ModeJoin.h | 13 +------------ Mode/ModeSingle.cpp | 12 ++---------- Mode/ModeSingle.h | 13 ------------- 6 files changed, 35 insertions(+), 48 deletions(-) (limited to 'Mode') diff --git a/Mode/Mode.cpp b/Mode/Mode.cpp index 29b16ca..64a8e53 100644 --- a/Mode/Mode.cpp +++ b/Mode/Mode.cpp @@ -2,11 +2,19 @@ const char* Mode::_file_name = "SurveyData.txt"; -Mode::Mode(DOGS102* lcd, ButtonHandler* buttons) +Mode::Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) : _lcd(lcd), _buttons(buttons), + _dot(dot), + _lora(lora), + _main_id(Thread::gettid()), _index(0), - _main_id(Thread::gettid()) + _band(_dot->getFrequencyBand()), + _sub_band(0), + _data_rate(mDot::SF_7), + _power(2), + _next_tx(0), + _send_data(false) {} Mode::~Mode() {} diff --git a/Mode/Mode.h b/Mode/Mode.h index ac5d839..903d9c8 100644 --- a/Mode/Mode.h +++ b/Mode/Mode.h @@ -3,6 +3,8 @@ #include "DOGS102.h" #include "ButtonHandler.h" +#include "mDot.h" +#include "LoRaHandler.h" #include "GPSPARSER.h" class Mode { @@ -29,7 +31,7 @@ class Mode { uint8_t power; } DataItem; - Mode(DOGS102* lcd, ButtonHandler* buttons); + Mode(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora); ~Mode(); virtual bool start() = 0; @@ -40,9 +42,20 @@ class Mode { DOGS102* _lcd; ButtonHandler* _buttons; - uint32_t _index; + mDot* _dot; + LoRaHandler* _lora; osThreadId _main_id; static const char* _file_name; + uint32_t _index; + uint8_t _band; + uint8_t _sub_band; + uint8_t _data_rate; + uint8_t _power; + uint32_t _next_tx; + ButtonHandler::ButtonEvent _be; + LoRaHandler::LoRaStatus _ls; + uint8_t _state; + bool _send_data; }; #endif diff --git a/Mode/ModeJoin.cpp b/Mode/ModeJoin.cpp index a39643f..e8026b9 100644 --- a/Mode/ModeJoin.cpp +++ b/Mode/ModeJoin.cpp @@ -2,15 +2,9 @@ #include "MTSLog.h" #include "MTSText.h" -ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, uint8_t band) - : Mode(lcd, buttons), - _join(lcd, band), - _dot(dot), - _lora(lora), - _band(band), - _data_rate(band == mDot::FB_915 ? mDot::SF_10 : mDot::SF_12), - _power(20), - _next_tx(0), +ModeJoin::ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) + : Mode(lcd, buttons, dot, lora), + _join(lcd, _band), _joined(false) {} @@ -21,6 +15,9 @@ bool ModeJoin::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); + + _data_rate = (_band == mDot::FB_915) ? mDot::SF_10 : mDot::SF_12; + _power = 20; _joined = false; display(); @@ -33,6 +30,7 @@ bool ModeJoin::start() { _next_tx = _lora->getNextTx(); if (_next_tx) { logInfo("next tx %lu ms", _next_tx); + _join.updateStatus("Waiting..."); _join.updateCountdown(_next_tx / 1000); } else if (! joining) { logInfo("attempting to join"); diff --git a/Mode/ModeJoin.h b/Mode/ModeJoin.h index 6ab6622..af48d94 100644 --- a/Mode/ModeJoin.h +++ b/Mode/ModeJoin.h @@ -3,12 +3,10 @@ #include "Mode.h" #include "LayoutJoin.h" -#include "mDot.h" -#include "LoRaHandler.h" class ModeJoin : public Mode { public: - ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, uint8_t band); + ModeJoin(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora); ~ModeJoin(); bool start(); @@ -17,16 +15,7 @@ class ModeJoin : public Mode { void display(); LayoutJoin _join; - mDot* _dot; - LoRaHandler* _lora; - uint8_t _band; - uint8_t _sub_band; - uint8_t _data_rate; - uint8_t _power; - uint32_t _next_tx; bool _joined; - ButtonHandler::ButtonEvent _be; - LoRaHandler::LoRaStatus _ls; }; #endif diff --git a/Mode/ModeSingle.cpp b/Mode/ModeSingle.cpp index f49f120..75bcdb9 100644 --- a/Mode/ModeSingle.cpp +++ b/Mode/ModeSingle.cpp @@ -2,18 +2,13 @@ #include "MTSLog.h" ModeSingle::ModeSingle(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora) - : Mode(lcd, buttons), + : Mode(lcd, buttons, dot, lora), _help(lcd), _file(lcd), _confirm(lcd), _progress(lcd), _success(lcd), - _failure(lcd), - _dot(dot), - _data_rate(mDot::SF_7), - _power(2), - _lora(lora), - _send_data(false) + _failure(lcd) {} ModeSingle::~ModeSingle() {} @@ -29,7 +24,6 @@ bool ModeSingle::start() { // clear any stale signals osSignalClear(_main_id, buttonSignal | loraSignal); - _band = _dot->getFrequencyBand(); _sub_band = _dot->getFrequencySubBand(); // see if we're supposed to send the data packet after success @@ -205,9 +199,7 @@ bool ModeSingle::start() { logInfo("next tx %lu ms", t); _progress.updateCountdown(t / 1000); } else { - logInfo("ready to transmit"); _progress.display(); - logInfo("countdown removed"); no_channel_ping = false; send_ping = true; } diff --git a/Mode/ModeSingle.h b/Mode/ModeSingle.h index 976c8eb..125e496 100644 --- a/Mode/ModeSingle.h +++ b/Mode/ModeSingle.h @@ -2,8 +2,6 @@ #define __MODESINGLE_H__ #include "Mode.h" -#include "mDot.h" -#include "LoRaHandler.h" #include "LayoutHelp.h" #include "LayoutFile.h" #include "LayoutConfirm.h" @@ -39,17 +37,6 @@ class ModeSingle : public Mode { LayoutSurveyProgress _progress; LayoutSurveySuccess _success; LayoutSurveyFailure _failure; - mDot* _dot; - LoRaHandler* _lora; - uint8_t _band; - uint8_t _sub_band; - uint8_t _data_rate; - uint8_t _power; - uint32_t _next_tx; - ButtonHandler::ButtonEvent _be; - LoRaHandler::LoRaStatus _ls; - uint8_t _state; - bool _send_data; }; #endif -- cgit v1.2.3