Custom Channel Plan version of MTDOT Box firmware

Dependencies:   DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot-Custom mDot_Channel_Plans

Fork of MTDOT-BOX-EVB-Factory-Firmware by MultiTech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LayoutJoin.cpp Source File

LayoutJoin.cpp

00001 /* /* Copyright (c) <2016> <MultiTech Systems>, MIT License
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
00004  * and associated documentation files (the "Software"), to deal in the Software without restriction, 
00005  * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
00006  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
00007  * furnished to do so, subject to the following conditions:
00008  *
00009  * The above copyright notice and this permission notice shall be included in all copies or 
00010  * substantial portions of the Software.
00011  *
00012  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
00013  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
00014  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
00015  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
00016  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017  */
00018 
00019 #include "LayoutJoin.h"
00020 
00021 LayoutJoin::LayoutJoin(DOGS102* lcd, uint8_t band)
00022   : Layout(lcd),
00023     _lId(0, 1, "NI="),
00024     _lKey(0, 2, "NK="),
00025     _lFsb(0, 3, "FSB="),
00026     _lRate(0, 5, "DR="),
00027     _lPower(6, 5, "P="),
00028     _lAttempt(11, 5, "A="),
00029     _fStatus(0, 0, 17),
00030     _fId(3, 1, 14),
00031     _fKey(3, 2, 14),
00032     _fFsb(4, 3, 2),
00033     _fRate(3, 5, 2),
00034     _fPower(8, 5, 2),
00035     _fAttempt(13, 5, 4),
00036     _fCountdown(0, 7, 9),
00037     _fCountdownLabel(0, 6, 17),
00038     _fCancel(11, 7, 6),
00039     _band(band)
00040 {}
00041 
00042 LayoutJoin::~LayoutJoin() {}
00043 
00044 void LayoutJoin::display() {
00045     clear();
00046     startUpdate();
00047 
00048     writeLabel(_lId);
00049     writeLabel(_lKey);
00050     writeLabel(_lFsb);
00051     writeLabel(_lRate);
00052     writeLabel(_lPower);
00053     writeLabel(_lAttempt);
00054 
00055     displayCancel();
00056     
00057     endUpdate();
00058 }
00059 
00060 void LayoutJoin::updateId(std::string id) {
00061     writeField(_fId, id, true);
00062 }
00063 
00064 void LayoutJoin::updateKey(std::string key) {
00065     writeField(_fKey, key, true);
00066 }
00067 
00068 void LayoutJoin::updateFsb(uint8_t band) {
00069     char buf[8];
00070     size_t size;
00071 
00072     size = snprintf(buf, sizeof(buf), "%u", band);
00073     writeField(_fFsb, buf, size, true);
00074 }
00075 
00076 void LayoutJoin::updateRate(uint8_t rate) {
00077     char buf[8];
00078     size_t size;
00079 
00080     size = snprintf(buf, sizeof(buf), "%u", rate);
00081     writeField(_fRate, buf, size, true);
00082 }
00083 
00084 void LayoutJoin::updatePower(uint32_t power) {
00085     char buf[16];
00086     size_t size;
00087 
00088     size = snprintf(buf, sizeof(buf), "%lu", power);
00089     writeField(_fPower, buf, size, true);
00090 }
00091 
00092 void LayoutJoin::updateAttempt(uint32_t attempt) {
00093     char buf[16];
00094     size_t size;
00095 
00096     size = snprintf(buf, sizeof(buf), "%lu", attempt);
00097     writeField(_fAttempt, buf, size, true);
00098 }
00099 
00100 void LayoutJoin::updateStatus(std::string status) {
00101     writeField(_fStatus, status, true);
00102 }
00103 
00104 void LayoutJoin::updateCountdown(uint32_t seconds) {
00105     char buf[16];
00106     size_t size;
00107 
00108     // make sure the string version is used
00109     writeField(_fCountdownLabel, string("No Free Channel"), true);
00110     size = snprintf(buf, sizeof(buf), "%lu s", seconds);
00111     writeField(_fCountdown, buf, size, true);
00112 }
00113 
00114 void LayoutJoin::displayCancel(bool display) {
00115     std::string str;
00116     if (display)
00117         str = "Cancel";
00118     else
00119         str = string(17, ' ');
00120 
00121     writeField(_fCancel, str, true);
00122 }
00123 
00124 void LayoutJoin::updateJoinFsb(uint8_t band) {
00125     char buf[8];
00126     size_t size;
00127 
00128     size = snprintf(buf, sizeof(buf), "%u", band);
00129     writeField(_fFsb, buf, size, true);
00130     size = snprintf(buf, sizeof(buf), "     %u", band);
00131     writeField(_fCancel, buf, size, true);
00132 }
00133 
00134 void LayoutJoin::displayEditFsb(uint8_t rate, uint32_t power, uint8_t band, string key, string id){    
00135     clear();
00136     startUpdate();
00137 
00138     writeLabel(_lId);
00139     writeLabel(_lKey);
00140     writeLabel(_lFsb);
00141     writeLabel(_lRate);
00142     writeLabel(_lPower);
00143     writeField(_fCountdown, string("Join"), true);
00144     updateId(id);
00145     updateKey(key);
00146     updateJoinFsb(band);
00147     updateRate(rate);
00148     updatePower(power);
00149     
00150     endUpdate();  
00151 }