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@1:871a329fd172, 2012-09-21 (annotated)
- Committer:
- rjc19
- Date:
- Fri Sep 21 18:06:47 2012 +0000
- Revision:
- 1:871a329fd172
- Parent:
- 0:d0c18e423b13
- Child:
- 3:d55665050fcb
First Attempt at logging serial data from CM_PWR ... Added Serial logger function and display
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; | 
| emh203 | 0:d0c18e423b13 | 69 | |
| 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 | 1:871a329fd172 | 150 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 151 | } | 
| rjc19 | 1:871a329fd172 | 152 | else{ | 
| rjc19 | 1:871a329fd172 | 153 | SystemState=SYSTEM_STATE_IDLE; | 
| rjc19 | 1:871a329fd172 | 154 | } | 
| rjc19 | 1:871a329fd172 | 155 | break; | 
| rjc19 | 1:871a329fd172 | 156 | |
| emh203 | 0:d0c18e423b13 | 157 | case SYSTEM_STATE_IDLE: | 
| emh203 | 0:d0c18e423b13 | 158 | DisplayMode = DISPLAY_CARD_STATUS; | 
| rjc19 | 1:871a329fd172 | 159 | switch (SystemState){ | 
| rjc19 | 1:871a329fd172 | 160 | case SYSTEM_STATE_SERIAL_LOGGING: | 
| rjc19 | 1:871a329fd172 | 161 | DisplayMode=DISPLAY_SERIAL_STATUS; //Need to stay here for serial logging | 
| rjc19 | 1:871a329fd172 | 162 | //NO BREAK ON PURPOSE | 
| rjc19 | 1:871a329fd172 | 163 | |
| rjc19 | 1:871a329fd172 | 164 | case SYSTEM_STATE_LOGGING: | 
| rjc19 | 1:871a329fd172 | 165 | f_close(&CurrentLogFileHandle); | 
| rjc19 | 1:871a329fd172 | 166 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 167 | PrintfEnqueue(&PCBackDoorTx,"Logging terminated on file %s\r\n>",CurrentLogFileName); | 
| rjc19 | 1:871a329fd172 | 168 | break; | 
| emh203 | 0:d0c18e423b13 | 169 | } | 
| emh203 | 0:d0c18e423b13 | 170 | SystemState = NextState; | 
| rjc19 | 1:871a329fd172 | 171 | break; | 
| emh203 | 0:d0c18e423b13 | 172 | } | 
| emh203 | 0:d0c18e423b13 | 173 | } | 
| emh203 | 0:d0c18e423b13 | 174 | |
| emh203 | 0:d0c18e423b13 | 175 | BOOL InitDataLog() | 
| emh203 | 0:d0c18e423b13 | 176 | { | 
| emh203 | 0:d0c18e423b13 | 177 | UINT BytesWritten; | 
| rjc19 | 1:871a329fd172 | 178 | |
| emh203 | 0:d0c18e423b13 | 179 | PrintfEnqueue(&PCBackDoorTx,"\r\n\r\bInitializing Data log....\r\n"); | 
| emh203 | 0:d0c18e423b13 | 180 | CreateLogFileName(); | 
| emh203 | 0:d0c18e423b13 | 181 | PrintfEnqueue(&PCBackDoorTx,"Filename: %s\r\n",CurrentLogFileName); | 
| emh203 | 0:d0c18e423b13 | 182 | PrintfEnqueue(&PCBackDoorTx,"Attempting File Open....\r\n"); | 
| rjc19 | 1:871a329fd172 | 183 | |
| rjc19 | 1:871a329fd172 | 184 | |
| emh203 | 0:d0c18e423b13 | 185 | f_mount(0,&MyFileSystem); | 
| rjc19 | 1:871a329fd172 | 186 | if(f_open(&CurrentLogFileHandle,&CurrentLogFileName[0],FA_WRITE | FA_OPEN_ALWAYS) != FR_OK) { | 
| rjc19 | 1:871a329fd172 | 187 | DataLogError = TRUE; | 
| rjc19 | 1:871a329fd172 | 188 | PrintfEnqueue(&PCBackDoorTx,"Could not open file!\r\n>"); | 
| rjc19 | 1:871a329fd172 | 189 | ErrorMsg = "Write Error!"; | 
| rjc19 | 1:871a329fd172 | 190 | return TRUE; | 
| rjc19 | 1:871a329fd172 | 191 | } | 
| emh203 | 0:d0c18e423b13 | 192 | |
| emh203 | 0:d0c18e423b13 | 193 | |
| rjc19 | 1:871a329fd172 | 194 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 195 | PrintfEnqueue(&PCBackDoorTx,"Writing Headers....\r\n"); | 
| rjc19 | 1:871a329fd172 | 196 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 197 | strftime(DTBuf,128, "%Y.%m.%d", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 198 | f_printf(&CurrentLogFileHandle, "Date %s\r\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 199 | strftime(DTBuf,128, "%H:%M:%S", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 200 | f_printf(&CurrentLogFileHandle, "Time %s\r\n\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 201 | sprintf(DTBuf, "Sample Rate %.1f Hz\r\n\r\n",SAMPLE_RATE); | 
| rjc19 | 1:871a329fd172 | 202 | f_write(&CurrentLogFileHandle,DTBuf,strlen(DTBuf),&BytesWritten); | 
| rjc19 | 1:871a329fd172 | 203 | PrintfEnqueue(&PCBackDoorTx,"Headers Written.... Starting log\r\n"); | 
| rjc19 | 1:871a329fd172 | 204 | |
| rjc19 | 1:871a329fd172 | 205 | |
| rjc19 | 1:871a329fd172 | 206 | PrintfEnqueue(&PCBackDoorTx,"\r\n>"); | 
| rjc19 | 1:871a329fd172 | 207 | |
| rjc19 | 1:871a329fd172 | 208 | |
| rjc19 | 1:871a329fd172 | 209 | |
| emh203 | 0:d0c18e423b13 | 210 | BinaryDataCachePtr = 0; | 
| emh203 | 0:d0c18e423b13 | 211 | WritesSinceLastFlush = 0; | 
| rjc19 | 1:871a329fd172 | 212 | |
| emh203 | 0:d0c18e423b13 | 213 | DataBlocksWritten = 0; | 
| emh203 | 0:d0c18e423b13 | 214 | DataPointIndex = 0; | 
| emh203 | 0:d0c18e423b13 | 215 | |
| emh203 | 0:d0c18e423b13 | 216 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 217 | } | 
| emh203 | 0:d0c18e423b13 | 218 | |
| rjc19 | 1:871a329fd172 | 219 | BOOL InitSerialDataLog() | 
| rjc19 | 1:871a329fd172 | 220 | { | 
| rjc19 | 1:871a329fd172 | 221 | PrintfEnqueue(&PCBackDoorTx,"\r\n\r\bInitializing Data log....\r\n"); | 
| rjc19 | 1:871a329fd172 | 222 | CreateLogFileName(); | 
| rjc19 | 1:871a329fd172 | 223 | PrintfEnqueue(&PCBackDoorTx,"Filename: %s\r\n",CurrentLogFileName); | 
| rjc19 | 1:871a329fd172 | 224 | PrintfEnqueue(&PCBackDoorTx,"Attempting File Open....\r\n"); | 
| rjc19 | 1:871a329fd172 | 225 | |
| rjc19 | 1:871a329fd172 | 226 | |
| rjc19 | 1:871a329fd172 | 227 | f_mount(0,&MyFileSystem); | 
| rjc19 | 1:871a329fd172 | 228 | if(f_open(&CurrentLogFileHandle,&CurrentLogFileName[0],FA_WRITE | FA_OPEN_ALWAYS) != FR_OK) { | 
| rjc19 | 1:871a329fd172 | 229 | DataLogError = TRUE; | 
| rjc19 | 1:871a329fd172 | 230 | PrintfEnqueue(&PCBackDoorTx,"Could not open file!\r\n>"); | 
| rjc19 | 1:871a329fd172 | 231 | ErrorMsg = "Write Error!"; | 
| rjc19 | 1:871a329fd172 | 232 | f_mount(0,0); | 
| rjc19 | 1:871a329fd172 | 233 | return TRUE; | 
| rjc19 | 1:871a329fd172 | 234 | } | 
| rjc19 | 1:871a329fd172 | 235 | |
| rjc19 | 1:871a329fd172 | 236 | |
| rjc19 | 1:871a329fd172 | 237 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 238 | PrintfEnqueue(&PCBackDoorTx,"Writing Headers....\r\n"); | 
| rjc19 | 1:871a329fd172 | 239 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 240 | f_printf(&CurrentLogFileHandle,"Rate,V1,C1,V2,C2,V3,C3,V4,C4,V5,C5,V6,C6,B1V,B1C,B2V,B2C,"); | 
| rjc19 | 1:871a329fd172 | 241 | strftime(DTBuf,128, "%Y.%m.%d", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 242 | |
| rjc19 | 1:871a329fd172 | 243 | f_printf(&CurrentLogFileHandle, "Date ,%s,",DTBuf); | 
| rjc19 | 1:871a329fd172 | 244 | strftime(DTBuf,128, "%H:%M:%S", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 245 | f_printf(&CurrentLogFileHandle, "Time ,%s\r\n\n",DTBuf); | 
| rjc19 | 1:871a329fd172 | 246 | |
| rjc19 | 1:871a329fd172 | 247 | // sprintf(DTBuf, "Sample Rate %.1f Hz\r\n\r\n",SAMPLE_RATE); | 
| rjc19 | 1:871a329fd172 | 248 | // f_write(&CurrentLogFileHandle,DTBuf,strlen(DTBuf),&BytesWritten); | 
| rjc19 | 1:871a329fd172 | 249 | f_sync(&CurrentLogFileHandle); | 
| rjc19 | 1:871a329fd172 | 250 | PrintfEnqueue(&PCBackDoorTx,"Headers Written.... Starting log\r\n"); | 
| rjc19 | 1:871a329fd172 | 251 | |
| rjc19 | 1:871a329fd172 | 252 | |
| rjc19 | 1:871a329fd172 | 253 | PrintfEnqueue(&PCBackDoorTx,"\r\n>"); | 
| rjc19 | 1:871a329fd172 | 254 | SerialLineBufferPtr=0; | 
| rjc19 | 1:871a329fd172 | 255 | return FALSE; | 
| rjc19 | 1:871a329fd172 | 256 | } | 
| emh203 | 0:d0c18e423b13 | 257 | |
| emh203 | 0:d0c18e423b13 | 258 | void CreateLogFileName() | 
| emh203 | 0:d0c18e423b13 | 259 | { | 
| rjc19 | 1:871a329fd172 | 260 | time(&CurrentTime_InSec); | 
| rjc19 | 1:871a329fd172 | 261 | strftime(CurrentLogFileName,256, "F%Y.%m.%d.%H.%M.%S.csv", localtime(&CurrentTime_InSec)); | 
| rjc19 | 1:871a329fd172 | 262 | } | 
| emh203 | 0:d0c18e423b13 | 263 | |
| emh203 | 0:d0c18e423b13 | 264 | |
| emh203 | 0:d0c18e423b13 | 265 | |
| emh203 | 0:d0c18e423b13 | 266 | void SystemTickIrq() | 
| emh203 | 0:d0c18e423b13 | 267 | { | 
| emh203 | 0:d0c18e423b13 | 268 | if(UpdateHostTerminalTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 269 | UpdateHostTerminalTick++; | 
| rjc19 | 1:871a329fd172 | 270 | |
| emh203 | 0:d0c18e423b13 | 271 | if(DisplayUpdateTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 272 | DisplayUpdateTick++; | 
| rjc19 | 1:871a329fd172 | 273 | |
| emh203 | 0:d0c18e423b13 | 274 | if(ButtonCheckTick<0xFFFF) | 
| rjc19 | 1:871a329fd172 | 275 | ButtonCheckTick++; | 
| rjc19 | 1:871a329fd172 | 276 | |
| rjc19 | 1:871a329fd172 | 277 | if(DisplayShutOffTick<0xFFFF) | 
| emh203 | 0:d0c18e423b13 | 278 | DisplayShutOffTick++; | 
| emh203 | 0:d0c18e423b13 | 279 | } | 
| emh203 | 0:d0c18e423b13 | 280 | |
| emh203 | 0:d0c18e423b13 | 281 | void InitButton() | 
| emh203 | 0:d0c18e423b13 | 282 | { | 
| emh203 | 0:d0c18e423b13 | 283 | ButtonCheckState = WAITING_FOR_PRESS; | 
| emh203 | 0:d0c18e423b13 | 284 | ButtonCheckTick = 0; | 
| emh203 | 0:d0c18e423b13 | 285 | PreviousButtonState = FALSE; | 
| emh203 | 0:d0c18e423b13 | 286 | CurrentButtonState = FALSE; | 
| emh203 | 0:d0c18e423b13 | 287 | |
| emh203 | 0:d0c18e423b13 | 288 | } | 
| emh203 | 0:d0c18e423b13 | 289 | void CheckButton() | 
| emh203 | 0:d0c18e423b13 | 290 | { | 
| rjc19 | 1:871a329fd172 | 291 | if(ButtonCheckTick>0) { | 
| emh203 | 0:d0c18e423b13 | 292 | ButtonCheckTick = 0; | 
| rjc19 | 1:871a329fd172 | 293 | |
| emh203 | 0:d0c18e423b13 | 294 | PreviousButtonState = CurrentButtonState; | 
| rjc19 | 1:871a329fd172 | 295 | CurrentButtonState = ActionButton.read(); | 
| rjc19 | 1:871a329fd172 | 296 | |
| rjc19 | 1:871a329fd172 | 297 | switch(ButtonCheckState) { | 
| emh203 | 0:d0c18e423b13 | 298 | default: | 
| emh203 | 0:d0c18e423b13 | 299 | case WAITING_FOR_PRESS: | 
| rjc19 | 1:871a329fd172 | 300 | |
| rjc19 | 1:871a329fd172 | 301 | if(CurrentButtonState == TRUE && PreviousButtonState == FALSE) { | 
| rjc19 | 1:871a329fd172 | 302 | ButtonCheckState = WAITING_FOR_RELEASE; | 
| rjc19 | 1:871a329fd172 | 303 | } | 
| rjc19 | 1:871a329fd172 | 304 | |
| rjc19 | 1:871a329fd172 | 305 | ButtonHoldTime = 0; | 
| rjc19 | 1:871a329fd172 | 306 | |
| rjc19 | 1:871a329fd172 | 307 | break; | 
| rjc19 | 1:871a329fd172 | 308 | |
| emh203 | 0:d0c18e423b13 | 309 | case WAITING_FOR_RELEASE: | 
| rjc19 | 1:871a329fd172 | 310 | |
| rjc19 | 1:871a329fd172 | 311 | if(CurrentButtonState == TRUE && PreviousButtonState == TRUE) { | 
| rjc19 | 1:871a329fd172 | 312 | ButtonHoldTime++; | 
| rjc19 | 1:871a329fd172 | 313 | } else if(CurrentButtonState == FALSE && PreviousButtonState == TRUE) { | 
| rjc19 | 1:871a329fd172 | 314 | ActionButtonHandler(ButtonHoldTime); | 
| rjc19 | 1:871a329fd172 | 315 | ButtonCheckState = WAITING_FOR_PRESS; | 
| rjc19 | 1:871a329fd172 | 316 | } else { | 
| rjc19 | 1:871a329fd172 | 317 | ButtonCheckState = WAITING_FOR_PRESS; | 
| rjc19 | 1:871a329fd172 | 318 | } | 
| rjc19 | 1:871a329fd172 | 319 | break; | 
| emh203 | 0:d0c18e423b13 | 320 | } | 
| emh203 | 0:d0c18e423b13 | 321 | } | 
| emh203 | 0:d0c18e423b13 | 322 | } | 
| rjc19 | 1:871a329fd172 | 323 | char SpeedString[20]; | 
| rjc19 | 1:871a329fd172 | 324 | void TranslateToText(){ | 
| rjc19 | 1:871a329fd172 | 325 | switch(SERIALSPEED){ | 
| rjc19 | 1:871a329fd172 | 326 | case '0': | 
| rjc19 | 1:871a329fd172 | 327 | sprintf(&SpeedString[0],"20 mS"); | 
| rjc19 | 1:871a329fd172 | 328 | break; | 
| rjc19 | 1:871a329fd172 | 329 | case '1': | 
| rjc19 | 1:871a329fd172 | 330 | sprintf(&SpeedString[0],"30 mS"); | 
| rjc19 | 1:871a329fd172 | 331 | break; | 
| rjc19 | 1:871a329fd172 | 332 | case '2': | 
| rjc19 | 1:871a329fd172 | 333 | sprintf(&SpeedString[0],"40 mS"); | 
| rjc19 | 1:871a329fd172 | 334 | break; | 
| rjc19 | 1:871a329fd172 | 335 | case '3': | 
| rjc19 | 1:871a329fd172 | 336 | sprintf(&SpeedString[0],"50 mS"); | 
| rjc19 | 1:871a329fd172 | 337 | break; | 
| rjc19 | 1:871a329fd172 | 338 | case '4': | 
| rjc19 | 1:871a329fd172 | 339 | sprintf(&SpeedString[0],"100 mS"); | 
| rjc19 | 1:871a329fd172 | 340 | break; | 
| rjc19 | 1:871a329fd172 | 341 | case '5': | 
| rjc19 | 1:871a329fd172 | 342 | sprintf(&SpeedString[0],"1 S"); | 
| rjc19 | 1:871a329fd172 | 343 | break; | 
| rjc19 | 1:871a329fd172 | 344 | case '6': | 
| rjc19 | 1:871a329fd172 | 345 | sprintf(&SpeedString[0],"2 S"); | 
| rjc19 | 1:871a329fd172 | 346 | break; | 
| rjc19 | 1:871a329fd172 | 347 | case '7': | 
| rjc19 | 1:871a329fd172 | 348 | sprintf(&SpeedString[0],"5 S"); | 
| rjc19 | 1:871a329fd172 | 349 | break; | 
| rjc19 | 1:871a329fd172 | 350 | case '8': | 
| rjc19 | 1:871a329fd172 | 351 | sprintf(&SpeedString[0],"10 S"); | 
| rjc19 | 1:871a329fd172 | 352 | break; | 
| rjc19 | 1:871a329fd172 | 353 | case '9': | 
| rjc19 | 1:871a329fd172 | 354 | sprintf(&SpeedString[0],"30 S"); | 
| rjc19 | 1:871a329fd172 | 355 | break; | 
| rjc19 | 1:871a329fd172 | 356 | default: | 
| rjc19 | 1:871a329fd172 | 357 | sprintf(&SpeedString[0],"ERROR"); | 
| rjc19 | 1:871a329fd172 | 358 | break; | 
| rjc19 | 1:871a329fd172 | 359 | } | 
| rjc19 | 1:871a329fd172 | 360 | } | 
| emh203 | 0:d0c18e423b13 | 361 | |
| emh203 | 0:d0c18e423b13 | 362 | void ActionButtonHandler(WORD ButtonPressTime) | 
| emh203 | 0:d0c18e423b13 | 363 | { | 
| emh203 | 0:d0c18e423b13 | 364 | DisplayShutOffTick = 0; | 
| emh203 | 0:d0c18e423b13 | 365 | |
| rjc19 | 1:871a329fd172 | 366 | if(ButtonPressTime<50) { | 
| rjc19 | 1:871a329fd172 | 367 | if(DisplayMode == DISPLAY_OFF) { | 
| rjc19 | 1:871a329fd172 | 368 | PowerUpSmartSwitch(); | 
| rjc19 | 1:871a329fd172 | 369 | SmartSwitch_Reset(); | 
| rjc19 | 1:871a329fd172 | 370 | SmartSwitchClear(); | 
| rjc19 | 1:871a329fd172 | 371 | DisplayMode = DISPLAY_MEASUREMENTS; | 
| rjc19 | 1:871a329fd172 | 372 | } else { | 
| rjc19 | 1:871a329fd172 | 373 | |
| rjc19 | 1:871a329fd172 | 374 | if(DataLogError == TRUE) { | 
| emh203 | 0:d0c18e423b13 | 375 | DataLogError = FALSE; | 
| rjc19 | 1:871a329fd172 | 376 | } else { | 
| emh203 | 0:d0c18e423b13 | 377 | DisplayMode++; | 
| rjc19 | 1:871a329fd172 | 378 | |
| rjc19 | 1:871a329fd172 | 379 | if(DisplayMode >= NUM_DISPLAYS) { | 
| emh203 | 0:d0c18e423b13 | 380 | DisplayMode = 0; | 
| emh203 | 0:d0c18e423b13 | 381 | } | 
| emh203 | 0:d0c18e423b13 | 382 | } | 
| emh203 | 0:d0c18e423b13 | 383 | } | 
| emh203 | 0:d0c18e423b13 | 384 | } | 
| rjc19 | 1:871a329fd172 | 385 | |
| rjc19 | 1:871a329fd172 | 386 | else if(ButtonPressTime>100 && ButtonPressTime<500) { //Long action button | 
| rjc19 | 1:871a329fd172 | 387 | switch(SystemState) { | 
| emh203 | 0:d0c18e423b13 | 388 | default: | 
| emh203 | 0:d0c18e423b13 | 389 | case SYSTEM_STATE_IDLE: | 
| rjc19 | 1:871a329fd172 | 390 | switch(DisplayMode) { | 
| rjc19 | 1:871a329fd172 | 391 | default: | 
| rjc19 | 1:871a329fd172 | 392 | |
| rjc19 | 1:871a329fd172 | 393 | break; | 
| rjc19 | 1:871a329fd172 | 394 | |
| emh203 | 0:d0c18e423b13 | 395 | case DISPLAY_MEASUREMENTS: | 
| emh203 | 0:d0c18e423b13 | 396 | AdjustIOffset(); | 
| rjc19 | 1:871a329fd172 | 397 | break; | 
| rjc19 | 1:871a329fd172 | 398 | |
| rjc19 | 1:871a329fd172 | 399 | |
| rjc19 | 1:871a329fd172 | 400 | case DISPLAY_FIRMWARE_VERSION: | 
| rjc19 | 1:871a329fd172 | 401 | LoadConfiguration(); | 
| rjc19 | 1:871a329fd172 | 402 | break; | 
| rjc19 | 1:871a329fd172 | 403 | |
| rjc19 | 1:871a329fd172 | 404 | |
| rjc19 | 1:871a329fd172 | 405 | case DISPLAY_CARD_STATUS: | 
| rjc19 | 1:871a329fd172 | 406 | // if(SDCardDetect == 1) | 
| rjc19 | 1:871a329fd172 | 407 | { | 
| rjc19 | 1:871a329fd172 | 408 | EnterSystemState(SYSTEM_STATE_LOGGING); | 
| rjc19 | 1:871a329fd172 | 409 | } | 
| emh203 | 0:d0c18e423b13 | 410 | break; | 
| emh203 | 0:d0c18e423b13 | 411 | |
| rjc19 | 1:871a329fd172 | 412 | case DISPLAY_SERIAL_STATUS: | 
| rjc19 | 1:871a329fd172 | 413 | EnterSystemState(SYSTEM_STATE_SERIAL_LOGGING); | 
| rjc19 | 1:871a329fd172 | 414 | break; | 
| rjc19 | 1:871a329fd172 | 415 | } | 
| rjc19 | 1:871a329fd172 | 416 | break; | 
| rjc19 | 1:871a329fd172 | 417 | |
| rjc19 | 1:871a329fd172 | 418 | case SYSTEM_STATE_SERIAL_LOGGING: | 
| rjc19 | 1:871a329fd172 | 419 | PrintfLogEnqueue(&PCBackDoorTx,"QQQ\r\n"); //Shutdown | 
| rjc19 | 1:871a329fd172 | 420 | EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 421 | DisplayMode=DISPLAY_SERIAL_STATUS; //Need to stay here | 
| rjc19 | 1:871a329fd172 | 422 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 423 | break; | 
| rjc19 | 1:871a329fd172 | 424 | |
| rjc19 | 1:871a329fd172 | 425 | case SYSTEM_STATE_LOGGING: | 
| rjc19 | 1:871a329fd172 | 426 | EnterSystemState(SYSTEM_STATE_IDLE); | 
| rjc19 | 1:871a329fd172 | 427 | // unmount the file system | 
| rjc19 | 1:871a329fd172 | 428 | f_mount(0,NULL); | 
| rjc19 | 1:871a329fd172 | 429 | break; | 
| rjc19 | 1:871a329fd172 | 430 | |
| emh203 | 0:d0c18e423b13 | 431 | } | 
| emh203 | 0:d0c18e423b13 | 432 | } | 
| emh203 | 0:d0c18e423b13 | 433 | } | 
| emh203 | 0:d0c18e423b13 | 434 | |
| emh203 | 0:d0c18e423b13 | 435 | void AdjustIOffset() | 
| emh203 | 0:d0c18e423b13 | 436 | { | 
| emh203 | 0:d0c18e423b13 | 437 | DWORD SamplesToTake; | 
| emh203 | 0:d0c18e423b13 | 438 | DWORD i; | 
| emh203 | 0:d0c18e423b13 | 439 | float RunningSum = 0; | 
| rjc19 | 1:871a329fd172 | 440 | |
| emh203 | 0:d0c18e423b13 | 441 | PrintfEnqueue(&PCBackDoorTx,"Zeroing ACS576.....\r\n"); | 
| rjc19 | 1:871a329fd172 | 442 | |
| emh203 | 0:d0c18e423b13 | 443 | ADCDataRdy=0; | 
| rjc19 | 1:871a329fd172 | 444 | |
| emh203 | 0:d0c18e423b13 | 445 | SamplesToTake = (DWORD)(SAMPLE_RATE)*2; | 
| rjc19 | 1:871a329fd172 | 446 | |
| rjc19 | 1:871a329fd172 | 447 | for(i=0; i<SamplesToTake; i++) { | 
| emh203 | 0:d0c18e423b13 | 448 | SmartSwitch_SetBackLightColor2((BYTE)((float)i/(float)SamplesToTake * 64)); | 
| rjc19 | 1:871a329fd172 | 449 | |
| rjc19 | 1:871a329fd172 | 450 | while(ADCDataRdy == FALSE) { | 
| rjc19 | 1:871a329fd172 | 451 | |
| emh203 | 0:d0c18e423b13 | 452 | } | 
| emh203 | 0:d0c18e423b13 | 453 | ADCDataRdy = FALSE; | 
| emh203 | 0:d0c18e423b13 | 454 | RunningSum += RobotBusCurrentHR; | 
| emh203 | 0:d0c18e423b13 | 455 | } | 
| rjc19 | 1:871a329fd172 | 456 | |
| emh203 | 0:d0c18e423b13 | 457 | ACS576_IOFFSET_TRIM += RunningSum / SamplesToTake; | 
| emh203 | 0:d0c18e423b13 | 458 | |
| emh203 | 0:d0c18e423b13 | 459 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 460 | |
| emh203 | 0:d0c18e423b13 | 461 | PrintfEnqueue(&PCBackDoorTx,"Exporting new configuration file.....\r\n>"); | 
| rjc19 | 1:871a329fd172 | 462 | |
| emh203 | 0:d0c18e423b13 | 463 | ExportConfigurationSettings(); | 
| emh203 | 0:d0c18e423b13 | 464 | } | 
| emh203 | 0:d0c18e423b13 | 465 | |
| emh203 | 0:d0c18e423b13 | 466 | |
| emh203 | 0:d0c18e423b13 | 467 | |
| emh203 | 0:d0c18e423b13 | 468 | |
| emh203 | 0:d0c18e423b13 | 469 | BOOL CheckforConfig(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 470 | { | 
| rjc19 | 1:871a329fd172 | 471 | if(!strcmp(LineIn,"config")) { | 
| emh203 | 0:d0c18e423b13 | 472 | LoadConfiguration(); | 
| emh203 | 0:d0c18e423b13 | 473 | } | 
| emh203 | 0:d0c18e423b13 | 474 | return TRUE; | 
| emh203 | 0:d0c18e423b13 | 475 | } | 
| emh203 | 0:d0c18e423b13 | 476 | |
| emh203 | 0:d0c18e423b13 | 477 | |
| emh203 | 0:d0c18e423b13 | 478 | BOOL CheckForTimeInit(CHAR * LineIn) | 
| emh203 | 0:d0c18e423b13 | 479 | { | 
| rjc19 | 1:871a329fd172 | 480 | if(!strcmp(LineIn,"tinit")) { | 
| emh203 | 0:d0c18e423b13 | 481 | set_time(1256729737); | 
| rjc19 | 1:871a329fd172 | 482 | PrintfEnqueue(&PCBackDoorTx,"\r\nTime Reset\r\n"); | 
| emh203 | 0:d0c18e423b13 | 483 | } | 
| rjc19 | 1:871a329fd172 | 484 | |
| emh203 | 0:d0c18e423b13 | 485 | return TRUE; | 
| emh203 | 0:d0c18e423b13 | 486 | |
| emh203 | 0:d0c18e423b13 | 487 | } | 
| emh203 | 0:d0c18e423b13 | 488 | |
| emh203 | 0:d0c18e423b13 | 489 | BOOL CheckForTime(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 490 | { | 
| emh203 | 0:d0c18e423b13 | 491 | int Hour,Minute,Second=0; | 
| emh203 | 0:d0c18e423b13 | 492 | int Items; | 
| emh203 | 0:d0c18e423b13 | 493 | BOOL Error = FALSE; | 
| rjc19 | 1:871a329fd172 | 494 | time_t TimeStampTemp; | 
| rjc19 | 1:871a329fd172 | 495 | |
| rjc19 | 1:871a329fd172 | 496 | |
| emh203 | 0:d0c18e423b13 | 497 | Items = sscanf(LineIn, "time=%d : %d : %d", &Hour, &Minute, &Second); | 
| rjc19 | 1:871a329fd172 | 498 | if(Items == 3) { | 
| emh203 | 0:d0c18e423b13 | 499 | PrintfEnqueue(&PCBackDoorTx,"\r\n"); | 
| rjc19 | 1:871a329fd172 | 500 | if(Hour>23) { | 
| emh203 | 0:d0c18e423b13 | 501 | PrintfEnqueue(&PCBackDoorTx,"Hour entry must be between 0 and 24\r\n"); | 
| emh203 | 0:d0c18e423b13 | 502 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 503 | } | 
| rjc19 | 1:871a329fd172 | 504 | if(Minute>60) { | 
| emh203 | 0:d0c18e423b13 | 505 | PrintfEnqueue(&PCBackDoorTx,"Minute entry must be between 0 and 60\r\n"); | 
| emh203 | 0:d0c18e423b13 | 506 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 507 | } | 
| rjc19 | 1:871a329fd172 | 508 | if(Second>60) { | 
| emh203 | 0:d0c18e423b13 | 509 | PrintfEnqueue(&PCBackDoorTx,"Second entry must be between 0 and 60\r\n"); | 
| emh203 | 0:d0c18e423b13 | 510 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 511 | } | 
| rjc19 | 1:871a329fd172 | 512 | |
| rjc19 | 1:871a329fd172 | 513 | if(Error == TRUE) { | 
| rjc19 | 1:871a329fd172 | 514 | PrintfEnqueue(&PCBackDoorTx,"Error in time format. Time not changed.\r\n"); | 
| rjc19 | 1:871a329fd172 | 515 | } else { | 
| emh203 | 0:d0c18e423b13 | 516 | TimeStampTemp = time(NULL); | 
| rjc19 | 1:871a329fd172 | 517 | //convert to tm struct | 
| emh203 | 0:d0c18e423b13 | 518 | CurrentTime = localtime(&TimeStampTemp); | 
| emh203 | 0:d0c18e423b13 | 519 | //dump in our new valus | 
| emh203 | 0:d0c18e423b13 | 520 | CurrentTime->tm_sec = Second; | 
| emh203 | 0:d0c18e423b13 | 521 | CurrentTime->tm_min = Minute; | 
| emh203 | 0:d0c18e423b13 | 522 | CurrentTime->tm_hour = Hour; | 
| emh203 | 0:d0c18e423b13 | 523 | //set the new time | 
| emh203 | 0:d0c18e423b13 | 524 | set_time(mktime(CurrentTime)); | 
| emh203 | 0:d0c18e423b13 | 525 | PrintfEnqueue(&PCBackDoorTx,"Time set to %d:%d:%d\r\n",Hour,Minute,Second); | 
| emh203 | 0:d0c18e423b13 | 526 | } | 
| rjc19 | 1:871a329fd172 | 527 | |
| rjc19 | 1:871a329fd172 | 528 | } | 
| rjc19 | 1:871a329fd172 | 529 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 530 | } | 
| emh203 | 0:d0c18e423b13 | 531 | |
| emh203 | 0:d0c18e423b13 | 532 | BOOL CheckForDate(CHAR *LineIn) | 
| emh203 | 0:d0c18e423b13 | 533 | { | 
| emh203 | 0:d0c18e423b13 | 534 | int Day,Month,Year=0; | 
| emh203 | 0:d0c18e423b13 | 535 | int Items; | 
| emh203 | 0:d0c18e423b13 | 536 | BOOL Error = FALSE; | 
| emh203 | 0:d0c18e423b13 | 537 | time_t TimeStampTemp; | 
| rjc19 | 1:871a329fd172 | 538 | |
| emh203 | 0:d0c18e423b13 | 539 | Items = sscanf(LineIn, "date=%d / %d / %d", &Month, &Day, &Year); | 
| rjc19 | 1:871a329fd172 | 540 | if(Items == 3) { | 
| emh203 | 0:d0c18e423b13 | 541 | PrintfEnqueue(&PCBackDoorTx,"\r\n"); | 
| rjc19 | 1:871a329fd172 | 542 | if(Month>12 || Month < 1) { | 
| emh203 | 0:d0c18e423b13 | 543 | PrintfEnqueue(&PCBackDoorTx,"Month entry must be between 1 and 12\r\n"); | 
| emh203 | 0:d0c18e423b13 | 544 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 545 | } | 
| rjc19 | 1:871a329fd172 | 546 | if(Day>31 || Day<1) { | 
| emh203 | 0:d0c18e423b13 | 547 | PrintfEnqueue(&PCBackDoorTx,"Day entry must be between 1 and 31\r\n"); | 
| emh203 | 0:d0c18e423b13 | 548 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 549 | } | 
| rjc19 | 1:871a329fd172 | 550 | if(Year<1900) { | 
| emh203 | 0:d0c18e423b13 | 551 | PrintfEnqueue(&PCBackDoorTx,"Year entry must be greater than 1900\r\n"); | 
| emh203 | 0:d0c18e423b13 | 552 | Error = TRUE; | 
| emh203 | 0:d0c18e423b13 | 553 | } | 
| rjc19 | 1:871a329fd172 | 554 | |
| rjc19 | 1:871a329fd172 | 555 | if(Error == TRUE) { | 
| rjc19 | 1:871a329fd172 | 556 | PrintfEnqueue(&PCBackDoorTx,"Error in time format. Date not changed.\r\n"); | 
| rjc19 | 1:871a329fd172 | 557 | } else { | 
| emh203 | 0:d0c18e423b13 | 558 | //Get the current time in seconds since unix epoch | 
| emh203 | 0:d0c18e423b13 | 559 | TimeStampTemp = time(NULL); | 
| emh203 | 0:d0c18e423b13 | 560 | //convert to tm struct fom | 
| emh203 | 0:d0c18e423b13 | 561 | CurrentTime = localtime(&TimeStampTemp); | 
| emh203 | 0:d0c18e423b13 | 562 | //dump in our new valus | 
| emh203 | 0:d0c18e423b13 | 563 | CurrentTime->tm_mon = Month-1; | 
| emh203 | 0:d0c18e423b13 | 564 | CurrentTime->tm_mday = Day; | 
| emh203 | 0:d0c18e423b13 | 565 | CurrentTime->tm_year = Year - 1900; | 
| emh203 | 0:d0c18e423b13 | 566 | //set the new time | 
| emh203 | 0:d0c18e423b13 | 567 | set_time(mktime(CurrentTime)); | 
| emh203 | 0:d0c18e423b13 | 568 | PrintfEnqueue(&PCBackDoorTx,"Date set to %d/%d/%d\r\n",Month,Day,Year); | 
| emh203 | 0:d0c18e423b13 | 569 | } | 
| rjc19 | 1:871a329fd172 | 570 | |
| rjc19 | 1:871a329fd172 | 571 | } | 
| rjc19 | 1:871a329fd172 | 572 | return FALSE; | 
| emh203 | 0:d0c18e423b13 | 573 | } | 
| emh203 | 0:d0c18e423b13 | 574 | |
| emh203 | 0:d0c18e423b13 | 575 | |
| emh203 | 0:d0c18e423b13 | 576 | |
| emh203 | 0:d0c18e423b13 | 577 | void UpdateDisplay() | 
| emh203 | 0:d0c18e423b13 | 578 | { | 
| emh203 | 0:d0c18e423b13 | 579 | |
| rjc19 | 1:871a329fd172 | 580 | if(DisplayShutOffTick > DISPLAY_SHUTOFF_TIME) { | 
| emh203 | 0:d0c18e423b13 | 581 | DisplayMode = DISPLAY_OFF; | 
| emh203 | 0:d0c18e423b13 | 582 | SmartSwitchClear(); | 
| rjc19 | 1:871a329fd172 | 583 | PowerDownSmartSwitch(); | 
| rjc19 | 1:871a329fd172 | 584 | } else { | 
| rjc19 | 1:871a329fd172 | 585 | if(DisplayUpdateTick > 25) { | 
| emh203 | 0:d0c18e423b13 | 586 | GFX_FullDisplayBufferClear(&BackBuffer); | 
| emh203 | 0:d0c18e423b13 | 587 | DisplayUpdateTick = 0; | 
| rjc19 | 1:871a329fd172 | 588 | SmartSwitch_SetBrightnss(0); | 
| rjc19 | 1:871a329fd172 | 589 | switch(DisplayMode) { | 
| rjc19 | 1:871a329fd172 | 590 | default: | 
| rjc19 | 1:871a329fd172 | 591 | case DISPLAY_MEASUREMENTS: | 
| rjc19 | 1:871a329fd172 | 592 | SmartSwitch_SetBackLightColor(3,3,3); | 
| rjc19 | 1:871a329fd172 | 593 | GFX_DrawString(&BackBuffer,"Robot Bus",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 594 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 595 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 596 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 597 | |
| rjc19 | 1:871a329fd172 | 598 | GFX_printf(&BackBuffer,0,16,&Font5x7,"V: %.2fv",RobotBusVoltageHR); | 
| rjc19 | 1:871a329fd172 | 599 | GFX_printf(&BackBuffer,0,24,&Font5x7,"I: %.2fa",RobotBusCurrentHR); | 
| emh203 | 0:d0c18e423b13 | 600 | break; | 
| rjc19 | 1:871a329fd172 | 601 | |
| rjc19 | 1:871a329fd172 | 602 | case DISPLAY_SERIAL_STATUS: | 
| rjc19 | 1:871a329fd172 | 603 | |
| rjc19 | 1:871a329fd172 | 604 | SmartSwitch_SetBrightnss(LastSerialBrightness); | 
| rjc19 | 1:871a329fd172 | 605 | SmartSwitch_SetBackLightColor(2,0,2); | 
| rjc19 | 1:871a329fd172 | 606 | GFX_DrawString(&BackBuffer,"Serial Log",0,0,&Font5x7); | 
| rjc19 | 1:871a329fd172 | 607 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,10); | 
| rjc19 | 1:871a329fd172 | 608 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,11); | 
| rjc19 | 1:871a329fd172 | 609 | GFX_DrawHline(&BackBuffer,0,PHYSICAL_DISPLAY_XRES-1,12); | 
| rjc19 | 1:871a329fd172 | 610 | GFX_printf(&BackBuffer,0,16,&Font5x7,"Rate %s",&SpeedString[0]); | 
| rjc19 | 1:871a329fd172 | 611 | TranslateToText(); | 
| rjc19 | 1:871a329fd172 | 612 | if(SystemState != SYSTEM_STATE_SERIAL_LOGGING){ | 
| rjc19 | 1:871a329fd172 | 613 | GFX_printf(&BackBuffer,0,24,&Font5x7,"Not Logging"); | 
| rjc19 | 1:871a329fd172 | 614 | LastSerialBrightness=7; | 
| rjc19 | 1:871a329fd172 | 615 | } | 
| rjc19 | 1:871a329fd172 | 616 | else{ //we are logging | 
| rjc19 | 1:871a329fd172 | 617 | GFX_printf(&BackBuffer,0,24,&Font5x7,"Logging"); | 
| rjc19 | 1:871a329fd172 | 618 | if(LastSerialBrightness == 7)LastSerialBrightness=3; | 
| rjc19 | 1:871a329fd172 | 619 | else LastSerialBrightness=7; | 
| 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 | 
