MultiTech / Mbed OS MTDOT-BOX-EVB-Factory-Firmware

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

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     if (lora::ChannelPlan::IsPlanFixed(_band)) {
00051         writeLabel(_lFsb);
00052     }
00053     writeLabel(_lRate);
00054     writeLabel(_lPower);
00055     writeLabel(_lAttempt);
00056 
00057     displayCancel();
00058     
00059     endUpdate();
00060 }
00061 
00062 void LayoutJoin::updateId(std::string id) {
00063     writeField(_fId, id, true);
00064 }
00065 
00066 void LayoutJoin::updateKey(std::string key) {
00067     writeField(_fKey, key, true);
00068 }
00069 
00070 void LayoutJoin::updateFsb(uint8_t band) {
00071     char buf[8];
00072     size_t size;
00073 
00074     size = snprintf(buf, sizeof(buf), "%u", band);
00075     writeField(_fFsb, buf, size, true);
00076 }
00077 
00078 void LayoutJoin::updateRate(uint8_t rate) {
00079     char buf[8];
00080     size_t size;
00081 
00082     size = snprintf(buf, sizeof(buf), "%u", rate);
00083     writeField(_fRate, buf, size, true);
00084 }
00085 
00086 void LayoutJoin::updatePower(uint32_t power) {
00087     char buf[16];
00088     size_t size;
00089 
00090     size = snprintf(buf, sizeof(buf), "%lu", power);
00091     writeField(_fPower, buf, size, true);
00092 }
00093 
00094 void LayoutJoin::updateAttempt(uint32_t attempt) {
00095     char buf[16];
00096     size_t size;
00097 
00098     size = snprintf(buf, sizeof(buf), "%lu", attempt);
00099     writeField(_fAttempt, buf, size, true);
00100 }
00101 
00102 void LayoutJoin::updateStatus(std::string status) {
00103     writeField(_fStatus, status, true);
00104 }
00105 
00106 void LayoutJoin::updateCountdown(uint32_t seconds) {
00107     char buf[16];
00108     size_t size;
00109 
00110     // make sure the string version is used
00111     writeField(_fCountdownLabel, string("No Free Channel"), true);
00112     size = snprintf(buf, sizeof(buf), "%lu s", seconds);
00113     writeField(_fCountdown, buf, size, true);
00114 }
00115 
00116 void LayoutJoin::displayCancel(bool display) {
00117     std::string str;
00118     if (display)
00119         str = "Cancel";
00120     else
00121         str = string(17, ' ');
00122 
00123     writeField(_fCancel, str, true);
00124 }
00125 
00126 void LayoutJoin::updateJoinFsb(uint8_t band) {
00127     char buf[8];
00128     size_t size;
00129 
00130     size = snprintf(buf, sizeof(buf), "%u", band);
00131     writeField(_fFsb, buf, size, true);
00132     size = snprintf(buf, sizeof(buf), "     %u", band);
00133     writeField(_fCancel, buf, size, true);
00134 }
00135 
00136 void LayoutJoin::displayEditFsb(uint8_t rate, uint32_t power, uint8_t band, string key, string id){    
00137     clear();
00138     startUpdate();
00139 
00140     writeLabel(_lId);
00141     writeLabel(_lKey);
00142     writeLabel(_lFsb);
00143     writeLabel(_lRate);
00144     writeLabel(_lPower);
00145     writeField(_fCountdown, string("Join"), true);
00146     updateId(id);
00147     updateKey(key);
00148     updateJoinFsb(band);
00149     updateRate(rate);
00150     updatePower(power);
00151     
00152     endUpdate();  
00153 }