From ba7827cbda3cc77ac28dc933978f3d97a0c05369 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:51:00 -0500 Subject: Upload new file --- Mode/ModeData.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Mode/ModeData.h (limited to 'Mode') diff --git a/Mode/ModeData.h b/Mode/ModeData.h new file mode 100644 index 0000000..2fe5239 --- /dev/null +++ b/Mode/ModeData.h @@ -0,0 +1,69 @@ +/* Copyright (c) <2016> , MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef __MODEDATA_H__ +#define __MODEDATA_H__ + +#include "Mode.h" +#include "LayoutData.h" +#include "LayoutHelp.h" +//max size of line plus one +#define ONELINEMAX 93 + + +class ModeData : public Mode +{ + +public: + ModeData(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); + ~ModeData(); + + bool start(); + + +private: + + + + bool _last; + string _str; + + int32_t _pos, _buf_size, _indexUpdate, _prev; + uint32_t _index; + + char _buf[ONELINEMAX]; + + mDot::mdot_file _file; + + LayoutData _data; + LayoutHelp _help; + LayoutData::singleLine _line; + + bool checkFile(); + bool readFile(); + string parse(); + void getLine(); + void displayData(); + void forward(); + void back(); + void configSw(); + + +}; + +#endif \ No newline at end of file -- cgit v1.2.3 From eae9590d687a9a748d8a47eee28e0ccec5f85ede Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Mon, 8 Aug 2016 12:53:01 -0500 Subject: Upload new file --- Mode/ModeData.cpp | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 Mode/ModeData.cpp (limited to 'Mode') diff --git a/Mode/ModeData.cpp b/Mode/ModeData.cpp new file mode 100644 index 0000000..53b0bc5 --- /dev/null +++ b/Mode/ModeData.cpp @@ -0,0 +1,187 @@ +/* Copyright (c) <2016> , MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "ModeData.h" +#include "MTSText.h" + +ModeData::ModeData(DOGS102* lcd, ButtonHandler* _buttons, mDot* _dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) + :Mode(lcd,_buttons,_dot,lora,gps,sensors), + _data(lcd), + _help(lcd), + _buf_size(ONELINEMAX) +{} + +ModeData::~ModeData() {} + +bool ModeData::checkFile() +{ + bool exists = false; + //get all files and see if file exists + vector files = _dot->listUserFiles(); + for (vector::iterator it = files.begin(); it != files.end(); it++) { + if (strcmp(file_name,it->name)==0) { + exists = true; + break; + } + } + //if file doesnt exist exit to main menu + if(!exists) { + _data.noData(); + osDelay(4000); + return true; + } + _file = _dot->openUserFile(file_name, mDot::FM_RDONLY); + //if nothing is in file exit to main menu + if (_file.fd < 0) { + _data.errorData(); + osDelay(4000); + _dot->closeUserFile(_file); + return true; + } + return false; +} + +bool ModeData::start() +{ + if(checkFile()) + return true; + _help.display(); + osDelay(3000); + readFile(); +} + +void ModeData::displayData() +{ + std::vector data = mts::Text::split(_str, ','); + _line.id = data.at(0); + _line.status = data.at(1); + _line.lock = data.at(2); + _line.lat = data.at(3); + _line.lng = data.at(4); + _line.alt = data.at(5); + _line.time = data.at(6); + _line.gateways = data.at(7); + _line.margin = data.at(8); + _line.rssiD = data.at(9); + _line.snrD = data.at(10); + _line.dataRate = data.at(11); + _line.power = data.at(12); + _data.updateAll(_line); +} + +//get the current line out of the buffer into str +void ModeData::getLine() +{ + _prev = 0; + _indexUpdate = 0; + _str = ""; + _dot->readUserFile(_file, (void*)_buf, _buf_size); + //only gets called when going back + if(_last) { + //-3 puts it back to one before new line + _indexUpdate = _buf_size - 3; + //check from back of buffer for new line + while(_buf[_indexUpdate]!='\n'&&_indexUpdate>=0) _indexUpdate--; + _indexUpdate++; + } + //go from indexUpdate to new line to ge the line + //prev keeps track of how long line read was + while(_buf[_indexUpdate]!='\n') { + _str += _buf[_indexUpdate]; + _indexUpdate++; + _prev++; + } + //push index past newline + _index += _indexUpdate+1; + displayData(); +} + +void ModeData::back() +{ + if(_index>=(_buf_size+_prev)) { + _index -= (_prev+_buf_size); + } else { + //special case for beginning of file + if(_index>0) _buf_size = _index-1; + _buf_size -= _prev; + _index = 0; + } + _last = true; + _dot->seekUserFile(_file,_index, SEEK_SET); + getLine(); +} + +void ModeData::forward() +{ + _last = false; + if(_index<_file.size) { + _buf_size = ONELINEMAX; + _dot->seekUserFile(_file, _index, SEEK_SET); + getLine(); + } +} + +//update switch labels +void ModeData::configSw() +{ + if(_index-(_prev+1)<=0) _data.updateSw2(""); + else _data.updateSw2("Back"); + if(_index<_file.size) _data.updateSw1("Next"); + else _data.updateSw1(""); +} + + +bool ModeData::readFile() +{ + _index = 0; + _last = false; + _prev = 0; + _indexUpdate = 0; + //called to start on page one + forward(); + configSw(); + ButtonHandler::ButtonEvent be; + + while (true) { + + be = _buttons->getButtonEvent(); + + switch(be) { + case ButtonHandler::sw1_press: + if(_index!=_file.size) { + forward(); + configSw();} + break; + + case ButtonHandler::sw2_press: + if(_index-(_prev+1)>0) { + back(); + configSw();} + break; + + case ButtonHandler::sw1_hold: + _dot->closeUserFile(_file); + return true; + + default: + break; + } + } +} + + -- cgit v1.2.3 From d4fe469db33a60931015e721ec851bf7f7856f37 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:04:35 -0500 Subject: Replace ModeData.cpp --- Mode/ModeData.cpp | 74 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'Mode') diff --git a/Mode/ModeData.cpp b/Mode/ModeData.cpp index 53b0bc5..401277e 100644 --- a/Mode/ModeData.cpp +++ b/Mode/ModeData.cpp @@ -18,6 +18,7 @@ #include "ModeData.h" #include "MTSText.h" +#define ONELINEMAX 93 ModeData::ModeData(DOGS102* lcd, ButtonHandler* _buttons, mDot* _dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors) :Mode(lcd,_buttons,_dot,lora,gps,sensors), @@ -28,8 +29,7 @@ ModeData::ModeData(DOGS102* lcd, ButtonHandler* _buttons, mDot* _dot, LoRaHandle ModeData::~ModeData() {} -bool ModeData::checkFile() -{ +bool ModeData::checkFile(){ bool exists = false; //get all files and see if file exists vector files = _dot->listUserFiles(); @@ -42,22 +42,21 @@ bool ModeData::checkFile() //if file doesnt exist exit to main menu if(!exists) { _data.noData(); - osDelay(4000); + osDelay(3000); return true; } _file = _dot->openUserFile(file_name, mDot::FM_RDONLY); //if nothing is in file exit to main menu if (_file.fd < 0) { _data.errorData(); - osDelay(4000); + osDelay(3000); _dot->closeUserFile(_file); return true; } return false; } -bool ModeData::start() -{ +bool ModeData::start(){ if(checkFile()) return true; _help.display(); @@ -65,8 +64,7 @@ bool ModeData::start() readFile(); } -void ModeData::displayData() -{ +void ModeData::displayData(){ std::vector data = mts::Text::split(_str, ','); _line.id = data.at(0); _line.status = data.at(1); @@ -85,8 +83,7 @@ void ModeData::displayData() } //get the current line out of the buffer into str -void ModeData::getLine() -{ +void ModeData::getLine(){ _prev = 0; _indexUpdate = 0; _str = ""; @@ -96,7 +93,9 @@ void ModeData::getLine() //-3 puts it back to one before new line _indexUpdate = _buf_size - 3; //check from back of buffer for new line - while(_buf[_indexUpdate]!='\n'&&_indexUpdate>=0) _indexUpdate--; + while(_buf[_indexUpdate] != '\n' && _indexUpdate >= 0){ + _indexUpdate--; + } _indexUpdate++; } //go from indexUpdate to new line to ge the line @@ -107,29 +106,29 @@ void ModeData::getLine() _prev++; } //push index past newline - _index += _indexUpdate+1; + _index += _indexUpdate + 1; displayData(); } -void ModeData::back() -{ - if(_index>=(_buf_size+_prev)) { - _index -= (_prev+_buf_size); +void ModeData::back(){ + if(_index >= (_buf_size + _prev)) { + _index -= (_prev + _buf_size); } else { //special case for beginning of file - if(_index>0) _buf_size = _index-1; + if(_index > 0){ + _buf_size = _index-1; + } _buf_size -= _prev; _index = 0; } _last = true; - _dot->seekUserFile(_file,_index, SEEK_SET); + _dot->seekUserFile(_file, _index, SEEK_SET); getLine(); } -void ModeData::forward() -{ +void ModeData::forward(){ _last = false; - if(_index<_file.size) { + if(_index < _file.size) { _buf_size = ONELINEMAX; _dot->seekUserFile(_file, _index, SEEK_SET); getLine(); @@ -137,17 +136,20 @@ void ModeData::forward() } //update switch labels -void ModeData::configSw() -{ - if(_index-(_prev+1)<=0) _data.updateSw2(""); - else _data.updateSw2("Back"); - if(_index<_file.size) _data.updateSw1("Next"); - else _data.updateSw1(""); +void ModeData::configSw(){ + if(_index - (_prev+1) <= 0){ + _data.updateSw2(""); + } else { + _data.updateSw2("Back"); + } + if(_index<_file.size){ + _data.updateSw1("Next"); + } else { + _data.updateSw1(""); + } } - -bool ModeData::readFile() -{ +bool ModeData::readFile(){ _index = 0; _last = false; _prev = 0; @@ -156,22 +158,21 @@ bool ModeData::readFile() forward(); configSw(); ButtonHandler::ButtonEvent be; - while (true) { - be = _buttons->getButtonEvent(); - switch(be) { case ButtonHandler::sw1_press: if(_index!=_file.size) { forward(); - configSw();} + configSw(); + } break; case ButtonHandler::sw2_press: - if(_index-(_prev+1)>0) { + if(_index - (_prev+1) > 0) { back(); - configSw();} + configSw(); + } break; case ButtonHandler::sw1_hold: @@ -184,4 +185,3 @@ bool ModeData::readFile() } } - -- cgit v1.2.3 From 5d9f1f7f1863c7c92d7aa29c37ced672b2946118 Mon Sep 17 00:00:00 2001 From: Ryan Klaassen Date: Wed, 10 Aug 2016 13:04:52 -0500 Subject: Replace ModeData.h --- Mode/ModeData.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'Mode') diff --git a/Mode/ModeData.h b/Mode/ModeData.h index 2fe5239..f9da741 100644 --- a/Mode/ModeData.h +++ b/Mode/ModeData.h @@ -22,12 +22,8 @@ #include "Mode.h" #include "LayoutData.h" #include "LayoutHelp.h" -//max size of line plus one -#define ONELINEMAX 93 - -class ModeData : public Mode -{ +class ModeData : public Mode{ public: ModeData(DOGS102* lcd, ButtonHandler* buttons, mDot* dot, LoRaHandler* lora, GPSPARSER* gps, SensorHandler* sensors); @@ -35,18 +31,14 @@ public: bool start(); - private: - - - bool _last; string _str; int32_t _pos, _buf_size, _indexUpdate, _prev; uint32_t _index; - char _buf[ONELINEMAX]; + char _buf[93]; mDot::mdot_file _file; @@ -62,8 +54,5 @@ private: void forward(); void back(); void configSw(); - - }; - #endif \ No newline at end of file -- cgit v1.2.3