Updated to libmDot 1.0.8-1
Dependencies: DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot mbed-rtos mbed
Fork of MTDOT-BOX-EVB-Factory-Firmware by
Layout/LayoutDemoSampling.cpp@1:71125aa00e33, 2016-02-04 (annotated)
- Committer:
- Mike Fiore
- Date:
- Thu Feb 04 12:36:36 2016 -0600
- Revision:
- 1:71125aa00e33
add rest of source - version 2.0.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:71125aa00e33 | 1 | /* Copyright (c) <2016> <MultiTech Systems>, MIT License |
Mike Fiore |
1:71125aa00e33 | 2 | * |
Mike Fiore |
1:71125aa00e33 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Mike Fiore |
1:71125aa00e33 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Mike Fiore |
1:71125aa00e33 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Mike Fiore |
1:71125aa00e33 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Mike Fiore |
1:71125aa00e33 | 7 | * furnished to do so, subject to the following conditions: |
Mike Fiore |
1:71125aa00e33 | 8 | * |
Mike Fiore |
1:71125aa00e33 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Mike Fiore |
1:71125aa00e33 | 10 | * substantial portions of the Software. |
Mike Fiore |
1:71125aa00e33 | 11 | * |
Mike Fiore |
1:71125aa00e33 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Mike Fiore |
1:71125aa00e33 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Mike Fiore |
1:71125aa00e33 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Mike Fiore |
1:71125aa00e33 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Mike Fiore |
1:71125aa00e33 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Mike Fiore |
1:71125aa00e33 | 17 | */ |
Mike Fiore |
1:71125aa00e33 | 18 | |
Mike Fiore |
1:71125aa00e33 | 19 | #include "LayoutDemoSampling.h" |
Mike Fiore |
1:71125aa00e33 | 20 | |
Mike Fiore |
1:71125aa00e33 | 21 | LayoutDemoSampling::LayoutDemoSampling(DOGS102* lcd) |
Mike Fiore |
1:71125aa00e33 | 22 | : Layout(lcd), |
Mike Fiore |
1:71125aa00e33 | 23 | _lAccx(0, 0, "AccX"), |
Mike Fiore |
1:71125aa00e33 | 24 | _lAccy(6, 0, "AccY"), |
Mike Fiore |
1:71125aa00e33 | 25 | _lAccz(12, 0, "AccZ"), |
Mike Fiore |
1:71125aa00e33 | 26 | _lPres(0, 2, "Press="), |
Mike Fiore |
1:71125aa00e33 | 27 | _lAlt(0, 3, "Alt="), |
Mike Fiore |
1:71125aa00e33 | 28 | _lTemp(0, 4, "Temp="), |
Mike Fiore |
1:71125aa00e33 | 29 | _lLight(0, 5, "Light="), |
Mike Fiore |
1:71125aa00e33 | 30 | _fAccx(0, 1, 5), |
Mike Fiore |
1:71125aa00e33 | 31 | _fAccy(6, 1, 5), |
Mike Fiore |
1:71125aa00e33 | 32 | _fAccz(12, 1, 5), |
Mike Fiore |
1:71125aa00e33 | 33 | _fPres(6, 2, 11), |
Mike Fiore |
1:71125aa00e33 | 34 | _fAlt(4, 3, 13), |
Mike Fiore |
1:71125aa00e33 | 35 | _fTemp(5, 4, 12), |
Mike Fiore |
1:71125aa00e33 | 36 | _fLight(6, 5, 11), |
Mike Fiore |
1:71125aa00e33 | 37 | _fInfo(0, 6, 17), |
Mike Fiore |
1:71125aa00e33 | 38 | _fSw1(9, 7, 8), |
Mike Fiore |
1:71125aa00e33 | 39 | _fSw2(0, 7, 8) |
Mike Fiore |
1:71125aa00e33 | 40 | {} |
Mike Fiore |
1:71125aa00e33 | 41 | |
Mike Fiore |
1:71125aa00e33 | 42 | LayoutDemoSampling::~LayoutDemoSampling() {} |
Mike Fiore |
1:71125aa00e33 | 43 | |
Mike Fiore |
1:71125aa00e33 | 44 | void LayoutDemoSampling::display() { |
Mike Fiore |
1:71125aa00e33 | 45 | clear(); |
Mike Fiore |
1:71125aa00e33 | 46 | startUpdate(); |
Mike Fiore |
1:71125aa00e33 | 47 | |
Mike Fiore |
1:71125aa00e33 | 48 | writeLabel(_lAccx); |
Mike Fiore |
1:71125aa00e33 | 49 | writeLabel(_lAccy); |
Mike Fiore |
1:71125aa00e33 | 50 | writeLabel(_lAccz); |
Mike Fiore |
1:71125aa00e33 | 51 | writeLabel(_lPres); |
Mike Fiore |
1:71125aa00e33 | 52 | writeLabel(_lAlt); |
Mike Fiore |
1:71125aa00e33 | 53 | writeLabel(_lTemp); |
Mike Fiore |
1:71125aa00e33 | 54 | writeLabel(_lLight); |
Mike Fiore |
1:71125aa00e33 | 55 | |
Mike Fiore |
1:71125aa00e33 | 56 | endUpdate(); |
Mike Fiore |
1:71125aa00e33 | 57 | } |
Mike Fiore |
1:71125aa00e33 | 58 | |
Mike Fiore |
1:71125aa00e33 | 59 | void LayoutDemoSampling::updateInfo(std::string info) { |
Mike Fiore |
1:71125aa00e33 | 60 | writeField(_fInfo, info, true); |
Mike Fiore |
1:71125aa00e33 | 61 | } |
Mike Fiore |
1:71125aa00e33 | 62 | |
Mike Fiore |
1:71125aa00e33 | 63 | void LayoutDemoSampling::updateSw1(std::string sw1) { |
Mike Fiore |
1:71125aa00e33 | 64 | writeField(_fSw1, sw1, true); |
Mike Fiore |
1:71125aa00e33 | 65 | } |
Mike Fiore |
1:71125aa00e33 | 66 | |
Mike Fiore |
1:71125aa00e33 | 67 | void LayoutDemoSampling::updateSw2(std::string sw2) { |
Mike Fiore |
1:71125aa00e33 | 68 | writeField(_fSw2, sw2, true); |
Mike Fiore |
1:71125aa00e33 | 69 | } |
Mike Fiore |
1:71125aa00e33 | 70 | |
Mike Fiore |
1:71125aa00e33 | 71 | void LayoutDemoSampling::updateCountdown(uint32_t seconds) { |
Mike Fiore |
1:71125aa00e33 | 72 | char buf[32]; |
Mike Fiore |
1:71125aa00e33 | 73 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 74 | std::string s; |
Mike Fiore |
1:71125aa00e33 | 75 | |
Mike Fiore |
1:71125aa00e33 | 76 | // make sure the string version is used |
Mike Fiore |
1:71125aa00e33 | 77 | writeField(_fInfo, string("No Free Channel"), true); |
Mike Fiore |
1:71125aa00e33 | 78 | size = snprintf(buf, sizeof(buf), "%lu s", seconds); |
Mike Fiore |
1:71125aa00e33 | 79 | for (int i = 0; i < _fSw1._maxSize - size; i++) |
Mike Fiore |
1:71125aa00e33 | 80 | s.append(" "); |
Mike Fiore |
1:71125aa00e33 | 81 | s.append(buf, size); |
Mike Fiore |
1:71125aa00e33 | 82 | writeField(_fSw1, s, true); |
Mike Fiore |
1:71125aa00e33 | 83 | } |
Mike Fiore |
1:71125aa00e33 | 84 | |
Mike Fiore |
1:71125aa00e33 | 85 | void LayoutDemoSampling::updateInterval(uint32_t seconds) { |
Mike Fiore |
1:71125aa00e33 | 86 | char buf[32]; |
Mike Fiore |
1:71125aa00e33 | 87 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 88 | |
Mike Fiore |
1:71125aa00e33 | 89 | if (seconds < 60) |
Mike Fiore |
1:71125aa00e33 | 90 | size = snprintf(buf, sizeof(buf), "Interval %lu s", seconds); |
Mike Fiore |
1:71125aa00e33 | 91 | else if (seconds < 60 * 60) |
Mike Fiore |
1:71125aa00e33 | 92 | size = snprintf(buf, sizeof(buf), "Interval %lu min", seconds / 60); |
Mike Fiore |
1:71125aa00e33 | 93 | else |
Mike Fiore |
1:71125aa00e33 | 94 | size = snprintf(buf, sizeof(buf), "Interval %lu hr", seconds / (60 * 60)); |
Mike Fiore |
1:71125aa00e33 | 95 | |
Mike Fiore |
1:71125aa00e33 | 96 | writeField(_fInfo, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 97 | } |
Mike Fiore |
1:71125aa00e33 | 98 | |
Mike Fiore |
1:71125aa00e33 | 99 | void LayoutDemoSampling::updateAccelerationX(int16_t x) { |
Mike Fiore |
1:71125aa00e33 | 100 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 101 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 102 | float fx = (float)x; |
Mike Fiore |
1:71125aa00e33 | 103 | fx /= 1024; |
Mike Fiore |
1:71125aa00e33 | 104 | // We can only display 5 characters. |
Mike Fiore |
1:71125aa00e33 | 105 | // For numbers < -1, we display -#.#g. For example -1.3g |
Mike Fiore |
1:71125aa00e33 | 106 | if(fx < -1){ |
Mike Fiore |
1:71125aa00e33 | 107 | size = snprintf(buf, sizeof(buf), "%4.1fg", fx); |
Mike Fiore |
1:71125aa00e33 | 108 | } |
Mike Fiore |
1:71125aa00e33 | 109 | // For numbers > -1 and < 0, we display -.##g. For example -.13g |
Mike Fiore |
1:71125aa00e33 | 110 | else if(fx < 0){ |
Mike Fiore |
1:71125aa00e33 | 111 | size = snprintf(buf, sizeof(buf), "%4.2fg", fx); |
Mike Fiore |
1:71125aa00e33 | 112 | for(uint8_t i = 1; i < 5; i++ ){ |
Mike Fiore |
1:71125aa00e33 | 113 | buf[i] = buf[i+1]; |
Mike Fiore |
1:71125aa00e33 | 114 | } |
Mike Fiore |
1:71125aa00e33 | 115 | } |
Mike Fiore |
1:71125aa00e33 | 116 | // For numbers > 0, we display #.##g. For example 0.13g. |
Mike Fiore |
1:71125aa00e33 | 117 | else{ |
Mike Fiore |
1:71125aa00e33 | 118 | size = snprintf(buf, sizeof(buf), "%4.2fg", fx); |
Mike Fiore |
1:71125aa00e33 | 119 | } |
Mike Fiore |
1:71125aa00e33 | 120 | writeField(_fAccx, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 121 | } |
Mike Fiore |
1:71125aa00e33 | 122 | |
Mike Fiore |
1:71125aa00e33 | 123 | void LayoutDemoSampling::updateAccelerationY(int16_t y) { |
Mike Fiore |
1:71125aa00e33 | 124 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 125 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 126 | float fy = (float)y; |
Mike Fiore |
1:71125aa00e33 | 127 | fy /= 1024; |
Mike Fiore |
1:71125aa00e33 | 128 | if(fy < -1){ |
Mike Fiore |
1:71125aa00e33 | 129 | size = snprintf(buf, sizeof(buf), "%4.1fg", fy); |
Mike Fiore |
1:71125aa00e33 | 130 | } |
Mike Fiore |
1:71125aa00e33 | 131 | else if(fy < 0){ |
Mike Fiore |
1:71125aa00e33 | 132 | size = snprintf(buf, sizeof(buf), "%4.2fg", fy); |
Mike Fiore |
1:71125aa00e33 | 133 | for(uint8_t i = 1; i < 5; i++ ){ |
Mike Fiore |
1:71125aa00e33 | 134 | buf[i] = buf[i+1]; |
Mike Fiore |
1:71125aa00e33 | 135 | } |
Mike Fiore |
1:71125aa00e33 | 136 | } |
Mike Fiore |
1:71125aa00e33 | 137 | else{ |
Mike Fiore |
1:71125aa00e33 | 138 | size = snprintf(buf, sizeof(buf), "%4.2fg", fy); |
Mike Fiore |
1:71125aa00e33 | 139 | } |
Mike Fiore |
1:71125aa00e33 | 140 | writeField(_fAccy, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 141 | } |
Mike Fiore |
1:71125aa00e33 | 142 | |
Mike Fiore |
1:71125aa00e33 | 143 | void LayoutDemoSampling::updateAccelerationZ(int16_t z) { |
Mike Fiore |
1:71125aa00e33 | 144 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 145 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 146 | float fz = (float)z; |
Mike Fiore |
1:71125aa00e33 | 147 | fz /= 1024; |
Mike Fiore |
1:71125aa00e33 | 148 | if(fz < -1){ |
Mike Fiore |
1:71125aa00e33 | 149 | size = snprintf(buf, sizeof(buf), "%1.1fg", fz); |
Mike Fiore |
1:71125aa00e33 | 150 | } |
Mike Fiore |
1:71125aa00e33 | 151 | else if(fz < 0){ |
Mike Fiore |
1:71125aa00e33 | 152 | size = snprintf(buf, sizeof(buf), "%4.2fg", fz); |
Mike Fiore |
1:71125aa00e33 | 153 | for(uint8_t i = 1; i < 5; i++ ){ |
Mike Fiore |
1:71125aa00e33 | 154 | buf[i] = buf[i+1]; |
Mike Fiore |
1:71125aa00e33 | 155 | } |
Mike Fiore |
1:71125aa00e33 | 156 | } |
Mike Fiore |
1:71125aa00e33 | 157 | else{ |
Mike Fiore |
1:71125aa00e33 | 158 | size = snprintf(buf, sizeof(buf), "%1.2fg", fz); |
Mike Fiore |
1:71125aa00e33 | 159 | } |
Mike Fiore |
1:71125aa00e33 | 160 | writeField(_fAccz, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 161 | } |
Mike Fiore |
1:71125aa00e33 | 162 | |
Mike Fiore |
1:71125aa00e33 | 163 | void LayoutDemoSampling::updatePressure(float pressure) { |
Mike Fiore |
1:71125aa00e33 | 164 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 165 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 166 | size = snprintf(buf, sizeof(buf), "%3.2f kPa", pressure/1000); |
Mike Fiore |
1:71125aa00e33 | 167 | writeField(_fPres, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 168 | } |
Mike Fiore |
1:71125aa00e33 | 169 | |
Mike Fiore |
1:71125aa00e33 | 170 | void LayoutDemoSampling::updateAltitude(float altitude) { |
Mike Fiore |
1:71125aa00e33 | 171 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 172 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 173 | size = snprintf(buf, sizeof(buf), "%5.2f m", altitude); |
Mike Fiore |
1:71125aa00e33 | 174 | writeField(_fAlt, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 175 | } |
Mike Fiore |
1:71125aa00e33 | 176 | |
Mike Fiore |
1:71125aa00e33 | 177 | void LayoutDemoSampling::updateTemperature(float temperature) { |
Mike Fiore |
1:71125aa00e33 | 178 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 179 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 180 | size = snprintf(buf, sizeof(buf), "%3.2f C", temperature); |
Mike Fiore |
1:71125aa00e33 | 181 | writeField(_fTemp, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 182 | } |
Mike Fiore |
1:71125aa00e33 | 183 | |
Mike Fiore |
1:71125aa00e33 | 184 | void LayoutDemoSampling::updateLight(float light) { |
Mike Fiore |
1:71125aa00e33 | 185 | char buf[16]; |
Mike Fiore |
1:71125aa00e33 | 186 | size_t size; |
Mike Fiore |
1:71125aa00e33 | 187 | size = snprintf(buf, sizeof(buf), "%4.2f lx", light); |
Mike Fiore |
1:71125aa00e33 | 188 | writeField(_fLight, buf, size, true); |
Mike Fiore |
1:71125aa00e33 | 189 | } |