DS18B20 uSD data logger with MAX32630FTHR
Dependencies: OneWire SDFileSystem max32630fthr mbed
Fork of MAX32630FTHR_iButton_uSD_Logger by
main.cpp@2:9e45f00fd2de, 2017-02-17 (annotated)
- Committer:
- j3
- Date:
- Fri Feb 17 22:23:17 2017 +0000
- Revision:
- 2:9e45f00fd2de
- Parent:
- 0:0cdbc206e85f
init commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:0cdbc206e85f | 1 | /****************************************************************************** |
j3 | 0:0cdbc206e85f | 2 | * MIT License |
j3 | 0:0cdbc206e85f | 3 | * |
j3 | 0:0cdbc206e85f | 4 | * Copyright (c) 2017 Justin J. Jordan |
j3 | 0:0cdbc206e85f | 5 | * |
j3 | 0:0cdbc206e85f | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
j3 | 0:0cdbc206e85f | 7 | * of this software and associated documentation files (the "Software"), to deal |
j3 | 0:0cdbc206e85f | 8 | * in the Software without restriction, including without limitation the rights |
j3 | 0:0cdbc206e85f | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
j3 | 0:0cdbc206e85f | 10 | * copies of the Software, and to permit persons to whom the Software is |
j3 | 0:0cdbc206e85f | 11 | * furnished to do so, subject to the following conditions: |
j3 | 0:0cdbc206e85f | 12 | |
j3 | 0:0cdbc206e85f | 13 | * The above copyright notice and this permission notice shall be included in all |
j3 | 0:0cdbc206e85f | 14 | * copies or substantial portions of the Software. |
j3 | 0:0cdbc206e85f | 15 | |
j3 | 0:0cdbc206e85f | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
j3 | 0:0cdbc206e85f | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
j3 | 0:0cdbc206e85f | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
j3 | 0:0cdbc206e85f | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
j3 | 0:0cdbc206e85f | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
j3 | 0:0cdbc206e85f | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
j3 | 0:0cdbc206e85f | 22 | * SOFTWARE. |
j3 | 0:0cdbc206e85f | 23 | ******************************************************************************/ |
j3 | 0:0cdbc206e85f | 24 | |
j3 | 0:0cdbc206e85f | 25 | |
j3 | 0:0cdbc206e85f | 26 | #include "mbed.h" |
j3 | 0:0cdbc206e85f | 27 | #include "OneWire.h" |
j3 | 0:0cdbc206e85f | 28 | #include "max32630fthr.h" |
j3 | 0:0cdbc206e85f | 29 | #include "SDFileSystem.h" |
j3 | 2:9e45f00fd2de | 30 | |
j3 | 2:9e45f00fd2de | 31 | #define TERM_HOME "\033[H" |
j3 | 2:9e45f00fd2de | 32 | #define TERM_CLEAR_FROM_CURSOR "\033[0J" |
j3 | 2:9e45f00fd2de | 33 | #define TERM_CLEAR_EOL "\033[K" |
j3 | 0:0cdbc206e85f | 34 | |
j3 | 0:0cdbc206e85f | 35 | using namespace OneWire; |
j3 | 0:0cdbc206e85f | 36 | using namespace RomCommands; |
j3 | 0:0cdbc206e85f | 37 | |
j3 | 0:0cdbc206e85f | 38 | |
j3 | 0:0cdbc206e85f | 39 | Ticker oneSecondTicker; |
j3 | 0:0cdbc206e85f | 40 | volatile uint32_t secondCounter = 0; |
j3 | 0:0cdbc206e85f | 41 | void oneSecond() |
j3 | 0:0cdbc206e85f | 42 | { |
j3 | 0:0cdbc206e85f | 43 | secondCounter++; |
j3 | 0:0cdbc206e85f | 44 | } |
j3 | 0:0cdbc206e85f | 45 | |
j3 | 0:0cdbc206e85f | 46 | //Setup start/stop button |
j3 | 0:0cdbc206e85f | 47 | DigitalIn sw2(P2_3, PullUp); |
j3 | 0:0cdbc206e85f | 48 | InterruptIn startStopLog(P2_3); |
j3 | 0:0cdbc206e85f | 49 | volatile bool startLog = false; |
j3 | 0:0cdbc206e85f | 50 | void startStopLogISR() |
j3 | 0:0cdbc206e85f | 51 | { |
j3 | 0:0cdbc206e85f | 52 | startLog = !startLog; |
j3 | 0:0cdbc206e85f | 53 | } |
j3 | 0:0cdbc206e85f | 54 | |
j3 | 0:0cdbc206e85f | 55 | |
j3 | 0:0cdbc206e85f | 56 | int main () |
j3 | 0:0cdbc206e85f | 57 | { |
j3 | 0:0cdbc206e85f | 58 | //Init board and set GPIO to 3.3V logic |
j3 | 0:0cdbc206e85f | 59 | MAX32630FTHR pegasus; |
j3 | 0:0cdbc206e85f | 60 | pegasus.init(MAX32630FTHR::VIO_3V3); |
j3 | 0:0cdbc206e85f | 61 | |
j3 | 0:0cdbc206e85f | 62 | //Turn RGB LED off |
j3 | 0:0cdbc206e85f | 63 | DigitalOut rLED(LED1, LED_ON); |
j3 | 0:0cdbc206e85f | 64 | DigitalOut gLED(LED2, LED_OFF); |
j3 | 0:0cdbc206e85f | 65 | DigitalOut bLED(LED3, LED_OFF); |
j3 | 0:0cdbc206e85f | 66 | |
j3 | 2:9e45f00fd2de | 67 | //Clear terminal screen |
j3 | 2:9e45f00fd2de | 68 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 69 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 70 | |
j3 | 0:0cdbc206e85f | 71 | //Get 1-Wire Master (owm) instance |
j3 | 2:9e45f00fd2de | 72 | // (extWeakPup, extStrongPup) |
j3 | 2:9e45f00fd2de | 73 | MCU_OWM owm(false, true); |
j3 | 0:0cdbc206e85f | 74 | |
j3 | 0:0cdbc206e85f | 75 | //Make sure owm is initialized |
j3 | 0:0cdbc206e85f | 76 | OneWireMaster::CmdResult result = owm.OWInitMaster(); |
j3 | 0:0cdbc206e85f | 77 | while(result != OneWireMaster::Success) |
j3 | 0:0cdbc206e85f | 78 | { |
j3 | 2:9e45f00fd2de | 79 | printf("Failed to init OWM...\r\n\r\n"); |
j3 | 0:0cdbc206e85f | 80 | result = owm.OWInitMaster(); |
j3 | 0:0cdbc206e85f | 81 | wait(0.5); |
j3 | 0:0cdbc206e85f | 82 | } |
j3 | 2:9e45f00fd2de | 83 | printf("OWM Initialized...\r\n"); |
j3 | 0:0cdbc206e85f | 84 | wait(2.0); |
j3 | 2:9e45f00fd2de | 85 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 86 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 87 | |
j3 | 0:0cdbc206e85f | 88 | |
j3 | 2:9e45f00fd2de | 89 | //Check for DS18B20 |
j3 | 0:0cdbc206e85f | 90 | SearchState search_state; |
j3 | 2:9e45f00fd2de | 91 | search_state.findFamily(0x28); |
j3 | 0:0cdbc206e85f | 92 | do |
j3 | 0:0cdbc206e85f | 93 | { |
j3 | 0:0cdbc206e85f | 94 | result = OWNext(owm, search_state); |
j3 | 2:9e45f00fd2de | 95 | if(search_state.romId.familyCode() != 0x28) |
j3 | 0:0cdbc206e85f | 96 | { |
j3 | 2:9e45f00fd2de | 97 | printf("Failed to find DS18B20...\r\n"); |
j3 | 2:9e45f00fd2de | 98 | printf("Please connect DS18B20...\r\n\r\n"); |
j3 | 0:0cdbc206e85f | 99 | wait(0.5); |
j3 | 0:0cdbc206e85f | 100 | } |
j3 | 0:0cdbc206e85f | 101 | else |
j3 | 0:0cdbc206e85f | 102 | { |
j3 | 2:9e45f00fd2de | 103 | printf("Found DS18B20...\r\n"); |
j3 | 0:0cdbc206e85f | 104 | } |
j3 | 0:0cdbc206e85f | 105 | } |
j3 | 2:9e45f00fd2de | 106 | while(search_state.romId.familyCode() != 0x28); |
j3 | 2:9e45f00fd2de | 107 | wait(2.0); |
j3 | 2:9e45f00fd2de | 108 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 109 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 110 | |
j3 | 2:9e45f00fd2de | 111 | //Get instance of DS18B20 object |
j3 | 0:0cdbc206e85f | 112 | MultidropRomIterator selector(owm); |
j3 | 2:9e45f00fd2de | 113 | DS18B20 tempSensor(selector); |
j3 | 0:0cdbc206e85f | 114 | tempSensor.setRomId(search_state.romId); |
j3 | 0:0cdbc206e85f | 115 | |
j3 | 0:0cdbc206e85f | 116 | |
j3 | 0:0cdbc206e85f | 117 | //Get instance of sd card file system |
j3 | 0:0cdbc206e85f | 118 | SDFileSystem sd(P0_5, P0_6, P0_4, P0_7, "sd"); // mosi, miso, sclk, cs |
j3 | 0:0cdbc206e85f | 119 | |
j3 | 0:0cdbc206e85f | 120 | //Configure pin for sd card detect |
j3 | 0:0cdbc206e85f | 121 | DigitalIn uSDdetect(P2_2, PullUp); |
j3 | 0:0cdbc206e85f | 122 | |
j3 | 0:0cdbc206e85f | 123 | static const char FILE_NAME[] = "/sd/log.txt"; |
j3 | 0:0cdbc206e85f | 124 | FILE *fp; |
j3 | 0:0cdbc206e85f | 125 | |
j3 | 0:0cdbc206e85f | 126 | //Check for card |
j3 | 0:0cdbc206e85f | 127 | if(uSDdetect) |
j3 | 0:0cdbc206e85f | 128 | { |
j3 | 2:9e45f00fd2de | 129 | printf("Please insert uSD card\r\n"); |
j3 | 0:0cdbc206e85f | 130 | while(uSDdetect); |
j3 | 0:0cdbc206e85f | 131 | } |
j3 | 0:0cdbc206e85f | 132 | |
j3 | 0:0cdbc206e85f | 133 | rLED = LED_ON; |
j3 | 0:0cdbc206e85f | 134 | gLED = LED_ON; |
j3 | 0:0cdbc206e85f | 135 | do |
j3 | 0:0cdbc206e85f | 136 | { |
j3 | 0:0cdbc206e85f | 137 | fp = fopen(FILE_NAME, "w"); |
j3 | 0:0cdbc206e85f | 138 | if(fp != NULL) |
j3 | 0:0cdbc206e85f | 139 | { |
j3 | 2:9e45f00fd2de | 140 | printf("Card detected...\r\n"); |
j3 | 2:9e45f00fd2de | 141 | printf("Preparing log file...\r\n"); |
j3 | 0:0cdbc206e85f | 142 | fprintf(fp, "Time-Stamp, Battery Voltage, Temperature\n"); |
j3 | 0:0cdbc206e85f | 143 | fclose(fp); |
j3 | 0:0cdbc206e85f | 144 | } |
j3 | 0:0cdbc206e85f | 145 | else |
j3 | 0:0cdbc206e85f | 146 | { |
j3 | 2:9e45f00fd2de | 147 | printf("Failed to open file...\r\n"); |
j3 | 2:9e45f00fd2de | 148 | printf("Press Reset Button...\r\n\r\n"); |
j3 | 2:9e45f00fd2de | 149 | wait(0.5); |
j3 | 0:0cdbc206e85f | 150 | } |
j3 | 0:0cdbc206e85f | 151 | } |
j3 | 0:0cdbc206e85f | 152 | while(fp == NULL); |
j3 | 0:0cdbc206e85f | 153 | rLED = LED_OFF; |
j3 | 0:0cdbc206e85f | 154 | gLED = LED_ON; |
j3 | 2:9e45f00fd2de | 155 | |
j3 | 0:0cdbc206e85f | 156 | wait(2.0); |
j3 | 2:9e45f00fd2de | 157 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 158 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 159 | |
j3 | 0:0cdbc206e85f | 160 | enum UiStates |
j3 | 0:0cdbc206e85f | 161 | { |
j3 | 0:0cdbc206e85f | 162 | Reset, |
j3 | 0:0cdbc206e85f | 163 | NoLog_NoCardDetected, |
j3 | 0:0cdbc206e85f | 164 | NoLog_CardDetected, |
j3 | 0:0cdbc206e85f | 165 | Log_NoCardDetected, |
j3 | 0:0cdbc206e85f | 166 | Log_CardDetected |
j3 | 0:0cdbc206e85f | 167 | }; |
j3 | 0:0cdbc206e85f | 168 | |
j3 | 0:0cdbc206e85f | 169 | UiStates currentState = Reset, oldState = Reset; |
j3 | 0:0cdbc206e85f | 170 | |
j3 | 0:0cdbc206e85f | 171 | static const uint32_t SAMPLE_INTERVAL = 5; // In seconds |
j3 | 0:0cdbc206e85f | 172 | bool firstSampleTaken = false; |
j3 | 0:0cdbc206e85f | 173 | uint32_t sampleTime = 0; |
j3 | 0:0cdbc206e85f | 174 | float batteryVoltage, temperature; |
j3 | 0:0cdbc206e85f | 175 | |
j3 | 0:0cdbc206e85f | 176 | //attach timer to callback for 1 second tick |
j3 | 0:0cdbc206e85f | 177 | oneSecondTicker.attach(&oneSecond, 1); |
j3 | 0:0cdbc206e85f | 178 | |
j3 | 0:0cdbc206e85f | 179 | //Tie SW2 to callback fx |
j3 | 0:0cdbc206e85f | 180 | startStopLog.fall(&startStopLogISR); |
j3 | 0:0cdbc206e85f | 181 | |
j3 | 0:0cdbc206e85f | 182 | |
j3 | 0:0cdbc206e85f | 183 | while(1) |
j3 | 0:0cdbc206e85f | 184 | { |
j3 | 0:0cdbc206e85f | 185 | //card detect is active low |
j3 | 0:0cdbc206e85f | 186 | //Determine state, house keeping |
j3 | 0:0cdbc206e85f | 187 | if(!startLog && uSDdetect) //False, False |
j3 | 0:0cdbc206e85f | 188 | { |
j3 | 0:0cdbc206e85f | 189 | currentState = NoLog_NoCardDetected; |
j3 | 0:0cdbc206e85f | 190 | secondCounter = 0; |
j3 | 0:0cdbc206e85f | 191 | sampleTime = 0; |
j3 | 0:0cdbc206e85f | 192 | firstSampleTaken = false; |
j3 | 0:0cdbc206e85f | 193 | } |
j3 | 0:0cdbc206e85f | 194 | else if(!startLog && !uSDdetect) //False, True |
j3 | 0:0cdbc206e85f | 195 | { |
j3 | 0:0cdbc206e85f | 196 | currentState = NoLog_CardDetected; |
j3 | 0:0cdbc206e85f | 197 | secondCounter = 0; |
j3 | 0:0cdbc206e85f | 198 | sampleTime = 0; |
j3 | 0:0cdbc206e85f | 199 | firstSampleTaken = false; |
j3 | 0:0cdbc206e85f | 200 | } |
j3 | 0:0cdbc206e85f | 201 | else if(startLog && uSDdetect) //True, False |
j3 | 0:0cdbc206e85f | 202 | { |
j3 | 0:0cdbc206e85f | 203 | currentState = Log_NoCardDetected; |
j3 | 0:0cdbc206e85f | 204 | secondCounter = 0; |
j3 | 0:0cdbc206e85f | 205 | sampleTime = 0; |
j3 | 0:0cdbc206e85f | 206 | firstSampleTaken = false; |
j3 | 0:0cdbc206e85f | 207 | } |
j3 | 0:0cdbc206e85f | 208 | else //True, True |
j3 | 0:0cdbc206e85f | 209 | { |
j3 | 0:0cdbc206e85f | 210 | currentState = Log_CardDetected; |
j3 | 0:0cdbc206e85f | 211 | |
j3 | 0:0cdbc206e85f | 212 | //get t = 0 sample |
j3 | 0:0cdbc206e85f | 213 | if(!firstSampleTaken) |
j3 | 0:0cdbc206e85f | 214 | { |
j3 | 0:0cdbc206e85f | 215 | firstSampleTaken = true; |
j3 | 2:9e45f00fd2de | 216 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 217 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 218 | oldState = currentState; |
j3 | 2:9e45f00fd2de | 219 | |
j3 | 0:0cdbc206e85f | 220 | pegasus.getBatteryVoltage(&batteryVoltage); |
j3 | 0:0cdbc206e85f | 221 | tempSensor.convertTemperature(temperature); |
j3 | 0:0cdbc206e85f | 222 | |
j3 | 2:9e45f00fd2de | 223 | printf("Logging Data...\r\n\r\n"); |
j3 | 2:9e45f00fd2de | 224 | printf("Timestamp: %d (seconds)\r\n\r\n", sampleTime); |
j3 | 2:9e45f00fd2de | 225 | printf("Battery Voltage = %s%3.2f\r\n\r\n", TERM_CLEAR_EOL, batteryVoltage); |
j3 | 2:9e45f00fd2de | 226 | printf("Temperature = %s%5.2f\r\n\r\n", TERM_CLEAR_EOL, temperature); |
j3 | 2:9e45f00fd2de | 227 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 228 | |
j3 | 0:0cdbc206e85f | 229 | rLED = LED_ON; |
j3 | 0:0cdbc206e85f | 230 | fp = fopen(FILE_NAME, "a"); |
j3 | 0:0cdbc206e85f | 231 | if(fp != NULL) |
j3 | 0:0cdbc206e85f | 232 | { |
j3 | 0:0cdbc206e85f | 233 | fprintf(fp, "%d, %f, %f\n", sampleTime, batteryVoltage, temperature); |
j3 | 0:0cdbc206e85f | 234 | fclose(fp); |
j3 | 0:0cdbc206e85f | 235 | } |
j3 | 0:0cdbc206e85f | 236 | else |
j3 | 0:0cdbc206e85f | 237 | { |
j3 | 2:9e45f00fd2de | 238 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 239 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 2:9e45f00fd2de | 240 | printf("Failed to open file\r\n"); |
j3 | 2:9e45f00fd2de | 241 | printf("Press Reset Button...\r\n"); |
j3 | 2:9e45f00fd2de | 242 | printf("MBED DIE!!...\r\n"); |
j3 | 0:0cdbc206e85f | 243 | mbed_die(); |
j3 | 0:0cdbc206e85f | 244 | } |
j3 | 0:0cdbc206e85f | 245 | rLED = LED_OFF; |
j3 | 0:0cdbc206e85f | 246 | } |
j3 | 0:0cdbc206e85f | 247 | } |
j3 | 0:0cdbc206e85f | 248 | |
j3 | 0:0cdbc206e85f | 249 | //If state has changed, clear dispaly |
j3 | 0:0cdbc206e85f | 250 | if(oldState != currentState) |
j3 | 0:0cdbc206e85f | 251 | { |
j3 | 2:9e45f00fd2de | 252 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 253 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 0:0cdbc206e85f | 254 | oldState = currentState; |
j3 | 0:0cdbc206e85f | 255 | } |
j3 | 0:0cdbc206e85f | 256 | |
j3 | 0:0cdbc206e85f | 257 | //State based actions |
j3 | 0:0cdbc206e85f | 258 | switch(currentState) |
j3 | 0:0cdbc206e85f | 259 | { |
j3 | 0:0cdbc206e85f | 260 | case NoLog_NoCardDetected: |
j3 | 2:9e45f00fd2de | 261 | printf("Please insert uSD card...\r\n"); |
j3 | 2:9e45f00fd2de | 262 | printf(TERM_HOME); |
j3 | 0:0cdbc206e85f | 263 | break; |
j3 | 0:0cdbc206e85f | 264 | |
j3 | 0:0cdbc206e85f | 265 | case NoLog_CardDetected: |
j3 | 2:9e45f00fd2de | 266 | printf("Press SW2 to start logging data...\r\n"); |
j3 | 2:9e45f00fd2de | 267 | printf(TERM_HOME); |
j3 | 0:0cdbc206e85f | 268 | break; |
j3 | 0:0cdbc206e85f | 269 | |
j3 | 0:0cdbc206e85f | 270 | case Log_NoCardDetected: |
j3 | 0:0cdbc206e85f | 271 | startLog = false; |
j3 | 2:9e45f00fd2de | 272 | printf("Please insert uSD card\r\n"); |
j3 | 2:9e45f00fd2de | 273 | printf(TERM_HOME); |
j3 | 0:0cdbc206e85f | 274 | break; |
j3 | 0:0cdbc206e85f | 275 | |
j3 | 0:0cdbc206e85f | 276 | case Log_CardDetected: |
j3 | 0:0cdbc206e85f | 277 | |
j3 | 0:0cdbc206e85f | 278 | if(secondCounter >= SAMPLE_INTERVAL) |
j3 | 0:0cdbc206e85f | 279 | { |
j3 | 0:0cdbc206e85f | 280 | secondCounter = 0; |
j3 | 0:0cdbc206e85f | 281 | sampleTime += SAMPLE_INTERVAL; |
j3 | 0:0cdbc206e85f | 282 | |
j3 | 0:0cdbc206e85f | 283 | pegasus.getBatteryVoltage(&batteryVoltage); |
j3 | 0:0cdbc206e85f | 284 | tempSensor.convertTemperature(temperature); |
j3 | 0:0cdbc206e85f | 285 | |
j3 | 2:9e45f00fd2de | 286 | printf("Logging Data...\r\n\r\n"); |
j3 | 2:9e45f00fd2de | 287 | printf("Timestamp: %d (seconds)\r\n\r\n", sampleTime); |
j3 | 2:9e45f00fd2de | 288 | printf("Battery Voltage = %s%3.2f\r\n\r\n", TERM_CLEAR_EOL, batteryVoltage); |
j3 | 2:9e45f00fd2de | 289 | printf("Temperature = %s%5.2f\r\n\r\n", TERM_CLEAR_EOL, temperature); |
j3 | 2:9e45f00fd2de | 290 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 291 | |
j3 | 0:0cdbc206e85f | 292 | rLED = LED_ON; |
j3 | 0:0cdbc206e85f | 293 | fp = fopen(FILE_NAME, "a"); |
j3 | 0:0cdbc206e85f | 294 | if(fp != NULL) |
j3 | 0:0cdbc206e85f | 295 | { |
j3 | 0:0cdbc206e85f | 296 | fprintf(fp, "%d, %f, %f\n", sampleTime, batteryVoltage, temperature); |
j3 | 0:0cdbc206e85f | 297 | fclose(fp); |
j3 | 0:0cdbc206e85f | 298 | } |
j3 | 0:0cdbc206e85f | 299 | else |
j3 | 0:0cdbc206e85f | 300 | { |
j3 | 2:9e45f00fd2de | 301 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 302 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 2:9e45f00fd2de | 303 | printf("Failed to open file\r\n"); |
j3 | 2:9e45f00fd2de | 304 | printf("Press Reset Button...\r\n"); |
j3 | 2:9e45f00fd2de | 305 | printf("MBED DIE!!...\r\n"); |
j3 | 0:0cdbc206e85f | 306 | mbed_die(); |
j3 | 0:0cdbc206e85f | 307 | } |
j3 | 0:0cdbc206e85f | 308 | rLED = LED_OFF; |
j3 | 0:0cdbc206e85f | 309 | } |
j3 | 0:0cdbc206e85f | 310 | |
j3 | 0:0cdbc206e85f | 311 | break; |
j3 | 0:0cdbc206e85f | 312 | |
j3 | 0:0cdbc206e85f | 313 | default: |
j3 | 2:9e45f00fd2de | 314 | printf(TERM_HOME); |
j3 | 2:9e45f00fd2de | 315 | printf(TERM_CLEAR_FROM_CURSOR); |
j3 | 2:9e45f00fd2de | 316 | printf("Bad State\r\n"); |
j3 | 2:9e45f00fd2de | 317 | printf("Press Reset Button...\r\n"); |
j3 | 2:9e45f00fd2de | 318 | printf("MBED DIE!!...\r\n"); |
j3 | 0:0cdbc206e85f | 319 | mbed_die(); |
j3 | 0:0cdbc206e85f | 320 | break; |
j3 | 0:0cdbc206e85f | 321 | } |
j3 | 0:0cdbc206e85f | 322 | } |
j3 | 0:0cdbc206e85f | 323 | } |