Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PSU-POWERLOGGER by
CODE/System.cpp@3:d55665050fcb, 2012-09-28 (annotated)
- Committer:
- rjc19
- Date:
- Fri Sep 28 15:41:36 2012 +0000
- Revision:
- 3:d55665050fcb
- Parent:
- 1:871a329fd172
Working serial logger needs interface improvement
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| emh203 | 0:d0c18e423b13 | 1 | #include "System.h" | 
| emh203 | 0:d0c18e423b13 | 2 | |
| emh203 | 0:d0c18e423b13 | 3 | DigitalOut EXT_LED0(LED2); | 
| emh203 | 0:d0c18e423b13 | 4 | DigitalOut ETH_LED_GREEN(p29); | 
| emh203 | 0:d0c18e423b13 | 5 | DigitalOut ETH_LED_YELLOW(p30); | 
| emh203 | 0:d0c18e423b13 | 6 | DigitalIn ActionButton(p28); | 
| emh203 | 0:d0c18e423b13 | 7 | DigitalIn SDCardDetect(p11); | 
| emh203 | 0:d0c18e423b13 | 8 | Ticker SystemTick; | 
| emh203 | 0:d0c18e423b13 | 9 | |
| emh203 | 0:d0c18e423b13 | 10 | WORD UpdateHostTerminalTick; | 
| emh203 | 0:d0c18e423b13 | 11 | WORD DisplayUpdateTick; | 
| emh203 | 0:d0c18e423b13 | 12 | WORD ButtonCheckTick; | 
| emh203 | 0:d0c18e423b13 | 13 | WORD DisplayShutOffTick; | 
| emh203 | 0:d0c18e423b13 | 14 | |
| rjc19 | 1:871a329fd172 | 15 | |
| emh203 | 0:d0c18e423b13 | 16 | BYTE SystemState; | 
| rjc19 | 1:871a329fd172 | 17 | BYTE WeAreInNormalMode; | 
| emh203 | 0:d0c18e423b13 | 18 | CHAR DTBuf[32]; | 
| emh203 | 0:d0c18e423b13 | 19 | CHAR DataLineBuf[256]; | 
| emh203 | 0:d0c18e423b13 | 20 | |
| emh203 | 0:d0c18e423b13 | 21 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 22 | //smart Display related stuff | 
| emh203 | 0:d0c18e423b13 | 23 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 24 | |
| emh203 | 0:d0c18e423b13 | 25 | #define DISPLAY_MEASUREMENTS 0x00 | 
| emh203 | 0:d0c18e423b13 | 26 | #define DISPLAY_BATTERY 0x01 | 
| emh203 | 0:d0c18e423b13 | 27 | #define DISPLAY_DATE_TIME 0x02 | 
| emh203 | 0:d0c18e423b13 | 28 | #define DISPLAY_CARD_STATUS 0x03 | 
| emh203 | 0:d0c18e423b13 | 29 | #define DISPLAY_BUFFER_STATS 0x04 | 
| emh203 | 0:d0c18e423b13 | 30 | #define DISPLAY_FIRMWARE_VERSION 0x05 | 
| emh203 | 0:d0c18e423b13 | 31 | #define DISPLAY_ID 0x06 | 
| rjc19 | 1:871a329fd172 | 32 | #define DISPLAY_SERIAL_STATUS 0x07 | 
| rjc19 | 1:871a329fd172 | 33 | |
| emh203 | 0:d0c18e423b13 | 34 | #define DISPLAY_OFF 0xFF | 
| emh203 | 0:d0c18e423b13 | 35 | |
| rjc19 | 1:871a329fd172 | 36 | #define NUM_DISPLAYS 8 | 
| emh203 | 0:d0c18e423b13 | 37 | #define DISPLAY_SHUTOFF_TIME 10000 | 
| emh203 | 0:d0c18e423b13 | 38 | |
| emh203 | 0:d0c18e423b13 | 39 | BYTE DisplayMode; | 
| emh203 | 0:d0c18e423b13 | 40 | BYTE LastBackLightColor = 0; | 
| rjc19 | 1:871a329fd172 | 41 | BYTE LastSerialBrightness = 7; | 
| rjc19 | 1:871a329fd172 | 42 | BOOL SerialFileIsOpen = FALSE; | 
| rjc19 | 1:871a329fd172 | 43 | char SerialLineBuffer[256]; | 
| rjc19 | 1:871a329fd172 | 44 | UINT SerialLineBufferPtr; | 
| rjc19 | 1:871a329fd172 | 45 | UINT LinesWritten =0; | 
| emh203 | 0:d0c18e423b13 | 46 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 47 | //Action Button Related stuff | 
| emh203 | 0:d0c18e423b13 | 48 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 49 | #define WAITING_FOR_PRESS 0x00 | 
| emh203 | 0:d0c18e423b13 | 50 | #define WAITING_FOR_RELEASE 0x01 | 
| emh203 | 0:d0c18e423b13 | 51 | |
| rjc19 | 1:871a329fd172 | 52 | BYTE PreviousButtonState; | 
| rjc19 | 1:871a329fd172 | 53 | BYTE CurrentButtonState; | 
| emh203 | 0:d0c18e423b13 | 54 | WORD ButtonHoldTime; | 
| emh203 | 0:d0c18e423b13 | 55 | BYTE ButtonCheckState; | 
| emh203 | 0:d0c18e423b13 | 56 | void ActionButtonHandler(WORD ButtonPressTime); | 
| emh203 | 0:d0c18e423b13 | 57 | |
| emh203 | 0:d0c18e423b13 | 58 | //time Variables | 
| emh203 | 0:d0c18e423b13 | 59 | time_t CurrentTime_InSec; | 
| emh203 | 0:d0c18e423b13 | 60 | tm *CurrentTime; | 
| emh203 | 0:d0c18e423b13 | 61 | |
| emh203 | 0:d0c18e423b13 | 62 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 63 | //Logging Related Stuff | 
| emh203 | 0:d0c18e423b13 | 64 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 65 | CHAR CurrentLogFileName[256]; | 
| emh203 | 0:d0c18e423b13 | 66 | BOOL InitDataLog(); | 
| emh203 | 0:d0c18e423b13 | 67 | BOOL DataLogError; | 
| emh203 | 0:d0c18e423b13 | 68 | CHAR *ErrorMsg; | 
| rjc19 | 3:d55665050fcb | 69 | WORD SerialCount=0; | 
| emh203 | 0:d0c18e423b13 | 70 | void CreateLogFileName(); | 
| emh203 | 0:d0c18e423b13 | 71 | |
| emh203 | 0:d0c18e423b13 | 72 | FATFS MyFileSystem; | 
| emh203 | 0:d0c18e423b13 | 73 | FIL CurrentLogFileHandle; | 
| emh203 | 0:d0c18e423b13 | 74 | |
| emh203 | 0:d0c18e423b13 | 75 | //DataBlock MyDataBlock[2]; | 
| emh203 | 0:d0c18e423b13 | 76 | DataBlock MyDataBlock; | 
| emh203 | 0:d0c18e423b13 | 77 | |
| emh203 | 0:d0c18e423b13 | 78 | BYTE ActiveDataBlock; | 
| emh203 | 0:d0c18e423b13 | 79 | DWORD DataBlocksWritten; | 
| emh203 | 0:d0c18e423b13 | 80 | DWORD DataPointIndex; | 
| emh203 | 0:d0c18e423b13 | 81 | SIGNED_DWORD ReadWriteDifferential; | 
| emh203 | 0:d0c18e423b13 | 82 | |
| emh203 | 0:d0c18e423b13 | 83 | DWORD WritesSinceLastFlush; | 
| emh203 | 0:d0c18e423b13 | 84 | |
| emh203 | 0:d0c18e423b13 | 85 | #define BINARY_WRITE_CACHE_THRESHOLD 512 | 
| emh203 | 0:d0c18e423b13 | 86 | BYTE BinaryDataCache[BINARY_WRITE_CACHE_THRESHOLD + 64]; | 
| emh203 | 0:d0c18e423b13 | 87 | DWORD BinaryDataCachePtr; | 
| emh203 | 0:d0c18e423b13 | 88 | |
| emh203 | 0:d0c18e423b13 | 89 | #define NUM_WRITES_BEFORE_FLUSH (10) | 
| emh203 | 0:d0c18e423b13 | 90 | |
| emh203 | 0:d0c18e423b13 | 91 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 92 | //Misc System Related Stuff | 
| emh203 | 0:d0c18e423b13 | 93 | //***************************************************************** | 
| emh203 | 0:d0c18e423b13 | 94 | void SystemTickIrq(); | 
| emh203 | 0:d0c18e423b13 | 95 | void AdjustIOffset(); | 
| emh203 | 0:d0c18e423b13 | 96 | |
| emh203 | 0:d0c18e423b13 | 97 | void InitRobotPowerMeasurementSystem() | 
| emh203 | 0:d0c18e423b13 | 98 | { | 
| emh203 | 0:d0c18e423b13 | 99 | InitDataBlocks(&MyDataBlock); | 
| rjc19 | 1:871a329fd172 | 100 | |
| emh203 | 0:d0c18e423b13 | 101 | ActiveDataBlock = 0; | 
| emh203 | 0:d0c18e423b13 | 102 | DataBlocksWritten = 0; | 
| emh203 | 0:d0c18e423b13 | 103 | DataPointIndex = 0; | 
| rjc19 | 1:871a329fd172 | 104 | |
| emh203 | 0:d0c18e423b13 | 105 | SystemTick.attach_us(&SystemTickIrq,10000); | 
| emh203 | 0:d0c18e423b13 | 106 | CurrentTime_InSec = time(NULL); | 
| rjc19 | 1:871a329fd172 | 107 | |
| emh203 | 0:d0c18e423b13 | 108 | DataLogError = FALSE; | 
| emh203 | 0:d0c18e423b13 | 109 | } | 
| emh203 | 0:d0c18e423b13 | 110 | |
| emh203 | 0:d0c18e423b13 | 111 | |
| emh203 | 0:d0c18e423b13 | 112 | void InitDataBlocks(DataBlock * DB) | 
| emh203 | 0:d0c18e423b13 | 113 | { | 
| emh203 | 0:d0c18e423b13 | 114 | int i; | 
| rjc19 | 1:871a329fd172 | 115 | |
| rjc19 | 1:871a329fd172 | 116 | for(i=0; i<DATA_BLOCK_SIZE; i++) { | 
| emh203 | 0:d0c18e423b13 | 117 | DB->Voltage[i] = 0; | 
| emh203 | 0:d0c18e423b13 | 118 | DB->Current[i] = 0; | 
| emh203 | 0:d0c18e423b13 | 119 | } | 
| rjc19 | 1:871a329fd172 | 120 | |
| rjc19 | 1:871a329fd172 | 121 | DB->WriteOutPtr = 0; | 
| rjc19 | 1:871a329fd172 | 122 | DB->ReadInPtr = 0; | 
| emh203 | 0:d0c18e423b13 | 123 | } | 
| emh203 | 0:d0c18e423b13 | 124 | |
| emh203 | 0:d0c18e423b13 | 125 | |
| emh203 | 0:d0c18e423b13 | 126 | void EnterSystemState(BYTE NextState) | 
| emh203 | 0:d0c18e423b13 | 127 | { | 
| rjc19 | 1:871a329fd172 | 128 | switch(NextState) { | 
| emh203 | 0:d0c18e423b13 | 129 | default: | 
| emh203 | 0:d0c18e423b13 | 130 | case SYSTEM_STATE_INIT: | 
| emh203 | 0:d0c18e423b13 | 131 | DisplayMode = DISPLAY_MEASUREMENTS; | 
| emh203 | 0:d0c18e423b13 | 132 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 133 | break; | 
| rjc19 | 1:871a329fd172 | 134 | |
| emh203 | 0:d0c18e423b13 | 135 | case SYSTEM_STATE_LOGGING: | 
| rjc19 | 1:871a329fd172 | 136 | DisplayMode = DISPLAY_CARD_STATUS; | 
| rjc19 | 1:871a329fd172 | 137 | |
| rjc19 | 1:871a329fd172 | 138 | if(InitDataLog() == FALSE) { | 
| emh203 | 0:d0c18e423b13 | 139 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 140 | |
| rjc19 | 1:871a329fd172 | 141 | } else { | 
| emh203 | 0:d0c18e423b13 | 142 | SystemState = SYSTEM_STATE_IDLE; | 
| rjc19 | 1:871a329fd172 | 143 | } | 
| rjc19 | 1:871a329fd172 | 144 | |
| rjc19 | 1:871a329fd172 | 145 | break; | 
| rjc19 | 1:871a329fd172 | 146 | |
| rjc19 | 1:871a329fd172 | 147 | case SYSTEM_STATE_SERIAL_LOGGING: | 
| rjc19 | 1:871a329fd172 | 148 | if(InitSerialDataLog() == FALSE){ | 
| rjc19 | 1:871a329fd172 | 149 | PrintfLogEnqueue(&PCBackDoorTx,"%cS",SERIALSPEED); | 
| rjc19 | 3:d55665050fcb | 150 | SerialCount=0; | 
| rjc19 | 1:871a329fd172 | 151 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 152 | } | 
| rjc19 | 1:871a329fd172 | 153 | else{ | 
| rjc19 | 1:871a329fd172 | 154 | SystemState=SYSTEM_STATE_IDLE; | 
| rjc19 | 1:871a329fd172 | 155 | } | 
| rjc19 | 1:871a329fd172 | 156 | break; | 
| rjc19 | 1:871a329fd172 | 157 | |
| emh203 | 0:d0c18e423b13 | 158 | case SYSTEM_STATE_IDLE: | 
| emh203 | 0:d0c18e423b13 | 159 | DisplayMode = DISPLAY_CARD_STATUS; | 
| rjc19 | 1:871a329fd172 | 160 | switch (SystemState){ | 
| rjc19 | 1:871a329fd172 | 161 | case SYSTEM_STATE_SERIAL_LOGGING: | 
| rjc19 | 1:871a329fd172 | 162 | DisplayMode=DISPLAY_SERIAL_STATUS; //Need to stay here for serial logging | 
| rjc19 | 1:871a329fd172 | 163 | //NO BREAK ON PURPOSE | 
| rjc19 | 1:871a329fd172 | 164 | |
| rjc19 | 1:871a329fd172 | 165 | case SYSTEM_STATE_LOGGING: | 
| rjc19 | 1:871a329fd172 | 166 | f_close(&CurrentLogFileHandle); | 
| rjc19 | 1:871a329fd172 | 167 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 168 | PrintfEnqueue(&PCBackDoorTx,"Logging terminated on file %s\r\n>",CurrentLogFileName); | 
| rjc19 | 1:871a329fd172 | 169 | break; | 
| emh203 | 0:d0c18e423b13 | 170 | } | 
| emh203 | 0:d0c18e423b13 | 171 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 172 | break; | 
| emh203 | 0:d0c18e423b13 | 173 | } | 
| emh203 | 0:d0c18e423b13 | 174 | } | 
| emh203 | 0:d0c18e423b13 | 175 | |
| emh203 | 0:d0c18e423b13 | 176 | BOOL InitDataLog() | 
| emh203 | 0:d0c18e423b13 | 177 | { | 
| emh203 | 0:d0c18e423b13 | 178 | UINT BytesWritten; | 
| rjc19 | 1:871a329fd172 | 179 | |
| emh203 | 0:d0c18e423b13 | 180 | PrintfEnqueue(&PCBackDoorTx,"\r\n\r\bInitializing Data log....\r\n"); | 
| emh203 | 0:d0c18e423b13 | 181 | CreateLogFileName(); | 
| emh203 | 0:d0c18e423b13 | 182 | PrintfEnqueue(&PCBackDoorTx,"Filename: %s\r\n",CurrentLogFileName); | 
| emh203 | 0:d0c18e423b13 | 183 | PrintfEnqueue(&PCBackDoorTx,"Attempting File Open....\r\n"); | 
| rjc19 | 1:871a329fd172 | 184 | |
| rjc19 | 1:871a329fd172 | 185 | |
| emh203 | 0:d0c18e423b13 | 186 | f_mount(0,&MyFileSystem); | 
| rjc19 | 1:871a329fd172 | 187 | if(f_open(&CurrentLogFileHandle,&CurrentLogFileName[0],FA_WRITE | FA_OPEN_ALWAYS) != FR_OK) { | 
| rjc19 | 1:871a329fd172 | 188 | DataLogError = TRUE; | 
| rjc19 | 1:871a329fd172 | 189 | PrintfEnqueue(&PCBackDoorTx,"Could not open file!\r\n>"); | 
| rjc19 | 1:871a329fd172 | 190 | ErrorMsg = "Write Error!"; | 
| rjc19 | 1:871a329fd172 | 191 | return TRUE; | 
| rjc19 | 1:871a329fd172 | 192 | } | 
| emh203 | 0:d0c18e423b13 | 193 | |
| emh203 | 0:d0c18e423b13 | 194 | |
| rjc19 | 1:871a329fd172 | 195 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 196 | PrintfEnqueue(&PCBackDoorTx,"Writing Headers....\r\n"); | 
| rjc19 | 1:871a329fd172 | 197 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 198 | strftime(DTBuf,128, "%Y.%m.%d", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 199 | f_printf(&CurrentLogFileHandle, "Date %s\r\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 200 | strftime(DTBuf,128, "%H:%M:%S", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 201 | f_printf(&CurrentLogFileHandle, "Time %s\r\n\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 202 | sprintf(DTBuf, "Sample Rate %.1f Hz\r\n\r\n",SAMPLE_RATE); | 
| rjc19 | 1:871a329fd172 | 203 | f_write(&CurrentLogFileHandle,DTBuf,strlen(DTBuf),&BytesWritten); | 
| rjc19 | 1:871a329fd172 | 204 | PrintfEnqueue(&PCBackDoorTx,"Headers Written.... Starting log\r\n"); | 
| rjc19 | 1:871a329fd172 | 205 | |
| rjc19 | 1:871a329fd172 | 206 | |
| rjc19 | 1:871a329fd172 | 207 | PrintfEnqueue(&PCBackDoorTx,"\r\n>"); | 
| rjc19 | 1:871a329fd172 | 208 | |
| rjc19 | 1:871a329fd172 | 209 | |
| rjc19 | 1:871a329fd172 | 210 | |
| emh203 | 0:d0c18e423b13 | 211 | BinaryDataCachePtr = 0; | 
| emh203 | 0:d0c18e423b13 | 212 | WritesSinceLastFlush = 0; | 
| rjc19 | 1:871a329fd172 | 213 | |
| emh203 | 0:d0c18e423b13 | 214 | DataBlocksWritten = 0; | 
| emh203 | 0:d0c18e423b13 | 215 | DataPointIndex = 0; | 
| emh203 | 0:d0c18e423b13 | 216 | |
| emh203 | 0:d0c18e423b13 | 217 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 218 | } | 
| emh203 | 0:d0c18e423b13 | 219 | |
| rjc19 | 1:871a329fd172 | 220 | BOOL InitSerialDataLog() | 
| rjc19 | 1:871a329fd172 | 221 | { | 
| rjc19 | 1:871a329fd172 | 222 | PrintfEnqueue(&PCBackDoorTx,"\r\n\r\bInitializing Data log....\r\n"); | 
| rjc19 | 1:871a329fd172 | 223 | CreateLogFileName(); | 
| rjc19 | 1:871a329fd172 | 224 | PrintfEnqueue(&PCBackDoorTx,"Filename: %s\r\n",CurrentLogFileName); | 
| rjc19 | 1:871a329fd172 | 225 | PrintfEnqueue(&PCBackDoorTx,"Attempting File Open....\r\n"); | 
| rjc19 | 1:871a329fd172 | 226 | |
| rjc19 | 1:871a329fd172 | 227 | |
| rjc19 | 1:871a329fd172 | 228 | f_mount(0,&MyFileSystem); | 
| rjc19 | 1:871a329fd172 | 229 | if(f_open(&CurrentLogFileHandle,&CurrentLogFileName[0],FA_WRITE | FA_OPEN_ALWAYS) != FR_OK) { | 
| rjc19 | 1:871a329fd172 | 230 | DataLogError = TRUE; | 
| rjc19 | 1:871a329fd172 | 231 | PrintfEnqueue(&PCBackDoorTx,"Could not open file!\r\n>"); | 
| rjc19 | 1:871a329fd172 | 232 | ErrorMsg = "Write Error!"; | 
| rjc19 | 1:871a329fd172 | 233 | f_mount(0,0); | 
| rjc19 | 1:871a329fd172 | 234 | return TRUE; | 
| rjc19 | 1:871a329fd172 | 235 | } | 
| rjc19 | 1:871a329fd172 | 236 | |
| rjc19 | 1:871a329fd172 | 237 | |
| rjc19 | 1:871a329fd172 | 238 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 239 | PrintfEnqueue(&PCBackDoorTx,"Writing Headers....\r\n"); | 
| rjc19 | 1:871a329fd172 | 240 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 241 | f_printf(&CurrentLogFileHandle,"Rate,V1,C1,V2,C2,V3,C3,V4,C4,V5,C5,V6,C6,B1V,B1C,B2V,B2C,"); | 
| rjc19 | 1:871a329fd172 | 242 | strftime(DTBuf,128, "%Y.%m.%d", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 243 | |
| rjc19 | 1:871a329fd172 | 244 | f_printf(&CurrentLogFileHandle, "Date ,%s,",DTBuf); | 
| rjc19 | 1:871a329fd172 | 245 | strftime(DTBuf,128, "%H:%M:%S", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 246 | f_printf(&CurrentLogFileHandle, "Time ,%s\r\n\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 247 | |
| rjc19 | 1:871a329fd172 | 248 | // sprintf(DTBuf, "Sample Rate %.1f Hz\r\n\r\n",SAMPLE_RATE); | 
| rjc19 | 1:871a329fd172 | 249 | // f_write(&CurrentLogFileHandle,DTBuf,strlen(DTBuf),&BytesWritten); | 
| rjc19 | 1:871a329fd172 | 250 | f_sync(&CurrentLogFileHandle); | 
| rjc19 | 1:871a329fd172 | 251 | PrintfEnqueue(&PCBackDoorTx,"Headers Written.... Starting log\r\n"); | 
| rjc19 | 1:871a329fd172 | 252 | |
| rjc19 | 1:871a329fd172 | 253 | |
| rjc19 | 1:871a329fd172 | 254 | PrintfEnqueue(&PCBackDoorTx,"\r\n>"); | 
| rjc19 | 1:871a329fd172 | 255 | SerialLineBufferPtr=0; | 
| rjc19 | 1:871a329fd172 | 256 | return FALSE; | 
| rjc19 | 1:871a329fd172 | 257 | } | 
| emh203 | 0:d0c18e423b13 | 258 | |
| emh203 | 0:d0c18e423b13 | 259 | void CreateLogFileName() | 
| emh203 | 0:d0c18e423b13 | 260 | { | 
| rjc19 | 1:871a329fd172 | 261 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 262 | strftime(CurrentLogFileName,256, "F%Y.%m.%d.%H.%M.%S.csv", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 263 | } | 
| emh203 | 0:d0c18e423b13 | 264 | |
| emh203 | 0:d0c18e423b13 | 265 | |
| emh203 | 0:d0c18e423b13 | 266 | |
| emh203 | 0:d0c18e423b13 | 267 | void SystemTickIrq() | 
| emh203 | 0:d0c18e423b13 | 268 | { | 
| emh203 | 0:d0c18e423b13 | 269 | if(UpdateHostTerminalTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 270 | UpdateHostTerminalTick++; | 
| rjc19 | 1:871a329fd172 | 271 | |
| emh203 | 0:d0c18e423b13 | 272 | if(DisplayUpdateTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 273 | DisplayUpdateTick++; | 
| rjc19 | 1:871a329fd172 | 274 | |
| emh203 | 0:d0c18e423b13 | 275 | if(ButtonCheckTick<0xFFFF) | 
| rjc19 | 1:871a329fd172 | 276 | ButtonCheckTick++; | 
| rjc19 | 1:871a329fd172 | 277 | |
| rjc19 | 1:871a329fd172 | 278 | if(DisplayShutOffTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 279 | DisplayShutOffTick++; | 
| emh203 | 0:d0c18e423b13 | 280 | } | 
| emh203 | 0:d0c18e423b13 | 281 | |
| emh203 | 0:d0c18e423b13 | 282 | void InitButton() | 
| emh203 | 0:d0c18e423b13 | 283 | { | 
| emh203 | 0:d0c18e423b13 | 284 | ButtonCheckState = WAITING_FOR_PRESS; | 
| emh203 | 0:d0c18e423b13 | 285 | ButtonCheckTick = 0; | 
| emh203 | 0:d0c18e423b13 | 286 | PreviousButtonState = FALSE; | 
| emh203 | 0:d0c18e423b13 | 287 | CurrentButtonState = FALSE; | 
| emh203 | 0:d0c18e423b13 | 288 | |
| emh203 | 0:d0c18e423b13 | 289 | } | 
| emh203 | 0:d0c18e423b13 | 290 | void CheckButton() | 
| emh203 | 0:d0c18e423b13 | 291 | { | 
| rjc19 | 1:871a329fd172 | 292 | if(ButtonCheckTick>0) { | 
| emh203 | 0:d0c18e423b13 | 293 | ButtonCheckTick = 0; | 
| rjc19 | 1:871a329fd172 | 294 | |
| emh203 | 0:d0c18e423b13 | 295 | PreviousButtonState = CurrentButtonState; | 
| rjc19 | 1:871a329fd172 | 296 | CurrentButtonState = ActionButton.read(); | 
| rjc19 | 1:871a329fd172 | 297 | |
| rjc19 | 1:871a329fd172 | 298 | switch(ButtonCheckState) { | 
| emh203 | 0:d0c18e423b13 | 299 | default: | 
| emh203 | 0:d0c18e423b13 | 300 | case WAITING_FOR_PRESS: | 
| rjc19 | 1:871a329fd172 | 301 | |
| rjc19 | 1:871a329fd172 | 302 | if(CurrentButtonState == TRUE && PreviousButtonState == FALSE) { | 
| rjc19 | 1:871a329fd172 | 303 | ButtonCheckState = WAITING_FOR_RELEASE; | 
| rjc19 | 1:871a329fd172 | 304 | } | 
| rjc19 | 1:871a329fd172 | 305 | |
| rjc19 | 1:871a329fd172 | 306 | ButtonHoldTime = 0; | 
| rjc19 | 1:871a329fd172 | 307 | |
| rjc19 | 1:871a329fd172 | 308 | break; | 
| rjc19 | 1:871a329fd172 | 309 | |
| emh203 | 0:d0c18e423b13 | 310 | case WAITING_FOR_RELEASE: | 
| rjc19 | 1:871a329fd172 | 311 | |
| rjc19 | 1:871a329fd172 | 312 | if(CurrentButtonState == TRUE && PreviousButtonState == TRUE) { | 
| rjc19 | 1:871a329fd172 | 313 | ButtonHoldTime++; | 
| rjc19 | 1:871a329fd172 | 314 | } else if(CurrentButtonState == FALSE && PreviousButtonState == TRUE) { | 
| rjc19 | 1:871a329fd172 | 315 | ActionButtonHandler(ButtonHoldTime); | 
| rjc19 | 1:871a329fd172 | 316 | ButtonCheckState = WAITING_FOR_PRESS; | 
| rjc19 | 1:871a329fd172 | 317 | } else { | 
| rjc19 | 1:871a329fd172 | 318 | ButtonCheckState = WAITING_FOR_PRESS; | 
| rjc19 | 1:871a329fd172 | 319 | } | 
| rjc19 | 1:871a329fd172 | 320 | break; | 
| emh203 | 0:d0c18e423b13 | 321 | } | 
| emh203 | 0:d0c18e423b13 | 322 | } | 
| emh203 | 0:d0c18e423b13 | 323 | } | 
| rjc19 | 1:871a329fd172 | 324 | char SpeedString[20]; | 
| rjc19 | 1:871a329fd172 | 325 | void TranslateToText(){ | 
| rjc19 | 1:871a329fd172 | 326 | switch(SERIALSPEED){ | 
| rjc19 | 1:871a329fd172 | 327 | case '0': | 
| rjc19 | 1:871a329fd172 | 328 | sprintf(&SpeedString[0],"20 mS"); | 
| rjc19 | 1:871a329fd172 | 329 | break; | 
| rjc19 | 1:871a329fd172 | 330 | case '1': | 
| rjc19 | 1:871a329fd172 | 331 | sprintf(&SpeedString[0],"30 mS"); | 
| rjc19 | 1:871a329fd172 | 332 | break; | 
| rjc19 | 1:871a329fd172 | 333 | case '2': | 
| rjc19 | 1:871a329fd172 | 334 | sprintf(&SpeedString[0],"40 mS"); | 
| rjc19 | 1:871a329fd172 | 335 | break; | 
| rjc19 | 1:871a329fd172 | 336 | case '3': | 
| rjc19 | 1:871a329fd172 | 337 | sprintf(&SpeedString[0],"50 mS"); | 
| rjc19 | 1:871a329fd172 | 338 | break; | 
| rjc19 | 1:871a329fd172 | 339 | case '4': | 
| rjc19 | 1:871a329fd172 | 340 | sprintf(&SpeedString[0],"100 mS"); | 
| rjc19 | 1:871a329fd172 | 341 | break; | 
| rjc19 | 1:871a329fd172 | 342 | case '5': | 
| rjc19 | 1:871a329fd172 | 343 | sprintf(&SpeedString[0],"1 S"); | 
| rjc19 | 1:871a329fd172 | 344 | break; | 
| rjc19 | 1:871a329fd172 | 345 | case '6': | 
| rjc19 | 1:871a329fd172 | 346 | sprintf(&SpeedString[0],"2 S"); | 
| rjc19 | 1:871a329fd172 | 347 | break; | 
| rjc19 | 1:871a329fd172 | 348 | case '7': | 
| rjc19 | 1:871a329fd172 | 349 | sprintf(&SpeedString[0],"5 S"); | 
| rjc19 | 1:871a329fd172 | 350 | break; | 
| rjc19 | 1:871a329fd172 | 351 | case '8': | 
| rjc19 | 1:871a329fd172 | 352 | sprintf(&SpeedString[0],"10 S"); | 
| rjc19 | 1:871a329fd172 | 353 | break; | 
| rjc19 | 1:871a329fd172 | 354 | case '9': | 
| rjc19 | 1:871a329fd172 | 355 | sprintf(&SpeedString[0],"30 S"); | 
| rjc19 | 1:871a329fd172 | 356 | break; | 
| rjc19 | 1:871a329fd172 | 357 | default: | 
| rjc19 | 1:871a329fd172 | 358 | sprintf(&SpeedString[0],"ERROR"); | 
| rjc19 | 1:871a329fd172 | 359 | break; | 
| rjc19 | 1:871a329fd172 | 360 | } | 
| rjc19 | 1:871a329fd172 | 361 | } | 
| emh203 | 0:d0c18e423b13 | 362 | |
| emh203 | 0:d0c18e423b13 | 363 | void ActionButtonHandler(WORD ButtonPressTime) | 
| emh203 | 0:d0c18e423b13 | 364 | { | 
| emh203 | 0:d0c18e423b13 | 365 | DisplayShutOffTick = 0; | 
| emh203 | 0:d0c18e423b13 | 366 | |
| rjc19 | 1:871a329fd172 | 367 | if(ButtonPressTime<50) { | 
| rjc19 | 1:871a329fd172 | 368 | if(DisplayMode == DISPLAY_OFF) { | 
| rjc19 | 1:871a329fd172 | 369 | PowerUpSmartSwitch(); | 
| rjc19 | 1:871a329fd172 | 370 | SmartSwitch_Reset(); | 
| rjc19 | 1:871a329fd172 | 371 | SmartSwitchClear(); | 
| rjc19 | 1:871a329fd172 | 372 | DisplayMode = DISPLAY_MEASUREMENTS; | 
| rjc19 | 1:871a329fd172 | 373 | } else { | 
| rjc19 | 1:871a329fd172 | 374 | |
| rjc19 | 1:871a329fd172 | 375 | if(DataLogError == TRUE) { | 
| emh203 | 0:d0c18e423b13 | 376 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 377 | } else { | 
| emh203 | 0:d0c18e423b13 | 378 | DisplayMode++; | 
| rjc19 | 1:871a329fd172 | 379 | |
| rjc19 | 1:871a329fd172 | 380 | if(DisplayMode >= NUM_DISPLAYS) { | 
| emh203 | 0:d0c18e423b13 | 381 | DisplayMode = 0; | 
| emh203 | 0:d0c18e423b13 | 382 | } | 
| emh203 | 0:d0c18e423b13 | 383 | } | 
| emh203 | 0:d0c18e423b13 | 384 | } | 
| emh203 | 0:d0c18e423b13 | 385 | } | 
| rjc19 | 1:871a329fd172 | 386 | |
| rjc19 | 1:871a329fd172 | 387 | else if(ButtonPressTime>100 && ButtonPressTime<500) { //Long action button | 
| rjc19 | 1:871a329fd172 | 388 | switch(SystemState) { | 
| emh203 | 0:d0c18e423b13 | 389 | default: | 
| emh203 | 0:d0c18e423b13 | 390 | case SYSTEM_STATE_IDLE: | 
| rjc19 | 1:871a329fd172 | 391 | switch(DisplayMode) { | 
| rjc19 | 1:871a329fd172 | 392 | default: | 
| rjc19 | 1:871a329fd172 | 393 | |
| rjc19 | 1:871a329fd172 | 394 | break; | 
| rjc19 | 1:871a329fd172 | 395 | |
| emh203 | 0:d0c18e423b13 | 396 | case DISPLAY_MEASUREMENTS: | 
| emh203 | 0:d0c18e423b13 | 397 | AdjustIOffset(); | 
| rjc19 | 1:871a329fd172 | 398 | break; | 
| rjc19 | 1:871a329fd172 | 399 | |
| rjc19 | 1:871a329fd172 | 400 | |
| rjc19 | 1:871a329fd172 | 401 | case DISPLAY_FIRMWARE_VERSION: | 
| rjc19 | 1:871a329fd172 | 402 | LoadConfiguration(); | 
| rjc19 | 1:871a329fd172 | 403 | break; | 
| rjc19 | 1:871a329fd172 | 404 | |
| rjc19 | 1:871a329fd172 | 405 | |
| rjc19 | 1:871a329fd172 | 406 | case DISPLAY_CARD_STATUS: | 
| rjc19 | 1:871a329fd172 | 407 | // if(SDCardDetect == 1) | 
| rjc19 | 1:871a329fd172 | 408 | { | 
| rjc19 | 1:871a329fd172 | 409 | EnterSystemState(SYSTEM_STATE_LOGGING); | 
| rjc19 | 1:871a329fd172 | 410 | } | 
| emh203 | 0:d0c18e423b13 | 411 | break; | 
| emh203 | 0:d0c18e423b13 | 412 | |
| rjc19 | 1:871a329fd172 | 413 | case DISPLAY_SERIAL_STATUS: | 
| rjc19 | 1:871a329fd172 | 414 | EnterSystemState(SYSTEM_STATE_SERIAL_LOGGING); | 
| rjc19 | 1:871a329fd172 | 415 | break; | 
| rjc19 | 1:871a329fd172 | 416 | } | 
| rjc19 | 1:871a329fd172 | 417 | break; | 
| rjc19 | 1:871a329fd172 | 418 | |
| rjc19 | 1:871a329fd172 | 419 | case SYSTEM_STATE_SERIAL_LOGGING: | 
| rjc19 | 1:871a329fd172 | 420 | PrintfLogEnqueue(&PCBackDoorTx,"QQQ\r\n"); //Shutdown | 
| rjc19 | 1:871a329fd172 | 421 | EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 422 | DisplayMode=DISPLAY_SERIAL_STATUS; //Need to stay here | 
| rjc19 | 1:871a329fd172 | 423 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 424 | break; | 
| rjc19 | 1:871a329fd172 | 425 | |
| rjc19 | 1:871a329fd172 | 426 | case SYSTEM_STATE_LOGGING: | 
| rjc19 | 1:871a329fd172 | 427 | EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 428 | // unmount the file system | 
| rjc19 | 1:871a329fd172 | 429 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 430 | break; | 
| rjc19 | 1:871a329fd172 | 431 | |
| emh203 | 0:d0c18e423b13 | 432 | } | 
| emh203 | 0:d0c18e423b13 | 433 | } | 
| emh203 | 0:d0c18e423b13 | 434 | } | 
| emh203 | 0:d0c18e423b13 | 435 | |
| emh203 | 0:d0c18e423b13 | 436 | void AdjustIOffset() | 
| emh203 | 0:d0c18e423b13 | 437 | { | 
| emh203 | 0:d0c18e423b13 | 438 | DWORD SamplesToTake; | 
| emh203 | 0:d0c18e423b13 | 439 | DWORD i; | 
| emh203 | 0:d0c18e423b13 | 440 | float RunningSum = 0; | 
| rjc19 | 1:871a329fd172 | 441 | |
| emh203 | 0:d0c18e423b13 | 442 | PrintfEnqueue(&PCBackDoorTx,"Zeroing ACS576.....\r\n"); | 
| rjc19 | 1:871a329fd172 | 443 | |
| emh203 | 0:d0c18e423b13 | 444 | ADCDataRdy=0; | 
| rjc19 | 1:871a329fd172 | 445 | |
| emh203 | 0:d0c18e423b13 | 446 | SamplesToTake = (DWORD)(SAMPLE_RATE)*2; | 
| rjc19 | 1:871a329fd172 | 447 | |
| rjc19 | 1:871a329fd172 | 448 | for(i=0; i<SamplesToTake; i++) { | 
| emh203 | 0:d0c18e423b13 | 449 | SmartSwitch_SetBackLightColor2((BYTE)((float)i/(float)SamplesToTake * 64)); | 
| rjc19 | 1:871a329fd172 | 450 | |
| rjc19 | 1:871a329fd172 | 451 | while(ADCDataRdy == FALSE) { | 
| rjc19 | 1:871a329fd172 | 452 | |
| emh203 | 0:d0c18e423b13 | 453 | } | 
| emh203 | 0:d0c18e423b13 | 454 | ADCDataRdy = FALSE; | 
| emh203 | 0:d0c18e423b13 | 455 | RunningSum += RobotBusCurrentHR; | 
| emh203 | 0:d0c18e423b13 | 456 | } | 
| rjc19 | 1:871a329fd172 | 457 | |
| emh203 | 0:d0c18e423b13 | 458 | ACS576_IOFFSET_TRIM += RunningSum / SamplesToTake; | 
| emh203 | 0:d0c18e423b13 | 459 | |
| emh203 | 0:d0c18e423b13 | 460 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 461 | |
| emh203 | 0:d0c18e423b13 | 462 | PrintfEnqueue(&PCBackDoorTx,"Exporting new configuration file.....\r\n>"); | 
| rjc19 | 1:871a329fd172 | 463 | |
| emh203 | 0:d0c18e423b13 | 464 | ExportConfigurationSettings(); | 
| emh203 | 0:d0c18e423b13 | 465 | } | 
| emh203 | 0:d0c18e423b13 | 466 | |
| emh203 | 0:d0c18e423b13 | 467 | |
| emh203 | 0:d0c18e423b13 | 468 | |
| emh203 | 0:d0c18e423b13 | 469 | |
| emh203 | 0:d0c18e423b13 | 470 | BOOL CheckforConfig(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 471 | { | 
| rjc19 | 1:871a329fd172 | 472 | if(!strcmp(LineIn,"config")) { | 
| emh203 | 0:d0c18e423b13 | 473 | LoadConfiguration(); | 
| emh203 | 0:d0c18e423b13 | 474 | } | 
| emh203 | 0:d0c18e423b13 | 475 | return TRUE; | 
| emh203 | 0:d0c18e423b13 | 476 | } | 
| emh203 | 0:d0c18e423b13 | 477 | |
| emh203 | 0:d0c18e423b13 | 478 | |
| emh203 | 0:d0c18e423b13 | 479 | BOOL CheckForTimeInit(CHAR * LineIn) | 
| emh203 | 0:d0c18e423b13 | 480 | { | 
| rjc19 | 1:871a329fd172 | 481 | if(!strcmp(LineIn,"tinit")) { | 
| emh203 | 0:d0c18e423b13 | 482 | set_time(1256729737); | 
| rjc19 | 1:871a329fd172 | 483 | PrintfEnqueue(&PCBackDoorTx,"\r\nTime Reset\r\n"); | 
| emh203 | 0:d0c18e423b13 | 484 | } | 
| rjc19 | 1:871a329fd172 | 485 | |
| emh203 | 0:d0c18e423b13 | 486 | return TRUE; | 
| emh203 | 0:d0c18e423b13 | 487 | |
| emh203 | 0:d0c18e423b13 | 488 | } | 
| emh203 | 0:d0c18e423b13 | 489 | |
| emh203 | 0:d0c18e423b13 | 490 | BOOL CheckForTime(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 491 | { | 
| emh203 | 0:d0c18e423b13 | 492 | int Hour,Minute,Second=0; | 
| emh203 | 0:d0c18e423b13 | 493 | int Items; | 
| emh203 | 0:d0c18e423b13 | 494 | BOOL Error = FALSE; | 
| rjc19 | 1:871a329fd172 | 495 | time_t TimeStampTemp; | 
| rjc19 | 1:871a329fd172 | 496 | |
| rjc19 | 1:871a329fd172 | 497 | |
| emh203 | 0:d0c18e423b13 | 498 | Items = sscanf(LineIn, "time=%d : %d : %d", &Hour, &Minute, &Second); | 
| rjc19 | 1:871a329fd172 | 499 | if(Items == 3) { | 
| emh203 | 0:d0c18e423b13 | 500 | PrintfEnqueue(&PCBackDoorTx,"\r\n"); | 
| rjc19 | 1:871a329fd172 | 501 | if(Hour>23) { | 
| emh203 | 0:d0c18e423b13 | 502 | PrintfEnqueue(&PCBackDoorTx,"Hour entry must be between 0 and 24\r\n"); | 
| emh203 | 0:d0c18e423b13 | 503 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 504 | } | 
| rjc19 | 1:871a329fd172 | 505 | if(Minute>60) { | 
| emh203 | 0:d0c18e423b13 | 506 | PrintfEnqueue(&PCBackDoorTx,"Minute entry must be between 0 and 60\r\n"); | 
| emh203 | 0:d0c18e423b13 | 507 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 508 | } | 
| rjc19 | 1:871a329fd172 | 509 | if(Second>60) { | 
| emh203 | 0:d0c18e423b13 | 510 | PrintfEnqueue(&PCBackDoorTx,"Second entry must be between 0 and 60\r\n"); | 
| emh203 | 0:d0c18e423b13 | 511 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 512 | } | 
| rjc19 | 1:871a329fd172 | 513 | |
| rjc19 | 1:871a329fd172 | 514 | if(Error == TRUE) { | 
| rjc19 | 1:871a329fd172 | 515 | PrintfEnqueue(&PCBackDoorTx,"Error in time format. Time not changed.\r\n"); | 
| rjc19 | 1:871a329fd172 | 516 | } else { | 
| emh203 | 0:d0c18e423b13 | 517 | TimeStampTemp = time(NULL); | 
| rjc19 | 1:871a329fd172 | 518 | //convert to tm struct | 
| emh203 | 0:d0c18e423b13 | 519 | CurrentTime = localtime(&TimeStampTemp); | 
| emh203 | 0:d0c18e423b13 | 520 | //dump in our new valus | 
| emh203 | 0:d0c18e423b13 | 521 | CurrentTime->tm_sec = Second; | 
| emh203 | 0:d0c18e423b13 | 522 | CurrentTime->tm_min = Minute; | 
| emh203 | 0:d0c18e423b13 | 523 | CurrentTime->tm_hour = Hour; | 
| emh203 | 0:d0c18e423b13 | 524 | //set the new time | 
| emh203 | 0:d0c18e423b13 | 525 | set_time(mktime(CurrentTime)); | 
| emh203 | 0:d0c18e423b13 | 526 | PrintfEnqueue(&PCBackDoorTx,"Time set to %d:%d:%d\r\n",Hour,Minute,Second); | 
| emh203 | 0:d0c18e423b13 | 527 | } | 
| rjc19 | 1:871a329fd172 | 528 | |
| rjc19 | 1:871a329fd172 | 529 | } | 
| rjc19 | 1:871a329fd172 | 530 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 531 | } | 
| emh203 | 0:d0c18e423b13 | 532 | |
| emh203 | 0:d0c18e423b13 | 533 | BOOL CheckForDate(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 534 | { | 
| emh203 | 0:d0c18e423b13 | 535 | int Day,Month,Year=0; | 
| emh203 | 0:d0c18e423b13 | 536 | int Items; | 
| emh203 | 0:d0c18e423b13 | 537 | BOOL Error = FALSE; | 
| emh203 | 0:d0c18e423b13 | 538 | time_t TimeStampTemp; | 
| rjc19 | 1:871a329fd172 | 539 | |
| emh203 | 0:d0c18e423b13 | 540 | Items = sscanf(LineIn, "date=%d / %d / %d", &Month, &Day, &Year); | 
| rjc19 | 1:871a329fd172 | 541 | if(Items == 3) { | 
| emh203 | 0:d0c18e423b13 | 542 | PrintfEnqueue(&PCBackDoorTx,"\r\n"); | 
| rjc19 | 1:871a329fd172 | 543 | if(Month>12 || Month < 1) { | 
| emh203 | 0:d0c18e423b13 | 544 | PrintfEnqueue(&PCBackDoorTx,"Month entry must be between 1 and 12\r\n"); | 
| emh203 | 0:d0c18e423b13 | 545 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 546 | } | 
| rjc19 | 1:871a329fd172 | 547 | if(Day>31 || Day<1) { | 
| emh203 | 0:d0c18e423b13 | 548 | PrintfEnqueue(&PCBackDoorTx,"Day entry must be between 1 and 31\r\n"); | 
| emh203 | 0:d0c18e423b13 | 549 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 550 | } | 
| rjc19 | 1:871a329fd172 | 551 | if(Year<1900) { | 
| emh203 | 0:d0c18e423b13 | 552 | PrintfEnqueue(&PCBackDoorTx,"Year entry must be greater than 1900\r\n"); | 
| emh203 | 0:d0c18e423b13 | 553 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 554 | } | 
| rjc19 | 1:871a329fd172 | 555 | |
| rjc19 | 1:871a329fd172 | 556 | if(Error == TRUE) { | 
| rjc19 | 1:871a329fd172 | 557 | PrintfEnqueue(&PCBackDoorTx,"Error in time format. Date not changed.\r\n"); | 
| rjc19 | 1:871a329fd172 | 558 | } else { | 
| emh203 | 0:d0c18e423b13 | 559 | //Get the current time in seconds since unix epoch | 
| emh203 | 0:d0c18e423b13 | 560 | TimeStampTemp = time(NULL); | 
| emh203 | 0:d0c18e423b13 | 561 | //convert to tm struct fom | 
| emh203 | 0:d0c18e423b13 | 562 | CurrentTime = localtime(&TimeStampTemp); | 
| emh203 | 0:d0c18e423b13 | 563 | //dump in our new valus | 
| emh203 | 0:d0c18e423b13 | 564 | CurrentTime->tm_mon = Month-1; | 
| emh203 | 0:d0c18e423b13 | 565 | CurrentTime->tm_mday = Day; | 
| emh203 | 0:d0c18e423b13 | 566 | CurrentTime->tm_year = Year - 1900; | 
| emh203 | 0:d0c18e423b13 | 567 | //set the new time | 
| emh203 | 0:d0c18e423b13 | 568 | set_time(mktime(CurrentTime)); | 
| emh203 | 0:d0c18e423b13 | 569 | PrintfEnqueue(&PCBackDoorTx,"Date set to %d/%d/%d\r\n",Month,Day,Year); | 
| emh203 | 0:d0c18e423b13 | 570 | } | 
| rjc19 | 1:871a329fd172 | 571 | |
| rjc19 | 1:871a329fd172 | 572 | } | 
| rjc19 | 1:871a329fd172 | 573 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 574 | } | 
| emh203 | 0:d0c18e423b13 | 575 | |
| emh203 | 0:d0c18e423b13 | 576 | |
| emh203 | 0:d0c18e423b13 | 577 | |
| emh203 | 0:d0c18e423b13 | 578 | void UpdateDisplay() | 
| emh203 | 0:d0c18e423b13 | 579 | { | 
| emh203 | 0:d0c18e423b13 | 580 | |
| rjc19 | 1:871a329fd172 | 581 | if(DisplayShutOffTick > DISPLAY_SHUTOFF_TIME) { | 
| emh203 | 0:d0c18e423b13 | 582 | DisplayMode = DISPLAY_OFF; | 
| emh203 | 0:d0c18e423b13 | 583 | SmartSwitchClear(); | 
| rjc19 | 1:871a329fd172 | 584 | PowerDownSmartSwitch(); | 
| rjc19 | 1:871a329fd172 | 585 | } else { | 
| rjc19 | 1:871a329fd172 | 586 | if(DisplayUpdateTick > 25) { | 
| emh203 | 0:d0c18e423b13 | 587 | GFX_FullDisplayBufferClear(&BackBuffer); | 
| emh203 | 0:d0c18e423b13 | 588 | DisplayUpdateTick = 0; | 
| rjc19 | 1:871a329fd172 | 589 | SmartSwitch_SetBrightnss(0); | 
| rjc19 | 1:871a329fd172 | 590 | switch(DisplayMode) { | 
| rjc19 | 1:871a329fd172 | 591 | default: | 
| rjc19 | 1:871a329fd172 | 592 | case DISPLAY_MEASUREMENTS: | 
| rjc19 | 1:871a329fd172 | 593 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 594 | GFX_DrawString(&BackBuffer,"Robot Bus",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 595 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 596 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 597 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 598 | |
| rjc19 | 1:871a329fd172 | 599 | GFX_printf(&BackBuffer,0,16,&Font5x7,"V: %.2fv",RobotBusVoltageHR); | 
| rjc19 | 1:871a329fd172 | 600 | GFX_printf(&BackBuffer,0,24,&Font5x7,"I: %.2fa",RobotBusCurrentHR); | 
| emh203 | 0:d0c18e423b13 | 601 | break; | 
| rjc19 | 1:871a329fd172 | 602 | |
| rjc19 | 1:871a329fd172 | 603 | case DISPLAY_SERIAL_STATUS: | 
| rjc19 | 1:871a329fd172 | 604 | |
| rjc19 | 3:d55665050fcb | 605 | //SmartSwitch_SetBrightnss(LastSerialBrightness); | 
| rjc19 | 3:d55665050fcb | 606 | SmartSwitch_SetBackLightColor(3,0,3); | 
| rjc19 | 1:871a329fd172 | 607 | GFX_DrawString(&BackBuffer,"Serial Log",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 608 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 609 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 610 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 3:d55665050fcb | 611 | TranslateToText(); | 
| rjc19 | 1:871a329fd172 | 612 | if(SystemState != SYSTEM_STATE_SERIAL_LOGGING){ | 
| rjc19 | 3:d55665050fcb | 613 | GFX_printf(&BackBuffer,0,16,&Font5x7,"Rate %s",&SpeedString[0]); | 
| rjc19 | 1:871a329fd172 | 614 | GFX_printf(&BackBuffer,0,24,&Font5x7,"Not Logging"); | 
| rjc19 | 1:871a329fd172 | 615 | } | 
| rjc19 | 1:871a329fd172 | 616 | else{ //we are logging | 
| rjc19 | 3:d55665050fcb | 617 | GFX_printf(&BackBuffer,0,16,&Font5x7,"C-%d",SerialCount); | 
| rjc19 | 3:d55665050fcb | 618 | GFX_printf(&BackBuffer,0,24,&Font5x7,"Logging"); | 
| rjc19 | 3:d55665050fcb | 619 | SmartSwitch_SetBackLightColor(0,0,3); | 
| rjc19 | 1:871a329fd172 | 620 | } | 
| rjc19 | 1:871a329fd172 | 621 | break; | 
| rjc19 | 1:871a329fd172 | 622 | |
| rjc19 | 1:871a329fd172 | 623 | case DISPLAY_BATTERY: | 
| rjc19 | 1:871a329fd172 | 624 | SmartSwitch_SetBackLightColor(3,3,0); | 
| rjc19 | 1:871a329fd172 | 625 | GFX_DrawString(&BackBuffer,"Battery",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 626 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 627 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 628 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 629 | |
| rjc19 | 1:871a329fd172 | 630 | GFX_printf(&BackBuffer,0,16,&Font5x7,"V: %.1fv",BatteryVoltage); | 
| rjc19 | 1:871a329fd172 | 631 | |
| emh203 | 0:d0c18e423b13 | 632 | break; | 
| rjc19 | 1:871a329fd172 | 633 | |
| rjc19 | 1:871a329fd172 | 634 | case DISPLAY_DATE_TIME: | 
| rjc19 | 1:871a329fd172 | 635 | SmartSwitch_SetBackLightColor(1,3,0); | 
| rjc19 | 1:871a329fd172 | 636 | GFX_DrawString(&BackBuffer,"Date/Time",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 637 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 638 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 639 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 640 | |
| rjc19 | 1:871a329fd172 | 641 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 642 | strftime(DTBuf, 32, "%m.%d.%Y", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 643 | GFX_printf(&BackBuffer,0,16,&Font5x7,"%s",DTBuf); | 
| rjc19 | 1:871a329fd172 | 644 | |
| rjc19 | 1:871a329fd172 | 645 | strftime(DTBuf, 32, "%H:%M:%S", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 646 | GFX_printf(&BackBuffer,0,24,&Font5x7,"%s",DTBuf); | 
| emh203 | 0:d0c18e423b13 | 647 | break; | 
| rjc19 | 1:871a329fd172 | 648 | |
| rjc19 | 1:871a329fd172 | 649 | case DISPLAY_BUFFER_STATS: | 
| rjc19 | 1:871a329fd172 | 650 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 651 | GFX_DrawString(&BackBuffer,"Buf Status",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 652 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 653 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 654 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 655 | GFX_printf(&BackBuffer,0,16,&Font3x5,"R/W Diff:"); | 
| rjc19 | 1:871a329fd172 | 656 | GFX_printf(&BackBuffer,0,24,&Font3x5,"%04d/%d",ReadWriteDifferential,DATA_BLOCK_SIZE); | 
| emh203 | 0:d0c18e423b13 | 657 | break; | 
| rjc19 | 1:871a329fd172 | 658 | |
| rjc19 | 1:871a329fd172 | 659 | case DISPLAY_FIRMWARE_VERSION: | 
| rjc19 | 1:871a329fd172 | 660 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 661 | GFX_DrawString(&BackBuffer,"Firmware Version",0,0,&Font3x5); | 
| rjc19 | 1:871a329fd172 | 662 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 663 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 664 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 665 | GFX_printf(&BackBuffer,19,20,&Font5x7,"%d.%d",FIRMWARE_VERSION_MAJOR,FIRMWARE_VERSION_MINOR); | 
| emh203 | 0:d0c18e423b13 | 666 | break; | 
| rjc19 | 1:871a329fd172 | 667 | |
| rjc19 | 1:871a329fd172 | 668 | case DISPLAY_ID: | 
| rjc19 | 1:871a329fd172 | 669 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 670 | GFX_DrawString(&BackBuffer,"ID",0,0,&Font3x5); | 
| rjc19 | 1:871a329fd172 | 671 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 672 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 673 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 674 | GFX_printf(&BackBuffer,0,20,&Font5x7,"%s",ID); | 
| emh203 | 0:d0c18e423b13 | 675 | break; | 
| rjc19 | 1:871a329fd172 | 676 | |
| rjc19 | 1:871a329fd172 | 677 | case DISPLAY_CARD_STATUS: | 
| rjc19 | 1:871a329fd172 | 678 | |
| rjc19 | 1:871a329fd172 | 679 | if(1) { | 
| rjc19 | 1:871a329fd172 | 680 | |
| rjc19 | 1:871a329fd172 | 681 | switch(SystemState) { | 
| emh203 | 0:d0c18e423b13 | 682 | default: | 
| emh203 | 0:d0c18e423b13 | 683 | case SYSTEM_STATE_IDLE: | 
| rjc19 | 1:871a329fd172 | 684 | switch(LastBackLightColor) { | 
| emh203 | 0:d0c18e423b13 | 685 | default: | 
| emh203 | 0:d0c18e423b13 | 686 | case SMART_SWITCH_BACKLIGHT_GREEN: | 
| rjc19 | 1:871a329fd172 | 687 | LastBackLightColor = SMART_SWITCH_BACKLIGHT_YELLOW; | 
| rjc19 | 1:871a329fd172 | 688 | SmartSwitch_SetBackLightColor2(LastBackLightColor); | 
| rjc19 | 1:871a329fd172 | 689 | break; | 
| rjc19 | 1:871a329fd172 | 690 | |
| emh203 | 0:d0c18e423b13 | 691 | case SMART_SWITCH_BACKLIGHT_YELLOW: | 
| emh203 | 0:d0c18e423b13 | 692 | LastBackLightColor = SMART_SWITCH_BACKLIGHT_GREEN; | 
| emh203 | 0:d0c18e423b13 | 693 | SmartSwitch_SetBackLightColor2(LastBackLightColor); | 
| rjc19 | 1:871a329fd172 | 694 | break; | 
| rjc19 | 1:871a329fd172 | 695 | } | 
| rjc19 | 1:871a329fd172 | 696 | |
| rjc19 | 1:871a329fd172 | 697 | |
| rjc19 | 1:871a329fd172 | 698 | if(DataLogError == TRUE) { | 
| rjc19 | 1:871a329fd172 | 699 | GFX_DrawString(&BackBuffer,"Error!",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 700 | GFX_DrawString(&BackBuffer,ErrorMsg,0,16,&Font3x5); | 
| rjc19 | 1:871a329fd172 | 701 | } else { | 
| rjc19 | 1:871a329fd172 | 702 | GFX_DrawString(&BackBuffer,"SD Detected",0,16,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 703 | GFX_DrawString(&BackBuffer,"Idle....",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 704 | GFX_DrawString(&BackBuffer,"Not Logging",0,24,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 705 | } | 
| rjc19 | 1:871a329fd172 | 706 | break; | 
| rjc19 | 1:871a329fd172 | 707 | |
| rjc19 | 1:871a329fd172 | 708 | |
| emh203 | 0:d0c18e423b13 | 709 | case SYSTEM_STATE_LOGGING: | 
| emh203 | 0:d0c18e423b13 | 710 | SmartSwitch_SetBackLightColor2(SMART_SWITCH_BACKLIGHT_GREEN); | 
| rjc19 | 1:871a329fd172 | 711 | |
| emh203 | 0:d0c18e423b13 | 712 | GFX_DrawString(&BackBuffer,"Logging Data....",0,0,&Font5x7); | 
| emh203 | 0:d0c18e423b13 | 713 | GFX_DrawString(&BackBuffer,&CurrentLogFileName[4],0,16,&Font5x7); | 
| emh203 | 0:d0c18e423b13 | 714 | GFX_printf(&BackBuffer,0,26,&Font3x5,"Block: %d",DataBlocksWritten); | 
| rjc19 | 1:871a329fd172 | 715 | |
| rjc19 | 1:871a329fd172 | 716 | break; | 
| rjc19 | 1:871a329fd172 | 717 | } | 
| rjc19 | 1:871a329fd172 | 718 | } else { | 
| rjc19 | 1:871a329fd172 | 719 | GFX_DrawString(&BackBuffer,"No SD Card!",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 720 | |
| rjc19 | 1:871a329fd172 | 721 | switch(LastBackLightColor) { | 
| rjc19 | 1:871a329fd172 | 722 | default: | 
| rjc19 | 1:871a329fd172 | 723 | case SMART_SWITCH_BACKLIGHT_RED: | 
| rjc19 | 1:871a329fd172 | 724 | LastBackLightColor = SMART_SWITCH_BACKLIGHT_YELLOW; | 
| rjc19 | 1:871a329fd172 | 725 | SmartSwitch_SetBackLightColor2(LastBackLightColor); | 
| emh203 | 0:d0c18e423b13 | 726 | break; | 
| rjc19 | 1:871a329fd172 | 727 | |
| rjc19 | 1:871a329fd172 | 728 | case SMART_SWITCH_BACKLIGHT_YELLOW: | 
| rjc19 | 1:871a329fd172 | 729 | LastBackLightColor = SMART_SWITCH_BACKLIGHT_RED; | 
| rjc19 | 1:871a329fd172 | 730 | SmartSwitch_SetBackLightColor2(LastBackLightColor); | 
| emh203 | 0:d0c18e423b13 | 731 | break; | 
| rjc19 | 1:871a329fd172 | 732 | } | 
| rjc19 | 1:871a329fd172 | 733 | } | 
| rjc19 | 1:871a329fd172 | 734 | |
| rjc19 | 1:871a329fd172 | 735 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 736 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 737 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 738 | |
| emh203 | 0:d0c18e423b13 | 739 | break; | 
| rjc19 | 1:871a329fd172 | 740 | } | 
| rjc19 | 1:871a329fd172 | 741 | GFX_DumpRenderContextToPhysicalScreen(&BackBuffer); | 
| emh203 | 0:d0c18e423b13 | 742 | } | 
| emh203 | 0:d0c18e423b13 | 743 | } | 
| emh203 | 0:d0c18e423b13 | 744 | } | 
| emh203 | 0:d0c18e423b13 | 745 | |
| emh203 | 0:d0c18e423b13 | 746 | |
| emh203 | 0:d0c18e423b13 | 747 | void CheckSDCardStatus() | 
| emh203 | 0:d0c18e423b13 | 748 | { | 
| emh203 | 0:d0c18e423b13 | 749 | //Make sure that the SD card stays in while logging | 
| rjc19 | 1:871a329fd172 | 750 | switch(SystemState) { | 
| emh203 | 0:d0c18e423b13 | 751 | case SYSTEM_STATE_LOGGING: | 
| emh203 | 0:d0c18e423b13 | 752 | //if(SDCardDetect == 0) | 
| rjc19 | 1:871a329fd172 | 753 | { | 
| rjc19 | 1:871a329fd172 | 754 | //Gracefully shut the logging system down..... | 
| rjc19 | 1:871a329fd172 | 755 | // EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 756 | } | 
| emh203 | 0:d0c18e423b13 | 757 | break; | 
| rjc19 | 1:871a329fd172 | 758 | |
| emh203 | 0:d0c18e423b13 | 759 | default: | 
| rjc19 | 1:871a329fd172 | 760 | break; | 
| rjc19 | 1:871a329fd172 | 761 | } | 
| emh203 | 0:d0c18e423b13 | 762 | } | 
| emh203 | 0:d0c18e423b13 | 763 | |
| emh203 | 0:d0c18e423b13 | 764 | |
| emh203 | 0:d0c18e423b13 | 765 | void LogData() | 
| emh203 | 0:d0c18e423b13 | 766 | { | 
| emh203 | 0:d0c18e423b13 | 767 | WORD i; | 
| emh203 | 0:d0c18e423b13 | 768 | int ElementsToWrite; | 
| emh203 | 0:d0c18e423b13 | 769 | UINT BytesWritten; | 
| rjc19 | 1:871a329fd172 | 770 | |
| rjc19 | 1:871a329fd172 | 771 | if(RobotBusVoltageHR < 9) { | 
| rjc19 | 1:871a329fd172 | 772 | // EnterSystemState(SYSTEM_STATE_IDLE); | 
| emh203 | 0:d0c18e423b13 | 773 | return; | 
| emh203 | 0:d0c18e423b13 | 774 | } | 
| rjc19 | 1:871a329fd172 | 775 | |
| rjc19 | 1:871a329fd172 | 776 | if(DataLogError == TRUE) { | 
| emh203 | 0:d0c18e423b13 | 777 | //EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 778 | } else { | 
| rjc19 | 1:871a329fd172 | 779 | if(MyDataBlock.ReadInPtr < MyDataBlock.WriteOutPtr) { | 
| rjc19 | 1:871a329fd172 | 780 | ElementsToWrite = MyDataBlock.ReadInPtr + (DATA_BLOCK_SIZE - MyDataBlock.WriteOutPtr); | 
| rjc19 | 1:871a329fd172 | 781 | } else { | 
| emh203 | 0:d0c18e423b13 | 782 | ElementsToWrite = MyDataBlock.ReadInPtr - MyDataBlock.WriteOutPtr; | 
| emh203 | 0:d0c18e423b13 | 783 | } | 
| rjc19 | 1:871a329fd172 | 784 | |
| rjc19 | 1:871a329fd172 | 785 | if(ElementsToWrite > WRITE_BLOCK_THRESH) { | 
| rjc19 | 1:871a329fd172 | 786 | for(i=0; i<ElementsToWrite; i++) { | 
| rjc19 | 1:871a329fd172 | 787 | BinaryDataCachePtr += sprintf((char *)&BinaryDataCache[BinaryDataCachePtr],"%d,%.2f,%.2f\r\n",DataPointIndex,MyDataBlock.Voltage[MyDataBlock.WriteOutPtr],MyDataBlock.Current[MyDataBlock.WriteOutPtr]); | 
| rjc19 | 1:871a329fd172 | 788 | if(BinaryDataCachePtr>=BINARY_WRITE_CACHE_THRESHOLD) { | 
| rjc19 | 1:871a329fd172 | 789 | EXT_LED0 = 1; | 
| rjc19 | 1:871a329fd172 | 790 | f_write(&CurrentLogFileHandle,BinaryDataCache,BinaryDataCachePtr,&BytesWritten); | 
| rjc19 | 1:871a329fd172 | 791 | |
| rjc19 | 1:871a329fd172 | 792 | BinaryDataCachePtr = 0; | 
| rjc19 | 1:871a329fd172 | 793 | |
| rjc19 | 1:871a329fd172 | 794 | EXT_LED0=0; | 
| emh203 | 0:d0c18e423b13 | 795 | } | 
| rjc19 | 1:871a329fd172 | 796 | DataPointIndex++; | 
| rjc19 | 1:871a329fd172 | 797 | MyDataBlock.WriteOutPtr++; | 
| rjc19 | 1:871a329fd172 | 798 | if(MyDataBlock.WriteOutPtr == DATA_BLOCK_SIZE) { | 
| rjc19 | 1:871a329fd172 | 799 | MyDataBlock.WriteOutPtr = 0; | 
| rjc19 | 1:871a329fd172 | 800 | } | 
| rjc19 | 1:871a329fd172 | 801 | } | 
| rjc19 | 1:871a329fd172 | 802 | if(WritesSinceLastFlush > NUM_WRITES_BEFORE_FLUSH) { | 
| rjc19 | 1:871a329fd172 | 803 | f_close(&CurrentLogFileHandle); | 
| rjc19 | 1:871a329fd172 | 804 | WritesSinceLastFlush = 0; | 
| rjc19 | 1:871a329fd172 | 805 | f_open(&CurrentLogFileHandle,&CurrentLogFileName[0],FA_WRITE | FA_OPEN_ALWAYS); | 
| rjc19 | 1:871a329fd172 | 806 | f_lseek(&CurrentLogFileHandle, CurrentLogFileHandle.fsize); | 
| rjc19 | 1:871a329fd172 | 807 | } | 
| rjc19 | 1:871a329fd172 | 808 | DataBlocksWritten++; | 
| rjc19 | 1:871a329fd172 | 809 | } | 
| emh203 | 0:d0c18e423b13 | 810 | } | 
| emh203 | 0:d0c18e423b13 | 811 | } | 
| emh203 | 0:d0c18e423b13 | 812 | |
| emh203 | 0:d0c18e423b13 | 813 | |
| emh203 | 0:d0c18e423b13 | 814 | |
| emh203 | 0:d0c18e423b13 | 815 | void DisplayBootMsg() | 
| emh203 | 0:d0c18e423b13 | 816 | { | 
| rjc19 | 1:871a329fd172 | 817 | PrintfEnqueue(&PCBackDoorTx,"\r\n\r\n"); | 
| rjc19 | 1:871a329fd172 | 818 | PrintfEnqueue(&PCBackDoorTx,".______ _______. __ __ ___ .______ __ \r\n"); | 
| rjc19 | 1:871a329fd172 | 819 | PrintfEnqueue(&PCBackDoorTx,"| _ \\ / || | | | / \\ | _ \\ | | \r\n"); | 
| rjc19 | 1:871a329fd172 | 820 | PrintfEnqueue(&PCBackDoorTx,"| |_) | | (----`| | | | ______ / ^ \\ | |_) | | | \r\n"); | 
| rjc19 | 1:871a329fd172 | 821 | PrintfEnqueue(&PCBackDoorTx,"| ___/ \\ \\ | | | | |______/ /_\\ \\ | / | | \r\n"); | 
| rjc19 | 1:871a329fd172 | 822 | PrintfEnqueue(&PCBackDoorTx,"| | .----) | | `--' | / _____ \\ | |\\ \\----.| `----.\r\n"); | 
| rjc19 | 1:871a329fd172 | 823 | PrintfEnqueue(&PCBackDoorTx,"| _| |_______/ \\______/ /__/ \\__\\ | _| `._____||_______|\r\n"); | 
| rjc19 | 1:871a329fd172 | 824 | PrintfEnqueue(&PCBackDoorTx,"---------------------------------------------------------------------------\r\n"); | 
| rjc19 | 1:871a329fd172 | 825 | PrintfEnqueue(&PCBackDoorTx,"Robot Power Logger Control Terminal\r\n\r\n>"); | 
| emh203 | 0:d0c18e423b13 | 826 | } | 
| emh203 | 0:d0c18e423b13 | 827 | 
