SENtral Simple Serial Host interface for PNI Sensor Corp SENtral-A2 motion coprocessor. For use with the RM3100RTI Arduino shield module on top of an STM4 serial mbed board. Will work with an PNI RM3100RTI module or M&M motion modules. Interaction with unit using built in USB serial serial port set for 115200 baud. Send '?' char for menu. Presently requires SENtral firmware to either be loaded in the RM3100RTI Arduino shield SD Card or preloaded in the RM3100RTI or M&M module's EEPROM. Firmware is typically preloaded on the module's EEPROM by PNI. PNI Sensor, 2019 www.pnicorp.com

Dependencies:   mbed SDFileSystemVSG

SENtral Simple Serial Host interface for PNI Sensor Corp SENtral-A2 motion coprocessor. For use with the RM3100RTI Arduino shield module on top of an STM4 serial mbed board. Will work with an PNI RM3100RTI module or M&M motion modules. Interaction with unit using built in USB serial serial port set for 115200 baud. Send '?' char for menu. Presently requires SENtral firmware to either be loaded in the RM3100RTI Arduino shield SD Card or preloaded in the RM3100RTI or M&M module's EEPROM. Firmware is typically preloaded on the module's EEPROM by PNI. PNI Sensor, 2019 www.pnicorp.com

Committer:
JoeMiller
Date:
Fri Jul 22 18:13:26 2016 +0000
Revision:
1:b0a205c9b958
Parent:
0:02c0c2cbc3df
Child:
3:69239f60d620
Removed Nucleo RED LED. It interfered with SD Card Operation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JoeMiller 0:02c0c2cbc3df 1 #include "main.h"
JoeMiller 0:02c0c2cbc3df 2
JoeMiller 1:b0a205c9b958 3 #define REVISION "1.0.1"
JoeMiller 0:02c0c2cbc3df 4 #define CR 13
JoeMiller 0:02c0c2cbc3df 5 #define LF 10
JoeMiller 0:02c0c2cbc3df 6
JoeMiller 0:02c0c2cbc3df 7 // Note: all warmstart related functions are commented-out. The parameter list and
JoeMiller 0:02c0c2cbc3df 8 // flags are presently going through a major revision.
JoeMiller 0:02c0c2cbc3df 9
JoeMiller 0:02c0c2cbc3df 10
JoeMiller 0:02c0c2cbc3df 11
JoeMiller 0:02c0c2cbc3df 12 //******************************
JoeMiller 0:02c0c2cbc3df 13 // Function prototypes
JoeMiller 0:02c0c2cbc3df 14 //******************************
JoeMiller 0:02c0c2cbc3df 15 void read_BuildVersion(void);
JoeMiller 0:02c0c2cbc3df 16 void executeSerialFunction(char key);
JoeMiller 0:02c0c2cbc3df 17
JoeMiller 0:02c0c2cbc3df 18 //*******************************
JoeMiller 0:02c0c2cbc3df 19 // Global Variables
JoeMiller 0:02c0c2cbc3df 20 //*******************************
JoeMiller 0:02c0c2cbc3df 21 u8 serialCommandMode;
JoeMiller 0:02c0c2cbc3df 22 u8 serialSensorID;
JoeMiller 0:02c0c2cbc3df 23 u16 serialSensorRate;
JoeMiller 0:02c0c2cbc3df 24 u16 serialCommandValue;
JoeMiller 0:02c0c2cbc3df 25
JoeMiller 0:02c0c2cbc3df 26 u8 fifoBuffer[24 * 1024];
JoeMiller 0:02c0c2cbc3df 27 u32 bytesRead;
JoeMiller 0:02c0c2cbc3df 28
JoeMiller 0:02c0c2cbc3df 29 u8 apSuspendMode = 0;
JoeMiller 0:02c0c2cbc3df 30 u8 displayText = 1; // Also see simular "printData" in em7186.cpp
JoeMiller 0:02c0c2cbc3df 31 u8 reportMetaData = 0;
JoeMiller 0:02c0c2cbc3df 32
JoeMiller 0:02c0c2cbc3df 33 u8 fw[] = { "/sd/sentral.fw" };
JoeMiller 0:02c0c2cbc3df 34 u8 logfilename[] = { "/sd/log.csv" };
JoeMiller 0:02c0c2cbc3df 35 //u8 warmStartFile[] = { "/sd/warmstart.dat" };
JoeMiller 0:02c0c2cbc3df 36
JoeMiller 0:02c0c2cbc3df 37 FILE *flog;
JoeMiller 0:02c0c2cbc3df 38
JoeMiller 0:02c0c2cbc3df 39 char serial_inchar;
JoeMiller 0:02c0c2cbc3df 40
JoeMiller 0:02c0c2cbc3df 41 //******************************
JoeMiller 0:02c0c2cbc3df 42 // Interrupt callback functions
JoeMiller 0:02c0c2cbc3df 43 //******************************
JoeMiller 0:02c0c2cbc3df 44
JoeMiller 0:02c0c2cbc3df 45 void SENtral_Interrupt(void)
JoeMiller 0:02c0c2cbc3df 46 {
JoeMiller 0:02c0c2cbc3df 47
JoeMiller 0:02c0c2cbc3df 48 bytesRead = em7186_read_fifo(fifoBuffer);
JoeMiller 0:02c0c2cbc3df 49 em7186_parse_fifo(fifoBuffer, bytesRead);
JoeMiller 0:02c0c2cbc3df 50
JoeMiller 0:02c0c2cbc3df 51 }
JoeMiller 0:02c0c2cbc3df 52
JoeMiller 0:02c0c2cbc3df 53 void OnSerial(void)
JoeMiller 0:02c0c2cbc3df 54 {
JoeMiller 0:02c0c2cbc3df 55 serial_inchar = pc.getc();
JoeMiller 0:02c0c2cbc3df 56 }
JoeMiller 0:02c0c2cbc3df 57
JoeMiller 0:02c0c2cbc3df 58 //=============================================================================
JoeMiller 0:02c0c2cbc3df 59 // Serial input Character (Key) Commands
JoeMiller 0:02c0c2cbc3df 60 //=============================================================================
JoeMiller 0:02c0c2cbc3df 61
JoeMiller 0:02c0c2cbc3df 62 // processSerialInchar function is called upon every incomming serial character
JoeMiller 0:02c0c2cbc3df 63 // as defined in mbed_objects.cpp
JoeMiller 0:02c0c2cbc3df 64 void processSerialInchar(char key)
JoeMiller 0:02c0c2cbc3df 65 {
JoeMiller 0:02c0c2cbc3df 66 // The Simple Serial protocal mostly consists of single character commands
JoeMiller 0:02c0c2cbc3df 67 // the exceptions are commands that require additional information like 's' and 'X'.
JoeMiller 0:02c0c2cbc3df 68 // In these cases serialCommandMode states are used and operands are then preprocessed
JoeMiller 0:02c0c2cbc3df 69 // inside this function.
JoeMiller 0:02c0c2cbc3df 70
JoeMiller 0:02c0c2cbc3df 71 // If the protocal gets larger and more commands require additional data a more complex
JoeMiller 0:02c0c2cbc3df 72 // command processor with incoming serial buffer will have to be implimented
JoeMiller 0:02c0c2cbc3df 73 // presently this simple processor does the job
JoeMiller 0:02c0c2cbc3df 74
JoeMiller 0:02c0c2cbc3df 75 // serialCommandMode ** STATES **
JoeMiller 0:02c0c2cbc3df 76 // 0: Not in Sensor command building mode
JoeMiller 0:02c0c2cbc3df 77 // 1: 's' Sensor Rate chane. State 1 = Constructing Sensor ID number
JoeMiller 0:02c0c2cbc3df 78 // 2: State 2 = Constructing Sensor Rate Value
JoeMiller 0:02c0c2cbc3df 79 // 3: 'X' Firmware Image Tranfer Mode (waiting for source/destination character)
JoeMiller 0:02c0c2cbc3df 80 // CR: [carrage return] sends constructed sensor rate request
JoeMiller 0:02c0c2cbc3df 81
JoeMiller 0:02c0c2cbc3df 82 // send '?' to mbed for menu of commands
JoeMiller 0:02c0c2cbc3df 83
JoeMiller 0:02c0c2cbc3df 84
JoeMiller 0:02c0c2cbc3df 85 serial_inchar = NULL;
JoeMiller 0:02c0c2cbc3df 86
JoeMiller 0:02c0c2cbc3df 87 if ((serialCommandMode > 0) && (serialCommandMode < 3)) { //'s' virutual sensor rate change request
JoeMiller 0:02c0c2cbc3df 88 if ((key >= '0') && (key <= '9')) {
JoeMiller 0:02c0c2cbc3df 89 serialCommandValue = (serialCommandValue * 10) + (key - '0');
JoeMiller 0:02c0c2cbc3df 90 }
JoeMiller 0:02c0c2cbc3df 91 else if (key == ',') {
JoeMiller 0:02c0c2cbc3df 92 serialSensorID = (unsigned char)serialCommandValue;
JoeMiller 0:02c0c2cbc3df 93 serialCommandValue = 0;
JoeMiller 0:02c0c2cbc3df 94 serialCommandMode = 2;
JoeMiller 0:02c0c2cbc3df 95 } else if (key == CR || key == LF) {
JoeMiller 0:02c0c2cbc3df 96 if (serialCommandMode == 1) {
JoeMiller 0:02c0c2cbc3df 97 serialSensorID = serialCommandValue;
JoeMiller 0:02c0c2cbc3df 98 } else {
JoeMiller 0:02c0c2cbc3df 99 serialSensorRate = serialCommandValue;
JoeMiller 0:02c0c2cbc3df 100 }
JoeMiller 0:02c0c2cbc3df 101 if (serialSensorID > 0) {
JoeMiller 0:02c0c2cbc3df 102 if (displayText) printf("\n\rChanging rate of sensor %u to %d\n\r", serialSensorID, serialSensorRate);
JoeMiller 0:02c0c2cbc3df 103 em7186_set_sensor_rate(serialSensorID,serialSensorRate);
JoeMiller 0:02c0c2cbc3df 104 if (serialSensorRate > 0) {
JoeMiller 0:02c0c2cbc3df 105 sensorEnabled[serialSensorID-1] = TRUE;
JoeMiller 0:02c0c2cbc3df 106 } else {
JoeMiller 0:02c0c2cbc3df 107 sensorEnabled[serialSensorID-1] = FALSE;
JoeMiller 0:02c0c2cbc3df 108 }
JoeMiller 0:02c0c2cbc3df 109 }
JoeMiller 0:02c0c2cbc3df 110 serialCommandMode = 0;
JoeMiller 0:02c0c2cbc3df 111 serialSensorID = 0;
JoeMiller 0:02c0c2cbc3df 112 serialSensorRate = 0;
JoeMiller 0:02c0c2cbc3df 113 }
JoeMiller 0:02c0c2cbc3df 114 } else if (serialCommandMode == 3) { // 'X' Transfer firmware command
JoeMiller 0:02c0c2cbc3df 115 firmwareTransfer(key);
JoeMiller 0:02c0c2cbc3df 116 serialCommandMode = 0;
JoeMiller 0:02c0c2cbc3df 117 } else
JoeMiller 0:02c0c2cbc3df 118 executeSerialFunction(key);
JoeMiller 0:02c0c2cbc3df 119 }
JoeMiller 0:02c0c2cbc3df 120
JoeMiller 0:02c0c2cbc3df 121 void executeSerialFunction(char key)
JoeMiller 0:02c0c2cbc3df 122 {
JoeMiller 0:02c0c2cbc3df 123 u8 paramValues[2];
JoeMiller 0:02c0c2cbc3df 124 ParamInfo param = { 1,1 }; // parameter# 1, size=1
JoeMiller 0:02c0c2cbc3df 125 switch (key)
JoeMiller 0:02c0c2cbc3df 126 {
JoeMiller 0:02c0c2cbc3df 127 case 'B':
JoeMiller 0:02c0c2cbc3df 128 if (displayText) printf("\n\r\n\r ********** PREPARING FOR SENSOR SELF TEST REQUEST; STANDBY REQUEST MADE ********** \n\r\n\r");
JoeMiller 0:02c0c2cbc3df 129 paramValues[0] = 0x01; // Request Sensor Self Test bit and NOT standby bit
JoeMiller 0:02c0c2cbc3df 130 em7186_i2c_write(0x55, paramValues, 1); // 0x55 = Host Interface Control Reg
JoeMiller 0:02c0c2cbc3df 131 if (displayText) printf("\n\r\n\r ********** SENSOR SELF TEST REQUEST + RUN MADE ********** \n\r\n\r");
JoeMiller 0:02c0c2cbc3df 132 paramValues[0] = 0x40; // Request Sensor Self Test bit and NOT standby bit
JoeMiller 0:02c0c2cbc3df 133 em7186_i2c_write(0x55, paramValues, 1); // 0x55 = Host Interface Control Reg
JoeMiller 0:02c0c2cbc3df 134 break;
JoeMiller 0:02c0c2cbc3df 135 case 'c':
JoeMiller 0:02c0c2cbc3df 136 displayStatusRegisters();
JoeMiller 0:02c0c2cbc3df 137 break;
JoeMiller 0:02c0c2cbc3df 138 // case 'd':
JoeMiller 0:02c0c2cbc3df 139 // displayParams(2, warmStartList, sizeof(warmStartList) / sizeof(warmStartList[0]));
JoeMiller 0:02c0c2cbc3df 140 // break;
JoeMiller 0:02c0c2cbc3df 141 case 'D': // this togggles display of SENtral(FIFO) Data
JoeMiller 0:02c0c2cbc3df 142 // Only useful when intending to log data through SD Card and want to suspend terminal display of data
JoeMiller 0:02c0c2cbc3df 143 printData = !printData;
JoeMiller 0:02c0c2cbc3df 144 if (displayText) printf("Display SENtral Data - %s\n\r", (printData ? "Enabled" : "Disabled"));
JoeMiller 0:02c0c2cbc3df 145 break;
JoeMiller 0:02c0c2cbc3df 146 case 'e':
JoeMiller 0:02c0c2cbc3df 147 displayPhysicalSensorStatus();
JoeMiller 0:02c0c2cbc3df 148 break;
JoeMiller 0:02c0c2cbc3df 149 case 'f':
JoeMiller 0:02c0c2cbc3df 150 displaySensorStatus();
JoeMiller 0:02c0c2cbc3df 151 break;
JoeMiller 0:02c0c2cbc3df 152
JoeMiller 0:02c0c2cbc3df 153 case 'g':
JoeMiller 0:02c0c2cbc3df 154 logData = !logData;
JoeMiller 0:02c0c2cbc3df 155 if(logData) {
JoeMiller 0:02c0c2cbc3df 156 flog = fopen(logfilename, "a");
JoeMiller 0:02c0c2cbc3df 157 if (!flog) {
JoeMiller 0:02c0c2cbc3df 158 printf("Error Opening log file\n\r");
JoeMiller 0:02c0c2cbc3df 159 logData = 0;
JoeMiller 0:02c0c2cbc3df 160 }
JoeMiller 0:02c0c2cbc3df 161 else
JoeMiller 0:02c0c2cbc3df 162 printf("%s Log file open\n\r",logfilename);
JoeMiller 0:02c0c2cbc3df 163 }
JoeMiller 0:02c0c2cbc3df 164 else {
JoeMiller 0:02c0c2cbc3df 165 if(flog) {
JoeMiller 0:02c0c2cbc3df 166 fclose(flog);
JoeMiller 0:02c0c2cbc3df 167 printf("Log file closed\n\r");
JoeMiller 0:02c0c2cbc3df 168 }
JoeMiller 0:02c0c2cbc3df 169 }
JoeMiller 0:02c0c2cbc3df 170 break;
JoeMiller 0:02c0c2cbc3df 171
JoeMiller 0:02c0c2cbc3df 172 case 'h':
JoeMiller 0:02c0c2cbc3df 173 apSuspendMode = !apSuspendMode;
JoeMiller 0:02c0c2cbc3df 174 if (apSuspendMode) em7186_ap_suspend(1);
JoeMiller 0:02c0c2cbc3df 175 else em7186_ap_suspend(0);
JoeMiller 0:02c0c2cbc3df 176 if (displayText) printf("AP Suspend Mode %s\n\r", (apSuspendMode ? "Enabled" : "Disabled"));
JoeMiller 0:02c0c2cbc3df 177 break;
JoeMiller 0:02c0c2cbc3df 178 case 'H':
JoeMiller 0:02c0c2cbc3df 179 em7186_i2c_write_value(CHIP_CONTROL_REG, CHIP_CONTROL_CPU_STOP);
JoeMiller 0:02c0c2cbc3df 180 //SENtral_InterruptPin.enable_irq();
JoeMiller 0:02c0c2cbc3df 181 if (displayText) printf("Exit Run Mode Request sent\n\r");
JoeMiller 0:02c0c2cbc3df 182 break;
JoeMiller 0:02c0c2cbc3df 183 case 'i':
JoeMiller 0:02c0c2cbc3df 184 {
JoeMiller 0:02c0c2cbc3df 185 displayPhysicalSensorInformation();
JoeMiller 0:02c0c2cbc3df 186 break;
JoeMiller 0:02c0c2cbc3df 187 }
JoeMiller 0:02c0c2cbc3df 188 case 'j':
JoeMiller 0:02c0c2cbc3df 189 em7186_set_fifo_watermarks(1000, 1000);
JoeMiller 0:02c0c2cbc3df 190 break;
JoeMiller 0:02c0c2cbc3df 191 // case 'l':
JoeMiller 0:02c0c2cbc3df 192 // em7186_warm_start_load(warmStartFile);
JoeMiller 0:02c0c2cbc3df 193 // break;
JoeMiller 0:02c0c2cbc3df 194 case 'm':
JoeMiller 0:02c0c2cbc3df 195 reportMetaData = !reportMetaData;
JoeMiller 0:02c0c2cbc3df 196 if (reportMetaData) printf("Meta Data reporting - %s\n\r", (printData ? "Enabled" : "Disabled"));
JoeMiller 0:02c0c2cbc3df 197 break;
JoeMiller 0:02c0c2cbc3df 198 case 'n':
JoeMiller 0:02c0c2cbc3df 199 displaySensorInformation();
JoeMiller 0:02c0c2cbc3df 200 break;
JoeMiller 0:02c0c2cbc3df 201 case 'r':
JoeMiller 0:02c0c2cbc3df 202 em7186_i2c_write_value(CHIP_CONTROL_REG, CHIP_CONTROL_CPU_RUN);
JoeMiller 0:02c0c2cbc3df 203 em7186_set_scale_factors();
JoeMiller 0:02c0c2cbc3df 204 SENtral_InterruptPin.enable_irq();
JoeMiller 0:02c0c2cbc3df 205 if (displayText) printf("Run Mode Request sent\n\r");
JoeMiller 0:02c0c2cbc3df 206 break;
JoeMiller 0:02c0c2cbc3df 207 case 'R':
JoeMiller 0:02c0c2cbc3df 208 em7186_i2c_write_value(RESET_REQ_REG, 1);
JoeMiller 0:02c0c2cbc3df 209 if (displayText) printf("Reset Request Sent\n\r");
JoeMiller 0:02c0c2cbc3df 210 break;
JoeMiller 0:02c0c2cbc3df 211 case 's':
JoeMiller 0:02c0c2cbc3df 212 serialCommandMode = 1; // user beginning to Enable/Disable or change SensorRate
JoeMiller 0:02c0c2cbc3df 213 serialSensorID = 0; serialSensorRate = 0; serialCommandValue = 0;
JoeMiller 0:02c0c2cbc3df 214 if (displayText) printf("Enter Sensor ID,Rate--> ");
JoeMiller 0:02c0c2cbc3df 215 // reminder: SENtral must be "run"-ing before the virtual sensor actually starts
JoeMiller 0:02c0c2cbc3df 216 // run mode ('r' command) can be executed before or after this command
JoeMiller 0:02c0c2cbc3df 217 break;
JoeMiller 0:02c0c2cbc3df 218 // case 'S':
JoeMiller 0:02c0c2cbc3df 219 // em7186_warm_start_save(warmStartFile);
JoeMiller 0:02c0c2cbc3df 220 // break;
JoeMiller 0:02c0c2cbc3df 221 case 't':
JoeMiller 0:02c0c2cbc3df 222 displayText = !displayText;
JoeMiller 0:02c0c2cbc3df 223 if (displayText) printf("Text Display %s\n\r", (displayText ? "Enabled" : "Disabled"));
JoeMiller 0:02c0c2cbc3df 224 break;
JoeMiller 0:02c0c2cbc3df 225 case 'X':
JoeMiller 0:02c0c2cbc3df 226 if (displayText) printf("Firmware Transfer. Enter source/destination code: %s\n\r",fw);
JoeMiller 0:02c0c2cbc3df 227 serialCommandMode = 3;
JoeMiller 0:02c0c2cbc3df 228 break;
JoeMiller 0:02c0c2cbc3df 229 case 'v':
JoeMiller 0:02c0c2cbc3df 230 case 'V':
JoeMiller 0:02c0c2cbc3df 231 read_BuildVersion();
JoeMiller 0:02c0c2cbc3df 232 break;
JoeMiller 0:02c0c2cbc3df 233 // case 'w':
JoeMiller 0:02c0c2cbc3df 234 // warmStart(); // this is to test the warmstart save/load process
JoeMiller 0:02c0c2cbc3df 235 // break;
JoeMiller 0:02c0c2cbc3df 236 case 'y':
JoeMiller 0:02c0c2cbc3df 237 break;
JoeMiller 0:02c0c2cbc3df 238 case 'z':
JoeMiller 0:02c0c2cbc3df 239 displaySensorConfiguration();
JoeMiller 0:02c0c2cbc3df 240 break;
JoeMiller 0:02c0c2cbc3df 241 case '?':
JoeMiller 0:02c0c2cbc3df 242 {
JoeMiller 0:02c0c2cbc3df 243 u8 bar[45];
JoeMiller 0:02c0c2cbc3df 244 memset(bar, 205, sizeof(bar));
JoeMiller 0:02c0c2cbc3df 245 bar[sizeof(bar)-1] = 0;
JoeMiller 0:02c0c2cbc3df 246 printf("\n\r");
JoeMiller 0:02c0c2cbc3df 247 printf(" RM3100RTI-SEntral Simple Serial Interface\n\r");
JoeMiller 0:02c0c2cbc3df 248 printf(" Revision: %s\n\r",REVISION);
JoeMiller 0:02c0c2cbc3df 249 printf(" %c%s%c\n\r", 201, bar, 187);
JoeMiller 0:02c0c2cbc3df 250 printf(" %c Commands (case sensitive) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 251 // Status and configuration
JoeMiller 0:02c0c2cbc3df 252 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 253 printf(" %c Configuration and Status %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 254 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 255 printf(" %c c : Display status registers %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 256 printf(" %c e : Display physical sensor status %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 257 printf(" %c f : Display sensor status %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 258 printf(" %c i : Display Physical Sensor Information %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 259 printf(" %c n : Display sensor information %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 260 printf(" %c z : Display sensor configuration %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 261 printf(" %c v : Display Firmware Version information %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 262
JoeMiller 0:02c0c2cbc3df 263 // Sensor control
JoeMiller 0:02c0c2cbc3df 264 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 265 printf(" %c Firmware Transfers %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 266 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 267 printf(" %c XR : From SD Card to SENtral RAM %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 268 printf(" %c XE : From SD Card to EEPROM %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 269
JoeMiller 0:02c0c2cbc3df 270 // Sensor control
JoeMiller 0:02c0c2cbc3df 271 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 272 printf(" %c Sensor Rates %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 273 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 274 printf(" %c s @@@,###[CR] %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 275 printf(" %c where: %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 276 printf(" %c @@@ = Sensor ID %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 277 printf(" %c ### = Data rate %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 278 printf(" %c [CR]= carriage return (0x0D) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 279
JoeMiller 0:02c0c2cbc3df 280 // Display controls
JoeMiller 0:02c0c2cbc3df 281 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 282 printf(" %c Display Controls %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 283 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 284 printf(" %c t : Toggle command feedback text %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 285 printf(" %c m : Meta event reporting (on/off) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 286
JoeMiller 0:02c0c2cbc3df 287 // Data logging
JoeMiller 0:02c0c2cbc3df 288 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 289 printf(" %c Data Logging %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 290 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 291 printf(" %c g : Toggle sensor Data log (on/off) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 292 printf(" %c D : Toggle sensor Data display (on/off) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 293
JoeMiller 0:02c0c2cbc3df 294 // Additional controls
JoeMiller 0:02c0c2cbc3df 295 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 296 printf(" %c Additional Controls %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 297 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 298 printf(" %c j : Set fifo watermarks to 1000 %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 299 printf(" %c h : Toggle AP suspend mode (on/off) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 300 printf(" %c R : Send Reset Request to SENtral %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 301 printf(" %c r : Request SENtral Run Mode ON %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 302 printf(" %c H : Request SENtral Run Mode OFF (Halt) %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 303
JoeMiller 0:02c0c2cbc3df 304 // Warm-start
JoeMiller 0:02c0c2cbc3df 305 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 306 printf(" %c Warm-Start %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 307 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 308 printf(" %c S : Save warm-start parameters %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 309 printf(" %c l : Load warm-start parameters %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 310 printf(" %c d : Display warm-start parameters %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 311 printf(" %c w : Perform warm-start test %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 312
JoeMiller 0:02c0c2cbc3df 313 // Tests
JoeMiller 0:02c0c2cbc3df 314 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 315 printf(" %c Tests %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 316 printf(" %c%s%c\n\r", 204, bar, 185);
JoeMiller 0:02c0c2cbc3df 317 printf(" %c B : Run sensor Self tests %c\n\r", 186, 186);
JoeMiller 0:02c0c2cbc3df 318
JoeMiller 0:02c0c2cbc3df 319 printf(" %c%s%c\n\r", 200, bar, 188);
JoeMiller 0:02c0c2cbc3df 320
JoeMiller 0:02c0c2cbc3df 321 }
JoeMiller 0:02c0c2cbc3df 322 }
JoeMiller 0:02c0c2cbc3df 323 }
JoeMiller 0:02c0c2cbc3df 324
JoeMiller 0:02c0c2cbc3df 325
JoeMiller 0:02c0c2cbc3df 326 void runScript(void)
JoeMiller 0:02c0c2cbc3df 327 {
JoeMiller 0:02c0c2cbc3df 328
JoeMiller 0:02c0c2cbc3df 329 // This script(function) runs when the Pushbutton on the RM3100 Arduino
JoeMiller 0:02c0c2cbc3df 330 // shield is pressed, which is connected to pin D5.
JoeMiller 0:02c0c2cbc3df 331
JoeMiller 0:02c0c2cbc3df 332 green_LED = 1; // flash to denote start
JoeMiller 0:02c0c2cbc3df 333 wait(0.1);
JoeMiller 0:02c0c2cbc3df 334 green_LED = 0;
JoeMiller 0:02c0c2cbc3df 335
JoeMiller 0:02c0c2cbc3df 336 if (displayText) printf("Running Special script\n\r");
JoeMiller 0:02c0c2cbc3df 337
JoeMiller 0:02c0c2cbc3df 338 /*
JoeMiller 0:02c0c2cbc3df 339 Your custom code goes here
JoeMiller 0:02c0c2cbc3df 340 */
JoeMiller 0:02c0c2cbc3df 341
JoeMiller 0:02c0c2cbc3df 342
JoeMiller 0:02c0c2cbc3df 343 }
JoeMiller 0:02c0c2cbc3df 344
JoeMiller 0:02c0c2cbc3df 345
JoeMiller 0:02c0c2cbc3df 346 //******************************
JoeMiller 0:02c0c2cbc3df 347 // MAIN
JoeMiller 0:02c0c2cbc3df 348 //******************************
JoeMiller 0:02c0c2cbc3df 349
JoeMiller 0:02c0c2cbc3df 350 int main()
JoeMiller 0:02c0c2cbc3df 351 {
JoeMiller 0:02c0c2cbc3df 352
JoeMiller 0:02c0c2cbc3df 353 // Init user serial interface
JoeMiller 0:02c0c2cbc3df 354 pc.baud(115200);
JoeMiller 0:02c0c2cbc3df 355 printf("SENtral Simple Serial Host Interface %s\n\r",REVISION);
JoeMiller 0:02c0c2cbc3df 356
JoeMiller 0:02c0c2cbc3df 357 // Initialize Stuff
JoeMiller 0:02c0c2cbc3df 358 if (!em7186_i2c_init()) {
JoeMiller 0:02c0c2cbc3df 359 printf("Failed to see SENtral device.\n\r Check connections\n\r");
JoeMiller 0:02c0c2cbc3df 360 }
JoeMiller 0:02c0c2cbc3df 361
JoeMiller 0:02c0c2cbc3df 362
JoeMiller 0:02c0c2cbc3df 363 // Setup interrupt callback functions
JoeMiller 0:02c0c2cbc3df 364 SENtral_InterruptPin.rise(&SENtral_Interrupt); // SENtral host interrupt
JoeMiller 0:02c0c2cbc3df 365 pc.attach(&OnSerial); // user input from serial term
JoeMiller 0:02c0c2cbc3df 366
JoeMiller 0:02c0c2cbc3df 367
JoeMiller 0:02c0c2cbc3df 368 // flash ready signal on expansion board Assumes LED is jumpered to D4
JoeMiller 0:02c0c2cbc3df 369 for (char i=4;i;i--)
JoeMiller 0:02c0c2cbc3df 370 {
JoeMiller 0:02c0c2cbc3df 371 green_LED = 1; // This LED is optional RM3100RTI shield board specific
JoeMiller 0:02c0c2cbc3df 372 wait(0.1);
JoeMiller 0:02c0c2cbc3df 373 green_LED = 0;
JoeMiller 0:02c0c2cbc3df 374 wait(.1);
JoeMiller 0:02c0c2cbc3df 375 }
JoeMiller 0:02c0c2cbc3df 376 green_LED = 1;
JoeMiller 0:02c0c2cbc3df 377 wait(.25);
JoeMiller 0:02c0c2cbc3df 378
JoeMiller 0:02c0c2cbc3df 379 while (1)
JoeMiller 0:02c0c2cbc3df 380 {
JoeMiller 0:02c0c2cbc3df 381
JoeMiller 0:02c0c2cbc3df 382 if (serial_inchar)
JoeMiller 0:02c0c2cbc3df 383 {
JoeMiller 0:02c0c2cbc3df 384 processSerialInchar(serial_inchar); // process user key commands
JoeMiller 0:02c0c2cbc3df 385 serial_inchar = NULL;
JoeMiller 0:02c0c2cbc3df 386 }
JoeMiller 0:02c0c2cbc3df 387
JoeMiller 0:02c0c2cbc3df 388 if (pushButton == 1) // PBSwitch is wired as active high
JoeMiller 0:02c0c2cbc3df 389 runScript(); // execute special script(function)
JoeMiller 0:02c0c2cbc3df 390
JoeMiller 0:02c0c2cbc3df 391 }
JoeMiller 0:02c0c2cbc3df 392
JoeMiller 0:02c0c2cbc3df 393 }
JoeMiller 0:02c0c2cbc3df 394