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.
DRIVERS/CHEM_BOX_COMMON.cpp@6:6a870e1e52c1, 2021-09-12 (annotated)
- Committer:
- wavenumber
- Date:
- Sun Sep 12 20:53:43 2021 +0000
- Revision:
- 6:6a870e1e52c1
- Parent:
- 5:b56a4592aac0
- Child:
- 7:de452fceafc1
Added a simple P0 and P1 command for the pumps
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| emh203 | 0:7798270c1f52 | 1 | #include "mbed.h" | 
| emh203 | 0:7798270c1f52 | 2 | #include "CHEM_BOX_INTERFACE.h" | 
| emh203 | 0:7798270c1f52 | 3 | #include "MODSERIAL.h" | 
| emh203 | 0:7798270c1f52 | 4 | #include <stdio.h> | 
| emh203 | 0:7798270c1f52 | 5 | #include <stdarg.h> | 
| emh203 | 0:7798270c1f52 | 6 | |
| emh203 | 0:7798270c1f52 | 7 | //Mbed Objects | 
| emh203 | 0:7798270c1f52 | 8 | |
| wavenumber | 2:73a028278c5c | 9 | DigitalOut MBED_LED1(LED1); | 
| wavenumber | 2:73a028278c5c | 10 | |
| emh203 | 0:7798270c1f52 | 11 | DigitalOut AIO_ADC1_CS(p30); | 
| emh203 | 0:7798270c1f52 | 12 | |
| emh203 | 0:7798270c1f52 | 13 | DigitalOut AIO_ADC2_CS(p29); | 
| emh203 | 0:7798270c1f52 | 14 | |
| emh203 | 0:7798270c1f52 | 15 | PwmOut BUZZER_CONTROL(p26); | 
| emh203 | 0:7798270c1f52 | 16 | |
| emh203 | 0:7798270c1f52 | 17 | DigitalOut MCU_SR_CLEAR(p25); | 
| emh203 | 0:7798270c1f52 | 18 | |
| emh203 | 0:7798270c1f52 | 19 | DigitalOut AIO_DAC1_CS(p24); | 
| emh203 | 0:7798270c1f52 | 20 | |
| emh203 | 0:7798270c1f52 | 21 | DigitalOut AIO_DAC2_CS(p23); | 
| emh203 | 0:7798270c1f52 | 22 | |
| wavenumber | 3:cb48919cd5e8 | 23 | DigitalOut RED_LED(p20); | 
| wavenumber | 3:cb48919cd5e8 | 24 | |
| wavenumber | 3:cb48919cd5e8 | 25 | DigitalOut GREEN_LED(p14); | 
| wavenumber | 3:cb48919cd5e8 | 26 | |
| wavenumber | 3:cb48919cd5e8 | 27 | |
| emh203 | 0:7798270c1f52 | 28 | DigitalOut MFC_POWER_CONTROL(p22); | 
| emh203 | 0:7798270c1f52 | 29 | |
| emh203 | 0:7798270c1f52 | 30 | PwmOut FAN_CONTROL(p21); | 
| emh203 | 0:7798270c1f52 | 31 | |
| emh203 | 0:7798270c1f52 | 32 | SPI SPI1(p5,p6,p7); | 
| emh203 | 0:7798270c1f52 | 33 | |
| emh203 | 0:7798270c1f52 | 34 | DigitalOut MCU_SR_LOAD(p8); | 
| emh203 | 0:7798270c1f52 | 35 | |
| emh203 | 0:7798270c1f52 | 36 | SPI SPI0(p11,p12,p13); | 
| emh203 | 0:7798270c1f52 | 37 | |
| emh203 | 0:7798270c1f52 | 38 | |
| emh203 | 0:7798270c1f52 | 39 | BusOut TEMP_SENSE_ADDRESS(p15,p16,p17,p18); | 
| emh203 | 0:7798270c1f52 | 40 | |
| emh203 | 0:7798270c1f52 | 41 | DigitalOut TEMP_SENSE_CS(p19); | 
| emh203 | 0:7798270c1f52 | 42 | |
| emh203 | 0:7798270c1f52 | 43 | |
| emh203 | 0:7798270c1f52 | 44 | MODSERIAL RS232_0(p9, p10, 1024, 1024); | 
| emh203 | 0:7798270c1f52 | 45 | |
| emh203 | 0:7798270c1f52 | 46 | MODSERIAL RS232_1(p28, p27, 1024, 1024); | 
| emh203 | 0:7798270c1f52 | 47 | |
| emh203 | 0:7798270c1f52 | 48 | // Make TX buffer 1024bytes and RX buffer use 512bytes. | 
| emh203 | 0:7798270c1f52 | 49 | MODSERIAL PC(USBTX, USBRX, 1024, 1024); // tx, rx | 
| emh203 | 0:7798270c1f52 | 50 | |
| emh203 | 0:7798270c1f52 | 51 | //Local Variables | 
| emh203 | 0:7798270c1f52 | 52 | |
| emh203 | 0:7798270c1f52 | 53 | |
| wavenumber | 2:73a028278c5c | 54 | static uint8_t TerminalEcho = 1; | 
| wavenumber | 2:73a028278c5c | 55 | |
| emh203 | 0:7798270c1f52 | 56 | static uint8_t HeaterBits = 0; | 
| emh203 | 0:7798270c1f52 | 57 | |
| emh203 | 0:7798270c1f52 | 58 | static uint16_t SolenoidBits = 0; | 
| emh203 | 0:7798270c1f52 | 59 | |
| emh203 | 0:7798270c1f52 | 60 | static uint8_t DigitalOutputBits = 0; | 
| emh203 | 0:7798270c1f52 | 61 | |
| emh203 | 0:7798270c1f52 | 62 | Timeout BuzzTimeout; | 
| emh203 | 0:7798270c1f52 | 63 | |
| emh203 | 0:7798270c1f52 | 64 | static uint16_t Thermocouple_FAULT = 0; | 
| emh203 | 0:7798270c1f52 | 65 | |
| emh203 | 0:7798270c1f52 | 66 | static uint16_t Thermocouple_SCV = 0; | 
| emh203 | 0:7798270c1f52 | 67 | |
| emh203 | 0:7798270c1f52 | 68 | static uint16_t Thermocouple_SCG = 0; | 
| emh203 | 0:7798270c1f52 | 69 | |
| emh203 | 0:7798270c1f52 | 70 | static uint16_t Thermocouple_OC= 0; | 
| emh203 | 0:7798270c1f52 | 71 | |
| emh203 | 0:7798270c1f52 | 72 | static float Temperature[12]; | 
| emh203 | 0:7798270c1f52 | 73 | |
| emh203 | 0:7798270c1f52 | 74 | static float InternalTemperature[12]; | 
| emh203 | 0:7798270c1f52 | 75 | |
| emh203 | 0:7798270c1f52 | 76 | static uint16_t ReadRawADC(uint8_t Channel); | 
| emh203 | 0:7798270c1f52 | 77 | |
| emh203 | 0:7798270c1f52 | 78 | |
| emh203 | 0:7798270c1f52 | 79 | //Local Functions | 
| emh203 | 0:7798270c1f52 | 80 | |
| emh203 | 0:7798270c1f52 | 81 | void InitTerminal(); | 
| emh203 | 0:7798270c1f52 | 82 | |
| emh203 | 0:7798270c1f52 | 83 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data); | 
| emh203 | 0:7798270c1f52 | 84 | |
| emh203 | 0:7798270c1f52 | 85 | |
| emh203 | 0:7798270c1f52 | 86 | |
| emh203 | 0:7798270c1f52 | 87 | void InitChemBox() | 
| emh203 | 0:7798270c1f52 | 88 | { | 
| emh203 | 0:7798270c1f52 | 89 | |
| emh203 | 0:7798270c1f52 | 90 | AIO_ADC1_CS = 1; | 
| emh203 | 0:7798270c1f52 | 91 | |
| emh203 | 0:7798270c1f52 | 92 | AIO_ADC2_CS = 1; | 
| emh203 | 0:7798270c1f52 | 93 | |
| emh203 | 0:7798270c1f52 | 94 | BUZZER_CONTROL.period_ms(1.0); | 
| emh203 | 0:7798270c1f52 | 95 | |
| emh203 | 0:7798270c1f52 | 96 | MCU_SR_CLEAR = 1; | 
| emh203 | 0:7798270c1f52 | 97 | |
| emh203 | 0:7798270c1f52 | 98 | AIO_ADC1_CS = 1; | 
| emh203 | 0:7798270c1f52 | 99 | |
| emh203 | 0:7798270c1f52 | 100 | AIO_ADC2_CS = 1; | 
| emh203 | 0:7798270c1f52 | 101 | |
| emh203 | 0:7798270c1f52 | 102 | MFC_POWER_CONTROL = 0; | 
| emh203 | 0:7798270c1f52 | 103 | |
| emh203 | 0:7798270c1f52 | 104 | FAN_CONTROL.period_us(1000); | 
| emh203 | 0:7798270c1f52 | 105 | |
| emh203 | 0:7798270c1f52 | 106 | FAN_CONTROL.write(0); | 
| emh203 | 0:7798270c1f52 | 107 | |
| emh203 | 0:7798270c1f52 | 108 | SPI1.format(8,0); | 
| emh203 | 0:7798270c1f52 | 109 | |
| emh203 | 0:7798270c1f52 | 110 | SPI1.frequency(4000000); | 
| emh203 | 0:7798270c1f52 | 111 | |
| emh203 | 0:7798270c1f52 | 112 | MCU_SR_LOAD = 0; | 
| emh203 | 0:7798270c1f52 | 113 | |
| emh203 | 0:7798270c1f52 | 114 | SPI0.format(8,0); | 
| emh203 | 0:7798270c1f52 | 115 | |
| emh203 | 0:7798270c1f52 | 116 | SPI0.frequency(4000000); | 
| emh203 | 0:7798270c1f52 | 117 | |
| emh203 | 0:7798270c1f52 | 118 | TEMP_SENSE_ADDRESS = 0; | 
| emh203 | 0:7798270c1f52 | 119 | |
| emh203 | 0:7798270c1f52 | 120 | TEMP_SENSE_CS = 1; | 
| emh203 | 0:7798270c1f52 | 121 | |
| emh203 | 0:7798270c1f52 | 122 | HeaterBits = 0; | 
| emh203 | 0:7798270c1f52 | 123 | |
| emh203 | 0:7798270c1f52 | 124 | SolenoidBits = 0; | 
| emh203 | 0:7798270c1f52 | 125 | |
| emh203 | 0:7798270c1f52 | 126 | DigitalOutputBits = 0; | 
| emh203 | 0:7798270c1f52 | 127 | |
| emh203 | 0:7798270c1f52 | 128 | Thermocouple_FAULT = 0; | 
| emh203 | 0:7798270c1f52 | 129 | |
| emh203 | 0:7798270c1f52 | 130 | Thermocouple_SCV = 0; | 
| emh203 | 0:7798270c1f52 | 131 | |
| emh203 | 0:7798270c1f52 | 132 | Thermocouple_SCG = 0; | 
| emh203 | 0:7798270c1f52 | 133 | |
| emh203 | 0:7798270c1f52 | 134 | Thermocouple_OC= 0; | 
| emh203 | 0:7798270c1f52 | 135 | |
| emh203 | 0:7798270c1f52 | 136 | InitTerminal(); | 
| wavenumber | 6:6a870e1e52c1 | 137 | |
| wavenumber | 6:6a870e1e52c1 | 138 | RS232_0.baud(19200); | 
| wavenumber | 6:6a870e1e52c1 | 139 | |
| wavenumber | 6:6a870e1e52c1 | 140 | RS232_1.baud(19200); | 
| wavenumber | 6:6a870e1e52c1 | 141 | |
| wavenumber | 3:cb48919cd5e8 | 142 | |
| emh203 | 0:7798270c1f52 | 143 | } | 
| emh203 | 0:7798270c1f52 | 144 | |
| emh203 | 0:7798270c1f52 | 145 | |
| emh203 | 0:7798270c1f52 | 146 | void SetFanSpeed(uint8_t S) | 
| emh203 | 0:7798270c1f52 | 147 | { | 
| emh203 | 0:7798270c1f52 | 148 | if(S>100) | 
| emh203 | 0:7798270c1f52 | 149 | S = 100; | 
| emh203 | 0:7798270c1f52 | 150 | |
| emh203 | 0:7798270c1f52 | 151 | FAN_CONTROL = (float)(S)/100.0; | 
| emh203 | 0:7798270c1f52 | 152 | |
| emh203 | 0:7798270c1f52 | 153 | } | 
| emh203 | 0:7798270c1f52 | 154 | |
| emh203 | 0:7798270c1f52 | 155 | void EnableFan() | 
| emh203 | 0:7798270c1f52 | 156 | { | 
| emh203 | 0:7798270c1f52 | 157 | SetFanSpeed(100); | 
| emh203 | 0:7798270c1f52 | 158 | } | 
| emh203 | 0:7798270c1f52 | 159 | |
| emh203 | 0:7798270c1f52 | 160 | void DisableFan() | 
| emh203 | 0:7798270c1f52 | 161 | { | 
| emh203 | 0:7798270c1f52 | 162 | SetFanSpeed(0); | 
| emh203 | 0:7798270c1f52 | 163 | } | 
| emh203 | 0:7798270c1f52 | 164 | |
| emh203 | 0:7798270c1f52 | 165 | void BuzzOff() | 
| emh203 | 0:7798270c1f52 | 166 | { | 
| emh203 | 0:7798270c1f52 | 167 | BUZZER_CONTROL = 0; | 
| emh203 | 0:7798270c1f52 | 168 | } | 
| emh203 | 0:7798270c1f52 | 169 | |
| emh203 | 0:7798270c1f52 | 170 | void Buzz(float Time) | 
| emh203 | 0:7798270c1f52 | 171 | { | 
| emh203 | 0:7798270c1f52 | 172 | BUZZER_CONTROL = 0.5; | 
| emh203 | 0:7798270c1f52 | 173 | BuzzTimeout.attach(&BuzzOff, Time); | 
| emh203 | 0:7798270c1f52 | 174 | |
| emh203 | 0:7798270c1f52 | 175 | } | 
| emh203 | 0:7798270c1f52 | 176 | |
| emh203 | 0:7798270c1f52 | 177 | |
| emh203 | 0:7798270c1f52 | 178 | void EnableHeater(uint8_t RelayIndex) | 
| emh203 | 0:7798270c1f52 | 179 | { | 
| emh203 | 0:7798270c1f52 | 180 | HeaterBits |= (1<<RelayIndex); | 
| emh203 | 0:7798270c1f52 | 181 | } | 
| emh203 | 0:7798270c1f52 | 182 | |
| emh203 | 0:7798270c1f52 | 183 | void DisableHeater(uint8_t RelayIndex) | 
| emh203 | 0:7798270c1f52 | 184 | { | 
| emh203 | 0:7798270c1f52 | 185 | HeaterBits &= ~(1<<RelayIndex); | 
| emh203 | 0:7798270c1f52 | 186 | } | 
| emh203 | 0:7798270c1f52 | 187 | |
| emh203 | 0:7798270c1f52 | 188 | void EnableSolenoidValve(uint8_t SolenoidIndex) | 
| emh203 | 0:7798270c1f52 | 189 | { | 
| emh203 | 0:7798270c1f52 | 190 | SolenoidBits |= (1<<SolenoidIndex); | 
| emh203 | 0:7798270c1f52 | 191 | } | 
| emh203 | 0:7798270c1f52 | 192 | |
| emh203 | 0:7798270c1f52 | 193 | void DisableSolenoidValue(uint8_t SolenoidIndex) | 
| emh203 | 0:7798270c1f52 | 194 | { | 
| emh203 | 0:7798270c1f52 | 195 | SolenoidBits &= ~(1<<SolenoidIndex); | 
| emh203 | 0:7798270c1f52 | 196 | } | 
| emh203 | 0:7798270c1f52 | 197 | |
| emh203 | 0:7798270c1f52 | 198 | void DisableAllHeatersAndSolenoids() | 
| emh203 | 0:7798270c1f52 | 199 | { | 
| emh203 | 0:7798270c1f52 | 200 | |
| emh203 | 0:7798270c1f52 | 201 | SolenoidBits = 0; | 
| emh203 | 0:7798270c1f52 | 202 | HeaterBits = 0; | 
| emh203 | 0:7798270c1f52 | 203 | |
| emh203 | 0:7798270c1f52 | 204 | MCU_SR_CLEAR = 1; | 
| emh203 | 0:7798270c1f52 | 205 | |
| emh203 | 0:7798270c1f52 | 206 | MCU_SR_CLEAR = 0; | 
| emh203 | 0:7798270c1f52 | 207 | |
| emh203 | 0:7798270c1f52 | 208 | MCU_SR_CLEAR = 1; | 
| emh203 | 0:7798270c1f52 | 209 | |
| emh203 | 0:7798270c1f52 | 210 | MCU_SR_LOAD = 1; | 
| emh203 | 0:7798270c1f52 | 211 | |
| emh203 | 0:7798270c1f52 | 212 | MCU_SR_LOAD = 0; | 
| emh203 | 0:7798270c1f52 | 213 | } | 
| emh203 | 0:7798270c1f52 | 214 | |
| emh203 | 0:7798270c1f52 | 215 | void EnableMiscDigitalOutput(uint8_t DigitalOutIndex) | 
| emh203 | 0:7798270c1f52 | 216 | { | 
| emh203 | 0:7798270c1f52 | 217 | DigitalOutputBits |= (1<<DigitalOutIndex); | 
| emh203 | 0:7798270c1f52 | 218 | } | 
| emh203 | 0:7798270c1f52 | 219 | |
| emh203 | 0:7798270c1f52 | 220 | void DisableMiscDigitalOutput(uint8_t DigitalOutIndex) | 
| emh203 | 0:7798270c1f52 | 221 | { | 
| emh203 | 0:7798270c1f52 | 222 | DigitalOutputBits &= ~(1<<DigitalOutIndex); | 
| emh203 | 0:7798270c1f52 | 223 | } | 
| emh203 | 0:7798270c1f52 | 224 | |
| emh203 | 0:7798270c1f52 | 225 | void FlushDigitalIO() | 
| emh203 | 0:7798270c1f52 | 226 | { | 
| emh203 | 0:7798270c1f52 | 227 | SPI1.format(8,0); | 
| emh203 | 0:7798270c1f52 | 228 | |
| emh203 | 0:7798270c1f52 | 229 | SPI1.write((SolenoidBits >> 8) & 0xFF); | 
| emh203 | 0:7798270c1f52 | 230 | SPI1.write(SolenoidBits & 0xFF); | 
| emh203 | 0:7798270c1f52 | 231 | SPI1.write(HeaterBits & 0xFF); | 
| emh203 | 0:7798270c1f52 | 232 | SPI1.write(DigitalOutputBits & 0xFF); | 
| emh203 | 0:7798270c1f52 | 233 | |
| emh203 | 0:7798270c1f52 | 234 | MCU_SR_LOAD = 1; | 
| emh203 | 0:7798270c1f52 | 235 | MCU_SR_LOAD = 0; | 
| emh203 | 0:7798270c1f52 | 236 | } | 
| emh203 | 0:7798270c1f52 | 237 | |
| wavenumber | 2:73a028278c5c | 238 | //Make sure to call ReadThermocouple before you call this so internal variables are updated | 
| emh203 | 0:7798270c1f52 | 239 | uint16_t ReadThermocouple_OC() | 
| emh203 | 0:7798270c1f52 | 240 | { | 
| emh203 | 0:7798270c1f52 | 241 | return Thermocouple_OC; | 
| emh203 | 0:7798270c1f52 | 242 | } | 
| wavenumber | 2:73a028278c5c | 243 | //Make sure to call ReadThermocouple before you call this so internal variables are updated | 
| emh203 | 0:7798270c1f52 | 244 | uint16_t ReadThermocouple_SCG() | 
| emh203 | 0:7798270c1f52 | 245 | { | 
| emh203 | 0:7798270c1f52 | 246 | return Thermocouple_SCG; | 
| emh203 | 0:7798270c1f52 | 247 | } | 
| wavenumber | 2:73a028278c5c | 248 | //Make sure to call ReadThermocouple before you call this so internal variables are updated | 
| emh203 | 0:7798270c1f52 | 249 | uint16_t ReadThermocouple_SCV() | 
| emh203 | 0:7798270c1f52 | 250 | { | 
| emh203 | 0:7798270c1f52 | 251 | return Thermocouple_SCV; | 
| emh203 | 0:7798270c1f52 | 252 | } | 
| wavenumber | 2:73a028278c5c | 253 | //Make sure to call ReadThermocouple before you call this so internal variables are updated | 
| emh203 | 0:7798270c1f52 | 254 | uint16_t ReadThermocouple_FAULT() | 
| emh203 | 0:7798270c1f52 | 255 | { | 
| emh203 | 0:7798270c1f52 | 256 | return Thermocouple_FAULT; | 
| emh203 | 0:7798270c1f52 | 257 | } | 
| emh203 | 0:7798270c1f52 | 258 | |
| emh203 | 0:7798270c1f52 | 259 | |
| emh203 | 0:7798270c1f52 | 260 | float ReadInternalTemperature(uint8_t ThermocoupleIndex) | 
| emh203 | 0:7798270c1f52 | 261 | { | 
| emh203 | 0:7798270c1f52 | 262 | ReadThermocouple(ThermocoupleIndex); //this will yank out the Data | 
| emh203 | 0:7798270c1f52 | 263 | return InternalTemperature[ThermocoupleIndex]; | 
| emh203 | 0:7798270c1f52 | 264 | } | 
| emh203 | 0:7798270c1f52 | 265 | |
| emh203 | 0:7798270c1f52 | 266 | |
| emh203 | 0:7798270c1f52 | 267 | |
| emh203 | 0:7798270c1f52 | 268 | float ReadThermocouple(uint8_t ThermocoupleIndex) | 
| emh203 | 0:7798270c1f52 | 269 | { | 
| emh203 | 0:7798270c1f52 | 270 | uint8_t i=0; | 
| emh203 | 0:7798270c1f52 | 271 | uint32_t ThermocoupleData = 0; | 
| emh203 | 0:7798270c1f52 | 272 | uint8_t TempData[4]; | 
| emh203 | 0:7798270c1f52 | 273 | |
| emh203 | 0:7798270c1f52 | 274 | int16_t InternalTemp = 0; | 
| emh203 | 0:7798270c1f52 | 275 | int16_t ThermocoupleTemp = 0; | 
| emh203 | 0:7798270c1f52 | 276 | |
| emh203 | 0:7798270c1f52 | 277 | //reset SPi format | 
| emh203 | 0:7798270c1f52 | 278 | SPI1.format(8,0); | 
| emh203 | 0:7798270c1f52 | 279 | |
| emh203 | 0:7798270c1f52 | 280 | TEMP_SENSE_ADDRESS = ThermocoupleIndex & 0x1f; | 
| emh203 | 0:7798270c1f52 | 281 | |
| emh203 | 0:7798270c1f52 | 282 | TEMP_SENSE_CS = 0; | 
| emh203 | 0:7798270c1f52 | 283 | |
| emh203 | 0:7798270c1f52 | 284 | for(i=0;i<4;i++) | 
| emh203 | 0:7798270c1f52 | 285 | TempData[i] = SPI1.write(0); | 
| emh203 | 0:7798270c1f52 | 286 | |
| emh203 | 0:7798270c1f52 | 287 | TEMP_SENSE_CS = 1; | 
| emh203 | 0:7798270c1f52 | 288 | |
| emh203 | 0:7798270c1f52 | 289 | |
| emh203 | 0:7798270c1f52 | 290 | ThermocoupleData = (uint32_t)(TempData[3]) | | 
| emh203 | 0:7798270c1f52 | 291 | (((uint32_t)(TempData[2]))<<8) | | 
| emh203 | 0:7798270c1f52 | 292 | (((uint32_t)(TempData[1]))<<16) | | 
| emh203 | 0:7798270c1f52 | 293 | (((uint32_t)(TempData[0]))<<24); | 
| emh203 | 0:7798270c1f52 | 294 | |
| emh203 | 0:7798270c1f52 | 295 | |
| emh203 | 0:7798270c1f52 | 296 | if(ThermocoupleData & 0x01) | 
| emh203 | 0:7798270c1f52 | 297 | Thermocouple_OC |= (1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 298 | else | 
| emh203 | 0:7798270c1f52 | 299 | Thermocouple_OC &= ~(1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 300 | |
| emh203 | 0:7798270c1f52 | 301 | if(ThermocoupleData & 0x02) | 
| emh203 | 0:7798270c1f52 | 302 | Thermocouple_SCG |= (1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 303 | else | 
| emh203 | 0:7798270c1f52 | 304 | Thermocouple_SCG &= ~(1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 305 | |
| emh203 | 0:7798270c1f52 | 306 | if(ThermocoupleData & 0x04) | 
| emh203 | 0:7798270c1f52 | 307 | Thermocouple_SCV |= (1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 308 | else | 
| emh203 | 0:7798270c1f52 | 309 | Thermocouple_SCV &= ~(1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 310 | |
| emh203 | 0:7798270c1f52 | 311 | if(ThermocoupleData & (1<<16)) | 
| emh203 | 0:7798270c1f52 | 312 | Thermocouple_FAULT |= (1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 313 | else | 
| emh203 | 0:7798270c1f52 | 314 | Thermocouple_FAULT &= ~(1<<ThermocoupleIndex); | 
| emh203 | 0:7798270c1f52 | 315 | |
| emh203 | 0:7798270c1f52 | 316 | if(ThermocoupleData & (1<<15)) | 
| emh203 | 0:7798270c1f52 | 317 | InternalTemp = (int16_t) ( ( (ThermocoupleData>>4) & 0xFFF) | 0xF000); //Sign extend in this case.... we need to map a 12 bit signed number to 16-bits | 
| emh203 | 0:7798270c1f52 | 318 | else | 
| emh203 | 0:7798270c1f52 | 319 | InternalTemp = (int16_t)( ( (ThermocoupleData>>4) & 0xFFF)); | 
| emh203 | 0:7798270c1f52 | 320 | |
| emh203 | 0:7798270c1f52 | 321 | |
| emh203 | 0:7798270c1f52 | 322 | if(ThermocoupleData & (0x10000000)) | 
| emh203 | 0:7798270c1f52 | 323 | ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF) | 0xC000); //Sign extend in this case.... we need to map a 14 bit signed number to 16-bits | 
| emh203 | 0:7798270c1f52 | 324 | else | 
| emh203 | 0:7798270c1f52 | 325 | ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF)); | 
| emh203 | 0:7798270c1f52 | 326 | |
| emh203 | 0:7798270c1f52 | 327 | Temperature[ThermocoupleIndex] = (float)ThermocoupleTemp/4.0; | 
| emh203 | 0:7798270c1f52 | 328 | |
| emh203 | 0:7798270c1f52 | 329 | InternalTemperature[ThermocoupleIndex] = (float)InternalTemp/16.0;; | 
| emh203 | 0:7798270c1f52 | 330 | |
| emh203 | 0:7798270c1f52 | 331 | return Temperature[ThermocoupleIndex]; | 
| emh203 | 0:7798270c1f52 | 332 | } | 
| emh203 | 0:7798270c1f52 | 333 | |
| emh203 | 0:7798270c1f52 | 334 | float ReadMFC_AnalogInput(uint8_t Channel) | 
| emh203 | 0:7798270c1f52 | 335 | { | 
| emh203 | 0:7798270c1f52 | 336 | if(Channel > 7) | 
| emh203 | 0:7798270c1f52 | 337 | Channel = 7; | 
| emh203 | 0:7798270c1f52 | 338 | |
| emh203 | 0:7798270c1f52 | 339 | return ((float)(ReadRawADC(Channel)) /4095.0) * 5.0; | 
| emh203 | 0:7798270c1f52 | 340 | |
| emh203 | 0:7798270c1f52 | 341 | } | 
| emh203 | 0:7798270c1f52 | 342 | |
| emh203 | 0:7798270c1f52 | 343 | void EnableMFC_Power() | 
| emh203 | 0:7798270c1f52 | 344 | { | 
| emh203 | 0:7798270c1f52 | 345 | MFC_POWER_CONTROL = 1; | 
| emh203 | 0:7798270c1f52 | 346 | } | 
| emh203 | 0:7798270c1f52 | 347 | |
| emh203 | 0:7798270c1f52 | 348 | void DisableMFC_Power() | 
| emh203 | 0:7798270c1f52 | 349 | { | 
| emh203 | 0:7798270c1f52 | 350 | MFC_POWER_CONTROL = 0; | 
| emh203 | 0:7798270c1f52 | 351 | } | 
| emh203 | 0:7798270c1f52 | 352 | |
| emh203 | 0:7798270c1f52 | 353 | |
| emh203 | 0:7798270c1f52 | 354 | float ReadMISC_AnalogInput(uint8_t Channel) | 
| emh203 | 0:7798270c1f52 | 355 | { | 
| emh203 | 0:7798270c1f52 | 356 | |
| emh203 | 0:7798270c1f52 | 357 | if(Channel > 3) | 
| emh203 | 0:7798270c1f52 | 358 | Channel = 3; | 
| emh203 | 0:7798270c1f52 | 359 | |
| emh203 | 0:7798270c1f52 | 360 | return ((float)(ReadRawADC(Channel + 9)) /4095.0) * 5.0; | 
| emh203 | 0:7798270c1f52 | 361 | |
| emh203 | 0:7798270c1f52 | 362 | } | 
| emh203 | 0:7798270c1f52 | 363 | |
| wavenumber | 3:cb48919cd5e8 | 364 | |
| wavenumber | 3:cb48919cd5e8 | 365 | |
| emh203 | 0:7798270c1f52 | 366 | float Read4to20(uint8_t Channel) | 
| emh203 | 0:7798270c1f52 | 367 | { | 
| emh203 | 0:7798270c1f52 | 368 | |
| emh203 | 0:7798270c1f52 | 369 | if(Channel > 1) | 
| emh203 | 0:7798270c1f52 | 370 | Channel = 1; | 
| emh203 | 0:7798270c1f52 | 371 | |
| wavenumber | 4:e3eda81c97ae | 372 | return (((float)(ReadRawADC(Channel + 7)) /4095.0) * 5.0) / 240; | 
| emh203 | 0:7798270c1f52 | 373 | |
| emh203 | 0:7798270c1f52 | 374 | } | 
| emh203 | 0:7798270c1f52 | 375 | |
| emh203 | 0:7798270c1f52 | 376 | |
| wavenumber | 3:cb48919cd5e8 | 377 | float ReadBP_AnalogInput() | 
| wavenumber | 3:cb48919cd5e8 | 378 | { | 
| wavenumber | 3:cb48919cd5e8 | 379 | |
| wavenumber | 3:cb48919cd5e8 | 380 | return ((float)(ReadRawADC(15)) /4095.0) * 10.0; | 
| wavenumber | 3:cb48919cd5e8 | 381 | |
| wavenumber | 3:cb48919cd5e8 | 382 | } | 
| wavenumber | 3:cb48919cd5e8 | 383 | |
| wavenumber | 3:cb48919cd5e8 | 384 | |
| wavenumber | 3:cb48919cd5e8 | 385 | |
| wavenumber | 3:cb48919cd5e8 | 386 | |
| wavenumber | 3:cb48919cd5e8 | 387 | static uint16_t ReadRawADC_Single(uint8_t Channel) | 
| emh203 | 0:7798270c1f52 | 388 | { | 
| emh203 | 0:7798270c1f52 | 389 | uint8_t ControlByte[3]; | 
| emh203 | 0:7798270c1f52 | 390 | uint8_t ADC_Data[3]; | 
| emh203 | 0:7798270c1f52 | 391 | uint16_t V; | 
| emh203 | 0:7798270c1f52 | 392 | |
| emh203 | 0:7798270c1f52 | 393 | SPI0.format(8,0); //The ADC requires mode 0,0 | 
| emh203 | 0:7798270c1f52 | 394 | |
| emh203 | 0:7798270c1f52 | 395 | /*See Microchip manual DS21298E-page 21*/ | 
| emh203 | 0:7798270c1f52 | 396 | |
| emh203 | 0:7798270c1f52 | 397 | ControlByte[0] = (((Channel&0x07)>>2) & 0x01) | (3<<1); | 
| emh203 | 0:7798270c1f52 | 398 | ControlByte[1] = Channel<<6; | 
| emh203 | 0:7798270c1f52 | 399 | ControlByte[2] = 0; | 
| emh203 | 0:7798270c1f52 | 400 | |
| emh203 | 0:7798270c1f52 | 401 | |
| emh203 | 0:7798270c1f52 | 402 | if(Channel<8) | 
| emh203 | 0:7798270c1f52 | 403 | AIO_ADC1_CS = 0; | 
| emh203 | 0:7798270c1f52 | 404 | else | 
| emh203 | 0:7798270c1f52 | 405 | AIO_ADC2_CS = 0; | 
| emh203 | 0:7798270c1f52 | 406 | |
| emh203 | 0:7798270c1f52 | 407 | //unroll the loop | 
| emh203 | 0:7798270c1f52 | 408 | ADC_Data[0] = SPI0.write(ControlByte[0]); | 
| emh203 | 0:7798270c1f52 | 409 | ADC_Data[1] = SPI0.write(ControlByte[1]); | 
| emh203 | 0:7798270c1f52 | 410 | ADC_Data[2] = SPI0.write(ControlByte[2]); | 
| emh203 | 0:7798270c1f52 | 411 | |
| emh203 | 0:7798270c1f52 | 412 | AIO_ADC1_CS = 1; | 
| emh203 | 0:7798270c1f52 | 413 | AIO_ADC2_CS = 1; | 
| emh203 | 0:7798270c1f52 | 414 | |
| emh203 | 0:7798270c1f52 | 415 | |
| emh203 | 0:7798270c1f52 | 416 | V = ((uint16_t)(ADC_Data[1])<<8 | (uint16_t)(ADC_Data[2])) & 0xFFF; | 
| emh203 | 0:7798270c1f52 | 417 | |
| emh203 | 0:7798270c1f52 | 418 | return (V); | 
| emh203 | 0:7798270c1f52 | 419 | |
| emh203 | 0:7798270c1f52 | 420 | } | 
| emh203 | 0:7798270c1f52 | 421 | |
| wavenumber | 3:cb48919cd5e8 | 422 | #define FILTER_SIZE 64 | 
| wavenumber | 3:cb48919cd5e8 | 423 | |
| wavenumber | 3:cb48919cd5e8 | 424 | static uint16_t ReadRawADC(uint8_t Channel) | 
| wavenumber | 3:cb48919cd5e8 | 425 | { | 
| wavenumber | 3:cb48919cd5e8 | 426 | uint32_t Value = 0; | 
| wavenumber | 3:cb48919cd5e8 | 427 | |
| wavenumber | 3:cb48919cd5e8 | 428 | for(int i=0;i<FILTER_SIZE;i++) | 
| wavenumber | 3:cb48919cd5e8 | 429 | { | 
| wavenumber | 3:cb48919cd5e8 | 430 | Value+=ReadRawADC_Single(Channel); | 
| wavenumber | 3:cb48919cd5e8 | 431 | } | 
| wavenumber | 3:cb48919cd5e8 | 432 | |
| wavenumber | 3:cb48919cd5e8 | 433 | Value = Value / FILTER_SIZE; | 
| wavenumber | 3:cb48919cd5e8 | 434 | |
| wavenumber | 3:cb48919cd5e8 | 435 | return Value; | 
| wavenumber | 3:cb48919cd5e8 | 436 | |
| wavenumber | 3:cb48919cd5e8 | 437 | } | 
| emh203 | 0:7798270c1f52 | 438 | |
| emh203 | 0:7798270c1f52 | 439 | void WriteMFC_AnalogOut(uint8_t Channel,float Value) | 
| emh203 | 0:7798270c1f52 | 440 | { | 
| emh203 | 0:7798270c1f52 | 441 | |
| emh203 | 0:7798270c1f52 | 442 | if(Channel>7) | 
| emh203 | 0:7798270c1f52 | 443 | Channel = 7; | 
| emh203 | 0:7798270c1f52 | 444 | |
| emh203 | 0:7798270c1f52 | 445 | if(Value >5.0) | 
| emh203 | 0:7798270c1f52 | 446 | Value = 5.0; | 
| emh203 | 0:7798270c1f52 | 447 | |
| emh203 | 0:7798270c1f52 | 448 | if(Value<0.0) | 
| emh203 | 0:7798270c1f52 | 449 | Value = 0.0; | 
| emh203 | 0:7798270c1f52 | 450 | |
| emh203 | 0:7798270c1f52 | 451 | WriteRAW_DAC_Value(Channel,(uint16_t)((Value/5.0) * 4095)); | 
| emh203 | 0:7798270c1f52 | 452 | |
| emh203 | 0:7798270c1f52 | 453 | } | 
| emh203 | 0:7798270c1f52 | 454 | |
| emh203 | 0:7798270c1f52 | 455 | void WriteMISC_AnalogOut(uint8_t Channel,float Value) | 
| emh203 | 0:7798270c1f52 | 456 | { | 
| emh203 | 0:7798270c1f52 | 457 | if(Channel>3) | 
| emh203 | 0:7798270c1f52 | 458 | Channel = 3; | 
| emh203 | 0:7798270c1f52 | 459 | |
| emh203 | 0:7798270c1f52 | 460 | if(Value >5.0) | 
| emh203 | 0:7798270c1f52 | 461 | Value = 5.0; | 
| emh203 | 0:7798270c1f52 | 462 | |
| emh203 | 0:7798270c1f52 | 463 | if(Value<0.0) | 
| emh203 | 0:7798270c1f52 | 464 | Value = 0.0; | 
| emh203 | 0:7798270c1f52 | 465 | |
| emh203 | 0:7798270c1f52 | 466 | WriteRAW_DAC_Value(8+Channel,(uint16_t)((Value/5.0)*4095)); | 
| emh203 | 0:7798270c1f52 | 467 | } | 
| emh203 | 0:7798270c1f52 | 468 | |
| wavenumber | 3:cb48919cd5e8 | 469 | void WriteBP_AnalogOut(float Value) | 
| wavenumber | 3:cb48919cd5e8 | 470 | { | 
| wavenumber | 3:cb48919cd5e8 | 471 | |
| wavenumber | 3:cb48919cd5e8 | 472 | if(Value >10.0) | 
| wavenumber | 3:cb48919cd5e8 | 473 | Value = 10.0; | 
| wavenumber | 3:cb48919cd5e8 | 474 | |
| wavenumber | 3:cb48919cd5e8 | 475 | if(Value<0.0) | 
| wavenumber | 3:cb48919cd5e8 | 476 | Value = 0.0; | 
| wavenumber | 3:cb48919cd5e8 | 477 | |
| wavenumber | 3:cb48919cd5e8 | 478 | WriteRAW_DAC_Value(12,(uint16_t)((Value/10.0)*4095)); | 
| wavenumber | 3:cb48919cd5e8 | 479 | } | 
| wavenumber | 3:cb48919cd5e8 | 480 | |
| emh203 | 0:7798270c1f52 | 481 | |
| emh203 | 0:7798270c1f52 | 482 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data) | 
| emh203 | 0:7798270c1f52 | 483 | { | 
| emh203 | 0:7798270c1f52 | 484 | |
| emh203 | 0:7798270c1f52 | 485 | uint16_t DataOut; | 
| emh203 | 0:7798270c1f52 | 486 | |
| emh203 | 0:7798270c1f52 | 487 | if(Channel<8) | 
| emh203 | 0:7798270c1f52 | 488 | AIO_DAC1_CS = 0; | 
| emh203 | 0:7798270c1f52 | 489 | else | 
| wavenumber | 3:cb48919cd5e8 | 490 | { | 
| emh203 | 0:7798270c1f52 | 491 | AIO_DAC2_CS = 0; | 
| wavenumber | 3:cb48919cd5e8 | 492 | Channel -= 8; | 
| wavenumber | 3:cb48919cd5e8 | 493 | } | 
| emh203 | 0:7798270c1f52 | 494 | |
| emh203 | 0:7798270c1f52 | 495 | SPI0.format(8,1); //The DAC requires mode 0,1 | 
| emh203 | 0:7798270c1f52 | 496 | |
| emh203 | 0:7798270c1f52 | 497 | DataOut = ((uint16_t)(Channel) & 0x7)<<12 | (Data & 0xFFF); | 
| emh203 | 0:7798270c1f52 | 498 | |
| emh203 | 0:7798270c1f52 | 499 | SPI0.write((DataOut>>8)&0xFF); | 
| emh203 | 0:7798270c1f52 | 500 | SPI0.write(DataOut&0xFF); | 
| emh203 | 0:7798270c1f52 | 501 | |
| emh203 | 0:7798270c1f52 | 502 | AIO_DAC1_CS = 1; | 
| emh203 | 0:7798270c1f52 | 503 | AIO_DAC2_CS = 1; | 
| emh203 | 0:7798270c1f52 | 504 | |
| emh203 | 0:7798270c1f52 | 505 | } | 
| emh203 | 0:7798270c1f52 | 506 | |
| emh203 | 0:7798270c1f52 | 507 | |
| emh203 | 0:7798270c1f52 | 508 | |
| emh203 | 0:7798270c1f52 | 509 | |
| emh203 | 0:7798270c1f52 | 510 | #define MAX_TERMINAL_LINE_CHARS 128 | 
| emh203 | 0:7798270c1f52 | 511 | #define MAX_TERMINAL_CMD_CHARS 64 | 
| emh203 | 0:7798270c1f52 | 512 | |
| emh203 | 0:7798270c1f52 | 513 | #ifndef TRUE | 
| emh203 | 0:7798270c1f52 | 514 | #define TRUE 1 | 
| emh203 | 0:7798270c1f52 | 515 | #endif | 
| emh203 | 0:7798270c1f52 | 516 | |
| emh203 | 0:7798270c1f52 | 517 | #ifndef FALSE | 
| emh203 | 0:7798270c1f52 | 518 | #define FALSE 0 | 
| emh203 | 0:7798270c1f52 | 519 | #endif | 
| emh203 | 0:7798270c1f52 | 520 | |
| emh203 | 0:7798270c1f52 | 521 | typedef void (*TerminalCallback)(char *); | 
| emh203 | 0:7798270c1f52 | 522 | |
| emh203 | 0:7798270c1f52 | 523 | |
| emh203 | 0:7798270c1f52 | 524 | typedef struct | 
| emh203 | 0:7798270c1f52 | 525 | { | 
| emh203 | 0:7798270c1f52 | 526 | const char *CommandString; | 
| emh203 | 0:7798270c1f52 | 527 | TerminalCallback Callback; | 
| emh203 | 0:7798270c1f52 | 528 | const char *HelpString; | 
| emh203 | 0:7798270c1f52 | 529 | |
| emh203 | 0:7798270c1f52 | 530 | } TerminalCallbackRecord; | 
| emh203 | 0:7798270c1f52 | 531 | |
| emh203 | 0:7798270c1f52 | 532 | //Callback function prototypes | 
| emh203 | 0:7798270c1f52 | 533 | void TerminalCmd_Help(char *arg); | 
| emh203 | 0:7798270c1f52 | 534 | void TerminalCmd_Stub(char *arg); | 
| emh203 | 0:7798270c1f52 | 535 | void TerminalCmd_EnableHeater(char *arg); | 
| emh203 | 0:7798270c1f52 | 536 | void TerminalCmd_DisableHeater(char *arg); | 
| emh203 | 0:7798270c1f52 | 537 | void TerminalCmd_EnableSolenoidValve(char *arg); | 
| emh203 | 0:7798270c1f52 | 538 | void TerminalCmd_DisableSolenoidValue(char *arg); | 
| emh203 | 0:7798270c1f52 | 539 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg); | 
| emh203 | 0:7798270c1f52 | 540 | void TerminalCmd_EnableMiscDigitalOutput(char *arg); | 
| emh203 | 0:7798270c1f52 | 541 | void TerminalCmd_DisableMiscDigitalOutput(char *arg); | 
| emh203 | 0:7798270c1f52 | 542 | void TerminalCmd_FlushDigitalIO(char *arg); | 
| emh203 | 0:7798270c1f52 | 543 | void TerminalCmd_FanOn(char *arg); | 
| emh203 | 0:7798270c1f52 | 544 | void TerminalCmd_FanOff(char *arg); | 
| emh203 | 0:7798270c1f52 | 545 | void TerminalCmd_Buzz(char *arg); | 
| emh203 | 0:7798270c1f52 | 546 | void TerminalCmd_T(char *arg); | 
| emh203 | 0:7798270c1f52 | 547 | void TerminalCmd_MFCI(char *arg); | 
| emh203 | 0:7798270c1f52 | 548 | void TerminalCmd_MFCO(char *arg); | 
| emh203 | 0:7798270c1f52 | 549 | void TerminalCmd_4TO20(char *arg); | 
| emh203 | 0:7798270c1f52 | 550 | void TerminalCmd_AIN(char *arg); | 
| emh203 | 0:7798270c1f52 | 551 | void TerminalCmd_MFCON(char *arg); | 
| emh203 | 0:7798270c1f52 | 552 | void TerminalCmd_MFCOFF(char *arg); | 
| emh203 | 0:7798270c1f52 | 553 | void TerminalCmd_AOUT(char *arg); | 
| emh203 | 0:7798270c1f52 | 554 | void TerminalCmd_Reset(char *arg); | 
| wavenumber | 2:73a028278c5c | 555 | void TerminalCmd_ECHO_OFF(char *arg); | 
| wavenumber | 3:cb48919cd5e8 | 556 | void TerminalCmd_BPOUT(char *arg); | 
| wavenumber | 3:cb48919cd5e8 | 557 | void TerminalCmd_BPIN(char *arg); | 
| wavenumber | 6:6a870e1e52c1 | 558 | void TerminalCmd_P0(char *arg); | 
| wavenumber | 6:6a870e1e52c1 | 559 | void TerminalCmd_P1(char *arg); | 
| emh203 | 0:7798270c1f52 | 560 | |
| emh203 | 0:7798270c1f52 | 561 | //Populate this array with the callback functions and their terminal command string | 
| emh203 | 0:7798270c1f52 | 562 | TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"}, | 
| emh203 | 0:7798270c1f52 | 563 | |
| emh203 | 0:7798270c1f52 | 564 | {"help",TerminalCmd_Help,"Lists available commands"}, | 
| emh203 | 0:7798270c1f52 | 565 | |
| emh203 | 0:7798270c1f52 | 566 | {"EH",TerminalCmd_EnableHeater,"Enables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 567 | |
| emh203 | 0:7798270c1f52 | 568 | {"DH",TerminalCmd_DisableHeater,"Disables a heater channel. Argument should be between 0 and 7. Outputs will update when a FDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 569 | |
| emh203 | 0:7798270c1f52 | 570 | {"ESV",TerminalCmd_EnableSolenoidValve,"Enables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 571 | |
| emh203 | 0:7798270c1f52 | 572 | {"DSV",TerminalCmd_DisableSolenoidValue,"Disables a solenoid channel. Argument should be between 0 and 11. Outputs will update when a FFDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 573 | |
| emh203 | 0:7798270c1f52 | 574 | {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."}, | 
| emh203 | 0:7798270c1f52 | 575 | |
| emh203 | 0:7798270c1f52 | 576 | {"EMDO",TerminalCmd_EnableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 577 | |
| emh203 | 0:7798270c1f52 | 578 | {"DMDO",TerminalCmd_DisableMiscDigitalOutput,"Enables a misc. digital output. Argument should be between 0 and 3. Output will update when a FDIO command is issued"}, | 
| emh203 | 0:7798270c1f52 | 579 | |
| emh203 | 0:7798270c1f52 | 580 | {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"}, | 
| emh203 | 0:7798270c1f52 | 581 | |
| emh203 | 0:7798270c1f52 | 582 | {"FON",TerminalCmd_FanOn,"Turns on the fans"}, | 
| emh203 | 0:7798270c1f52 | 583 | |
| emh203 | 0:7798270c1f52 | 584 | {"FOFF",TerminalCmd_FanOff,"Turns off the fans"}, | 
| emh203 | 0:7798270c1f52 | 585 | |
| emh203 | 0:7798270c1f52 | 586 | {"BUZZ",TerminalCmd_Buzz,"Buzz for a little bit. Argument should be a floating point number representing the number of seconds to buzz"}, | 
| emh203 | 0:7798270c1f52 | 587 | |
| emh203 | 0:7798270c1f52 | 588 | {"T",TerminalCmd_T,"Read thermocouple channel"}, | 
| emh203 | 0:7798270c1f52 | 589 | |
| emh203 | 0:7798270c1f52 | 590 | {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"}, | 
| emh203 | 0:7798270c1f52 | 591 | |
| emh203 | 0:7798270c1f52 | 592 | {"MFCO",TerminalCmd_MFCO,"Sets voltage at MFC output channel. First argument should be the channel. Second argument should be the voltage. I.E. MFCO 1.45"}, | 
| emh203 | 0:7798270c1f52 | 593 | |
| emh203 | 0:7798270c1f52 | 594 | {"AOUT",TerminalCmd_AOUT,"Sets voltage at misc. output channel. First argument should be the channel. Second argument should be the voltage. I.E. AOUT 3.211"}, | 
| emh203 | 0:7798270c1f52 | 595 | |
| emh203 | 0:7798270c1f52 | 596 | {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"}, | 
| emh203 | 0:7798270c1f52 | 597 | |
| emh203 | 0:7798270c1f52 | 598 | {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"}, | 
| emh203 | 0:7798270c1f52 | 599 | |
| emh203 | 0:7798270c1f52 | 600 | {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"}, | 
| emh203 | 0:7798270c1f52 | 601 | |
| wavenumber | 2:73a028278c5c | 602 | {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"}, | 
| wavenumber | 2:73a028278c5c | 603 | |
| wavenumber | 3:cb48919cd5e8 | 604 | {"BPOUT",TerminalCmd_BPOUT,"Sets a control voltage between 0 and 10 for the backpressure regulator. I.E. BPOUT 1.21"}, | 
| wavenumber | 3:cb48919cd5e8 | 605 | |
| wavenumber | 3:cb48919cd5e8 | 606 | {"BPIN",TerminalCmd_BPIN,"Reads the Back pressure regulator feedback. I.E. BPIN "}, | 
| wavenumber | 3:cb48919cd5e8 | 607 | |
| wavenumber | 6:6a870e1e52c1 | 608 | {"P0",TerminalCmd_P0,"Sends a command over RS232 port 0 to the Pump. A carriage return will be added automatically."}, | 
| wavenumber | 6:6a870e1e52c1 | 609 | |
| wavenumber | 6:6a870e1e52c1 | 610 | {"P1",TerminalCmd_P1,"Sends a command over RS232 port 0 to the Pump. A carriage return will be added automatically."}, | 
| wavenumber | 6:6a870e1e52c1 | 611 | |
| wavenumber | 3:cb48919cd5e8 | 612 | |
| wavenumber | 2:73a028278c5c | 613 | {"ECHO_OFF",TerminalCmd_ECHO_OFF,"Disables echoing of characters"} | 
| emh203 | 0:7798270c1f52 | 614 | }; | 
| emh203 | 0:7798270c1f52 | 615 | |
| emh203 | 0:7798270c1f52 | 616 | |
| emh203 | 0:7798270c1f52 | 617 | extern "C" void mbed_reset(); | 
| emh203 | 0:7798270c1f52 | 618 | |
| emh203 | 0:7798270c1f52 | 619 | void TerminalCmd_Reset(char *arg) | 
| emh203 | 0:7798270c1f52 | 620 | { | 
| emh203 | 0:7798270c1f52 | 621 | mbed_reset(); | 
| emh203 | 0:7798270c1f52 | 622 | } | 
| emh203 | 0:7798270c1f52 | 623 | |
| wavenumber | 2:73a028278c5c | 624 | |
| wavenumber | 2:73a028278c5c | 625 | |
| emh203 | 0:7798270c1f52 | 626 | void TerminalCmd_Stub(char *arg) | 
| emh203 | 0:7798270c1f52 | 627 | { | 
| emh203 | 0:7798270c1f52 | 628 | PC.printf("stub \r\n"); | 
| emh203 | 0:7798270c1f52 | 629 | } | 
| emh203 | 0:7798270c1f52 | 630 | |
| wavenumber | 2:73a028278c5c | 631 | void TerminalCmd_ECHO_OFF(char *arg) | 
| wavenumber | 2:73a028278c5c | 632 | { | 
| wavenumber | 2:73a028278c5c | 633 | TerminalEcho = 0; | 
| wavenumber | 2:73a028278c5c | 634 | } | 
| wavenumber | 2:73a028278c5c | 635 | |
| wavenumber | 6:6a870e1e52c1 | 636 | |
| wavenumber | 6:6a870e1e52c1 | 637 | void TerminalCmd_P0(char *arg) | 
| wavenumber | 6:6a870e1e52c1 | 638 | { | 
| wavenumber | 6:6a870e1e52c1 | 639 | RS232_0.printf("%s\r",arg); | 
| wavenumber | 6:6a870e1e52c1 | 640 | } | 
| wavenumber | 6:6a870e1e52c1 | 641 | |
| wavenumber | 6:6a870e1e52c1 | 642 | void TerminalCmd_P1(char *arg) | 
| wavenumber | 6:6a870e1e52c1 | 643 | { | 
| wavenumber | 6:6a870e1e52c1 | 644 | RS232_1.printf("%s\r",arg); | 
| wavenumber | 6:6a870e1e52c1 | 645 | } | 
| wavenumber | 6:6a870e1e52c1 | 646 | |
| wavenumber | 6:6a870e1e52c1 | 647 | |
| emh203 | 0:7798270c1f52 | 648 | void TerminalCmd_MFCI(char *arg) | 
| emh203 | 0:7798270c1f52 | 649 | { | 
| emh203 | 0:7798270c1f52 | 650 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 651 | float Data; | 
| emh203 | 0:7798270c1f52 | 652 | |
| emh203 | 0:7798270c1f52 | 653 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 654 | { | 
| emh203 | 0:7798270c1f52 | 655 | if(Channel>=0 && Channel <=6) | 
| emh203 | 0:7798270c1f52 | 656 | { | 
| emh203 | 0:7798270c1f52 | 657 | Data = ReadMFC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 658 | PC.printf("MFCI:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 659 | } | 
| emh203 | 0:7798270c1f52 | 660 | else | 
| emh203 | 0:7798270c1f52 | 661 | { | 
| emh203 | 0:7798270c1f52 | 662 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel); | 
| emh203 | 0:7798270c1f52 | 663 | } | 
| emh203 | 0:7798270c1f52 | 664 | } | 
| emh203 | 0:7798270c1f52 | 665 | else | 
| emh203 | 0:7798270c1f52 | 666 | { | 
| emh203 | 0:7798270c1f52 | 667 | for(Channel = 0; Channel<=6; Channel++) | 
| emh203 | 0:7798270c1f52 | 668 | { | 
| emh203 | 0:7798270c1f52 | 669 | Data = ReadMFC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 670 | PC.printf("MFCI:%d:%.3f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 671 | } | 
| emh203 | 0:7798270c1f52 | 672 | } | 
| emh203 | 0:7798270c1f52 | 673 | } | 
| emh203 | 0:7798270c1f52 | 674 | |
| emh203 | 0:7798270c1f52 | 675 | void TerminalCmd_MFCON(char *arg) | 
| emh203 | 0:7798270c1f52 | 676 | { | 
| emh203 | 0:7798270c1f52 | 677 | EnableMFC_Power(); | 
| emh203 | 0:7798270c1f52 | 678 | } | 
| emh203 | 0:7798270c1f52 | 679 | |
| emh203 | 0:7798270c1f52 | 680 | |
| emh203 | 0:7798270c1f52 | 681 | void TerminalCmd_MFCOFF(char *arg) | 
| emh203 | 0:7798270c1f52 | 682 | { | 
| emh203 | 0:7798270c1f52 | 683 | DisableMFC_Power(); | 
| emh203 | 0:7798270c1f52 | 684 | } | 
| emh203 | 0:7798270c1f52 | 685 | |
| emh203 | 0:7798270c1f52 | 686 | |
| emh203 | 0:7798270c1f52 | 687 | void TerminalCmd_MFCO(char *arg) | 
| emh203 | 0:7798270c1f52 | 688 | { | 
| emh203 | 0:7798270c1f52 | 689 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 690 | float Data = 0.0; | 
| emh203 | 0:7798270c1f52 | 691 | |
| emh203 | 0:7798270c1f52 | 692 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) | 
| emh203 | 0:7798270c1f52 | 693 | { | 
| emh203 | 0:7798270c1f52 | 694 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 695 | { | 
| emh203 | 0:7798270c1f52 | 696 | WriteMFC_AnalogOut(Channel,Data); | 
| emh203 | 0:7798270c1f52 | 697 | } | 
| emh203 | 0:7798270c1f52 | 698 | else | 
| emh203 | 0:7798270c1f52 | 699 | { | 
| emh203 | 0:7798270c1f52 | 700 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); | 
| emh203 | 0:7798270c1f52 | 701 | } | 
| emh203 | 0:7798270c1f52 | 702 | } | 
| emh203 | 0:7798270c1f52 | 703 | else | 
| emh203 | 0:7798270c1f52 | 704 | { | 
| emh203 | 0:7798270c1f52 | 705 | PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. MFCO 2 4.45",arg); | 
| emh203 | 0:7798270c1f52 | 706 | } | 
| emh203 | 0:7798270c1f52 | 707 | } | 
| emh203 | 0:7798270c1f52 | 708 | |
| emh203 | 0:7798270c1f52 | 709 | void TerminalCmd_AOUT(char *arg) | 
| emh203 | 0:7798270c1f52 | 710 | { | 
| emh203 | 0:7798270c1f52 | 711 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 712 | float Data = 0.0; | 
| emh203 | 0:7798270c1f52 | 713 | |
| emh203 | 0:7798270c1f52 | 714 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) | 
| emh203 | 0:7798270c1f52 | 715 | { | 
| emh203 | 0:7798270c1f52 | 716 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 717 | { | 
| emh203 | 0:7798270c1f52 | 718 | WriteMISC_AnalogOut(Channel,Data); | 
| emh203 | 0:7798270c1f52 | 719 | } | 
| emh203 | 0:7798270c1f52 | 720 | else | 
| emh203 | 0:7798270c1f52 | 721 | { | 
| emh203 | 0:7798270c1f52 | 722 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 723 | } | 
| emh203 | 0:7798270c1f52 | 724 | } | 
| emh203 | 0:7798270c1f52 | 725 | else | 
| emh203 | 0:7798270c1f52 | 726 | { | 
| emh203 | 0:7798270c1f52 | 727 | PC.printf("Bad argument... %s. Channel should be an integer between 0 and 7 and value should be a float between 0.0 and 5.0. i.e. AOUT 1 1.25",arg); | 
| emh203 | 0:7798270c1f52 | 728 | } | 
| emh203 | 0:7798270c1f52 | 729 | } | 
| emh203 | 0:7798270c1f52 | 730 | |
| wavenumber | 3:cb48919cd5e8 | 731 | |
| wavenumber | 3:cb48919cd5e8 | 732 | void TerminalCmd_BPOUT(char *arg) | 
| wavenumber | 3:cb48919cd5e8 | 733 | { | 
| wavenumber | 3:cb48919cd5e8 | 734 | float Data = 0.0; | 
| wavenumber | 3:cb48919cd5e8 | 735 | |
| wavenumber | 3:cb48919cd5e8 | 736 | if(sscanf(arg,"%f",&Data) == 1) | 
| wavenumber | 3:cb48919cd5e8 | 737 | { | 
| wavenumber | 3:cb48919cd5e8 | 738 | WriteBP_AnalogOut(Data); | 
| wavenumber | 3:cb48919cd5e8 | 739 | } | 
| wavenumber | 3:cb48919cd5e8 | 740 | else | 
| wavenumber | 3:cb48919cd5e8 | 741 | { | 
| wavenumber | 3:cb48919cd5e8 | 742 | PC.printf("Bad argument... %s. value should be a float between 0.0 and 10.0. i.e. BPOUT 1.25",arg); | 
| wavenumber | 3:cb48919cd5e8 | 743 | } | 
| wavenumber | 3:cb48919cd5e8 | 744 | } | 
| wavenumber | 3:cb48919cd5e8 | 745 | |
| wavenumber | 3:cb48919cd5e8 | 746 | void TerminalCmd_BPIN(char *arg) | 
| wavenumber | 3:cb48919cd5e8 | 747 | { | 
| wavenumber | 3:cb48919cd5e8 | 748 | float Data; | 
| wavenumber | 3:cb48919cd5e8 | 749 | Data = ReadBP_AnalogInput(); | 
| wavenumber | 3:cb48919cd5e8 | 750 | PC.printf("BPIN:%.3f",Data); | 
| wavenumber | 3:cb48919cd5e8 | 751 | } | 
| wavenumber | 3:cb48919cd5e8 | 752 | |
| emh203 | 0:7798270c1f52 | 753 | void TerminalCmd_4TO20(char *arg) | 
| emh203 | 0:7798270c1f52 | 754 | { | 
| emh203 | 0:7798270c1f52 | 755 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 756 | float Data; | 
| emh203 | 0:7798270c1f52 | 757 | |
| emh203 | 0:7798270c1f52 | 758 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 759 | { | 
| emh203 | 0:7798270c1f52 | 760 | if(Channel>=0 && Channel <=1) | 
| emh203 | 0:7798270c1f52 | 761 | { | 
| emh203 | 0:7798270c1f52 | 762 | Data = Read4to20(Channel); | 
| emh203 | 0:7798270c1f52 | 763 | PC.printf("4TO20:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 764 | } | 
| emh203 | 0:7798270c1f52 | 765 | else | 
| emh203 | 0:7798270c1f52 | 766 | { | 
| emh203 | 0:7798270c1f52 | 767 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); | 
| emh203 | 0:7798270c1f52 | 768 | } | 
| emh203 | 0:7798270c1f52 | 769 | } | 
| emh203 | 0:7798270c1f52 | 770 | else | 
| emh203 | 0:7798270c1f52 | 771 | { | 
| emh203 | 0:7798270c1f52 | 772 | |
| emh203 | 0:7798270c1f52 | 773 | for(Channel = 0;Channel<=1;Channel++) | 
| emh203 | 0:7798270c1f52 | 774 | { | 
| emh203 | 0:7798270c1f52 | 775 | Data = Read4to20(Channel); | 
| emh203 | 1:d64ac853223c | 776 | PC.printf("4TO20:%d:%.5f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 777 | } | 
| emh203 | 0:7798270c1f52 | 778 | |
| emh203 | 0:7798270c1f52 | 779 | } | 
| emh203 | 0:7798270c1f52 | 780 | |
| emh203 | 0:7798270c1f52 | 781 | |
| emh203 | 0:7798270c1f52 | 782 | } | 
| emh203 | 0:7798270c1f52 | 783 | |
| emh203 | 0:7798270c1f52 | 784 | void TerminalCmd_AIN(char *arg) | 
| emh203 | 0:7798270c1f52 | 785 | { | 
| emh203 | 0:7798270c1f52 | 786 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 787 | float Data; | 
| emh203 | 0:7798270c1f52 | 788 | |
| emh203 | 0:7798270c1f52 | 789 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 790 | { | 
| emh203 | 0:7798270c1f52 | 791 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 792 | { | 
| emh203 | 0:7798270c1f52 | 793 | Data = ReadMISC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 794 | PC.printf("AIN:%d:%.3f",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 795 | } | 
| emh203 | 0:7798270c1f52 | 796 | else | 
| emh203 | 0:7798270c1f52 | 797 | { | 
| emh203 | 0:7798270c1f52 | 798 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 799 | } | 
| emh203 | 0:7798270c1f52 | 800 | } | 
| emh203 | 0:7798270c1f52 | 801 | else | 
| emh203 | 0:7798270c1f52 | 802 | { | 
| emh203 | 0:7798270c1f52 | 803 | for(Channel = 0;Channel<=3;Channel++) | 
| emh203 | 0:7798270c1f52 | 804 | { | 
| emh203 | 0:7798270c1f52 | 805 | Data = ReadMISC_AnalogInput(Channel); | 
| emh203 | 0:7798270c1f52 | 806 | PC.printf("AIN:%d:%.3f\r\n",Channel,Data); | 
| emh203 | 0:7798270c1f52 | 807 | } | 
| emh203 | 0:7798270c1f52 | 808 | } | 
| emh203 | 0:7798270c1f52 | 809 | } | 
| emh203 | 0:7798270c1f52 | 810 | |
| emh203 | 0:7798270c1f52 | 811 | |
| emh203 | 0:7798270c1f52 | 812 | |
| emh203 | 0:7798270c1f52 | 813 | void TerminalCmd_EnableHeater(char *arg) | 
| emh203 | 0:7798270c1f52 | 814 | { | 
| emh203 | 0:7798270c1f52 | 815 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 816 | |
| emh203 | 0:7798270c1f52 | 817 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 818 | { | 
| emh203 | 0:7798270c1f52 | 819 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 820 | { | 
| emh203 | 0:7798270c1f52 | 821 | EnableHeater(Channel); | 
| emh203 | 0:7798270c1f52 | 822 | } | 
| emh203 | 0:7798270c1f52 | 823 | else | 
| emh203 | 0:7798270c1f52 | 824 | { | 
| emh203 | 0:7798270c1f52 | 825 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); | 
| emh203 | 0:7798270c1f52 | 826 | } | 
| emh203 | 0:7798270c1f52 | 827 | } | 
| emh203 | 0:7798270c1f52 | 828 | else | 
| emh203 | 0:7798270c1f52 | 829 | { | 
| emh203 | 0:7798270c1f52 | 830 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); | 
| emh203 | 0:7798270c1f52 | 831 | } | 
| emh203 | 0:7798270c1f52 | 832 | } | 
| emh203 | 0:7798270c1f52 | 833 | |
| emh203 | 0:7798270c1f52 | 834 | void TerminalCmd_DisableHeater(char *arg) | 
| emh203 | 0:7798270c1f52 | 835 | { | 
| emh203 | 0:7798270c1f52 | 836 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 837 | |
| emh203 | 0:7798270c1f52 | 838 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 839 | { | 
| emh203 | 0:7798270c1f52 | 840 | if(Channel>=0 && Channel <=7) | 
| emh203 | 0:7798270c1f52 | 841 | { | 
| emh203 | 0:7798270c1f52 | 842 | DisableHeater(Channel); | 
| emh203 | 0:7798270c1f52 | 843 | } | 
| emh203 | 0:7798270c1f52 | 844 | else | 
| emh203 | 0:7798270c1f52 | 845 | { | 
| emh203 | 0:7798270c1f52 | 846 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); | 
| emh203 | 0:7798270c1f52 | 847 | } | 
| emh203 | 0:7798270c1f52 | 848 | } | 
| emh203 | 0:7798270c1f52 | 849 | else | 
| emh203 | 0:7798270c1f52 | 850 | { | 
| emh203 | 0:7798270c1f52 | 851 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); | 
| emh203 | 0:7798270c1f52 | 852 | } | 
| emh203 | 0:7798270c1f52 | 853 | |
| emh203 | 0:7798270c1f52 | 854 | } | 
| emh203 | 0:7798270c1f52 | 855 | |
| emh203 | 0:7798270c1f52 | 856 | void TerminalCmd_EnableSolenoidValve(char *arg) | 
| emh203 | 0:7798270c1f52 | 857 | { | 
| emh203 | 0:7798270c1f52 | 858 | |
| emh203 | 0:7798270c1f52 | 859 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 860 | |
| emh203 | 0:7798270c1f52 | 861 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 862 | { | 
| emh203 | 0:7798270c1f52 | 863 | if(Channel>=0 && Channel <=11) | 
| emh203 | 0:7798270c1f52 | 864 | { | 
| emh203 | 0:7798270c1f52 | 865 | EnableSolenoidValve(Channel); | 
| emh203 | 0:7798270c1f52 | 866 | } | 
| emh203 | 0:7798270c1f52 | 867 | else | 
| emh203 | 0:7798270c1f52 | 868 | { | 
| emh203 | 0:7798270c1f52 | 869 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); | 
| emh203 | 0:7798270c1f52 | 870 | } | 
| emh203 | 0:7798270c1f52 | 871 | } | 
| emh203 | 0:7798270c1f52 | 872 | else | 
| emh203 | 0:7798270c1f52 | 873 | { | 
| emh203 | 0:7798270c1f52 | 874 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); | 
| emh203 | 0:7798270c1f52 | 875 | } | 
| emh203 | 0:7798270c1f52 | 876 | } | 
| emh203 | 0:7798270c1f52 | 877 | |
| emh203 | 0:7798270c1f52 | 878 | void TerminalCmd_DisableSolenoidValue(char *arg) | 
| emh203 | 0:7798270c1f52 | 879 | { | 
| emh203 | 0:7798270c1f52 | 880 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 881 | |
| emh203 | 0:7798270c1f52 | 882 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 883 | { | 
| emh203 | 0:7798270c1f52 | 884 | if( Channel >= 0 && Channel <= 11) | 
| emh203 | 0:7798270c1f52 | 885 | { | 
| emh203 | 0:7798270c1f52 | 886 | DisableSolenoidValue(Channel); | 
| emh203 | 0:7798270c1f52 | 887 | } | 
| emh203 | 0:7798270c1f52 | 888 | else | 
| emh203 | 0:7798270c1f52 | 889 | { | 
| emh203 | 0:7798270c1f52 | 890 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); | 
| emh203 | 0:7798270c1f52 | 891 | } | 
| emh203 | 0:7798270c1f52 | 892 | } | 
| emh203 | 0:7798270c1f52 | 893 | else | 
| emh203 | 0:7798270c1f52 | 894 | { | 
| emh203 | 0:7798270c1f52 | 895 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); | 
| emh203 | 0:7798270c1f52 | 896 | } | 
| emh203 | 0:7798270c1f52 | 897 | |
| emh203 | 0:7798270c1f52 | 898 | } | 
| emh203 | 0:7798270c1f52 | 899 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg) | 
| emh203 | 0:7798270c1f52 | 900 | { | 
| emh203 | 0:7798270c1f52 | 901 | |
| emh203 | 0:7798270c1f52 | 902 | DisableAllHeatersAndSolenoids(); | 
| emh203 | 0:7798270c1f52 | 903 | |
| emh203 | 0:7798270c1f52 | 904 | } | 
| emh203 | 0:7798270c1f52 | 905 | |
| emh203 | 0:7798270c1f52 | 906 | void TerminalCmd_EnableMiscDigitalOutput(char *arg) | 
| emh203 | 0:7798270c1f52 | 907 | { | 
| emh203 | 0:7798270c1f52 | 908 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 909 | |
| emh203 | 0:7798270c1f52 | 910 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 911 | { | 
| emh203 | 0:7798270c1f52 | 912 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 913 | { | 
| emh203 | 0:7798270c1f52 | 914 | EnableMiscDigitalOutput(Channel); | 
| emh203 | 0:7798270c1f52 | 915 | } | 
| emh203 | 0:7798270c1f52 | 916 | else | 
| emh203 | 0:7798270c1f52 | 917 | { | 
| emh203 | 0:7798270c1f52 | 918 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 919 | } | 
| emh203 | 0:7798270c1f52 | 920 | } | 
| emh203 | 0:7798270c1f52 | 921 | else | 
| emh203 | 0:7798270c1f52 | 922 | { | 
| emh203 | 0:7798270c1f52 | 923 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); | 
| emh203 | 0:7798270c1f52 | 924 | } | 
| emh203 | 0:7798270c1f52 | 925 | |
| emh203 | 0:7798270c1f52 | 926 | } | 
| emh203 | 0:7798270c1f52 | 927 | |
| emh203 | 0:7798270c1f52 | 928 | void TerminalCmd_DisableMiscDigitalOutput(char *arg) | 
| emh203 | 0:7798270c1f52 | 929 | { | 
| emh203 | 0:7798270c1f52 | 930 | int Channel = -1; | 
| emh203 | 0:7798270c1f52 | 931 | |
| emh203 | 0:7798270c1f52 | 932 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 933 | { | 
| emh203 | 0:7798270c1f52 | 934 | if(Channel>=0 && Channel <=3) | 
| emh203 | 0:7798270c1f52 | 935 | { | 
| emh203 | 0:7798270c1f52 | 936 | DisableMiscDigitalOutput(Channel); | 
| emh203 | 0:7798270c1f52 | 937 | } | 
| emh203 | 0:7798270c1f52 | 938 | else | 
| emh203 | 0:7798270c1f52 | 939 | { | 
| emh203 | 0:7798270c1f52 | 940 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); | 
| emh203 | 0:7798270c1f52 | 941 | } | 
| emh203 | 0:7798270c1f52 | 942 | } | 
| emh203 | 0:7798270c1f52 | 943 | else | 
| emh203 | 0:7798270c1f52 | 944 | { | 
| emh203 | 0:7798270c1f52 | 945 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); | 
| emh203 | 0:7798270c1f52 | 946 | } | 
| emh203 | 0:7798270c1f52 | 947 | |
| emh203 | 0:7798270c1f52 | 948 | } | 
| emh203 | 0:7798270c1f52 | 949 | |
| emh203 | 0:7798270c1f52 | 950 | void TerminalCmd_FlushDigitalIO(char *arg) | 
| emh203 | 0:7798270c1f52 | 951 | { | 
| emh203 | 0:7798270c1f52 | 952 | FlushDigitalIO(); | 
| emh203 | 0:7798270c1f52 | 953 | } | 
| emh203 | 0:7798270c1f52 | 954 | |
| emh203 | 0:7798270c1f52 | 955 | void TerminalCmd_FanOn(char *arg) | 
| emh203 | 0:7798270c1f52 | 956 | { | 
| emh203 | 0:7798270c1f52 | 957 | SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off | 
| wavenumber | 2:73a028278c5c | 958 | MBED_LED1 = 1; | 
| emh203 | 0:7798270c1f52 | 959 | } | 
| emh203 | 0:7798270c1f52 | 960 | |
| emh203 | 0:7798270c1f52 | 961 | void TerminalCmd_FanOff(char *arg) | 
| emh203 | 0:7798270c1f52 | 962 | { | 
| emh203 | 0:7798270c1f52 | 963 | SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off | 
| wavenumber | 2:73a028278c5c | 964 | MBED_LED1 = 0; | 
| emh203 | 0:7798270c1f52 | 965 | } | 
| emh203 | 0:7798270c1f52 | 966 | |
| emh203 | 0:7798270c1f52 | 967 | void TerminalCmd_Fan(char *arg) | 
| emh203 | 0:7798270c1f52 | 968 | { | 
| emh203 | 0:7798270c1f52 | 969 | int Speed = -1; | 
| emh203 | 0:7798270c1f52 | 970 | |
| emh203 | 0:7798270c1f52 | 971 | if(sscanf(arg,"%d",&Speed) == 1) | 
| emh203 | 0:7798270c1f52 | 972 | { | 
| emh203 | 0:7798270c1f52 | 973 | if(Speed>=0 && Speed<=100) | 
| emh203 | 0:7798270c1f52 | 974 | { | 
| emh203 | 0:7798270c1f52 | 975 | SetFanSpeed(Speed); | 
| emh203 | 0:7798270c1f52 | 976 | } | 
| emh203 | 0:7798270c1f52 | 977 | else | 
| emh203 | 0:7798270c1f52 | 978 | { | 
| emh203 | 0:7798270c1f52 | 979 | PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed); | 
| emh203 | 0:7798270c1f52 | 980 | } | 
| emh203 | 0:7798270c1f52 | 981 | } | 
| emh203 | 0:7798270c1f52 | 982 | else | 
| emh203 | 0:7798270c1f52 | 983 | { | 
| emh203 | 0:7798270c1f52 | 984 | PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg); | 
| emh203 | 0:7798270c1f52 | 985 | } | 
| emh203 | 0:7798270c1f52 | 986 | |
| emh203 | 0:7798270c1f52 | 987 | } | 
| emh203 | 0:7798270c1f52 | 988 | |
| emh203 | 0:7798270c1f52 | 989 | |
| emh203 | 0:7798270c1f52 | 990 | void TerminalCmd_T(char *arg) | 
| emh203 | 0:7798270c1f52 | 991 | { | 
| emh203 | 0:7798270c1f52 | 992 | float Temp = 0; | 
| emh203 | 0:7798270c1f52 | 993 | int Channel = -1; | 
| wavenumber | 5:b56a4592aac0 | 994 | int Status = 0; | 
| emh203 | 0:7798270c1f52 | 995 | |
| emh203 | 0:7798270c1f52 | 996 | if(sscanf(arg,"%d",&Channel) == 1) | 
| emh203 | 0:7798270c1f52 | 997 | { | 
| emh203 | 0:7798270c1f52 | 998 | Temp = ReadThermocouple(Channel); | 
| wavenumber | 5:b56a4592aac0 | 999 | |
| wavenumber | 5:b56a4592aac0 | 1000 | if(ReadThermocouple_FAULT() & (1<<Channel)) | 
| wavenumber | 5:b56a4592aac0 | 1001 | { | 
| wavenumber | 5:b56a4592aac0 | 1002 | Status = 1; | 
| wavenumber | 5:b56a4592aac0 | 1003 | } | 
| wavenumber | 5:b56a4592aac0 | 1004 | else | 
| wavenumber | 5:b56a4592aac0 | 1005 | { | 
| wavenumber | 5:b56a4592aac0 | 1006 | Status = 0; | 
| wavenumber | 5:b56a4592aac0 | 1007 | } | 
| wavenumber | 5:b56a4592aac0 | 1008 | |
| wavenumber | 5:b56a4592aac0 | 1009 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); | 
| emh203 | 0:7798270c1f52 | 1010 | } | 
| emh203 | 0:7798270c1f52 | 1011 | else | 
| emh203 | 0:7798270c1f52 | 1012 | { | 
| emh203 | 0:7798270c1f52 | 1013 | for(Channel = 0; Channel<12;Channel++) | 
| emh203 | 0:7798270c1f52 | 1014 | { | 
| emh203 | 0:7798270c1f52 | 1015 | Temp = ReadThermocouple(Channel); | 
| wavenumber | 5:b56a4592aac0 | 1016 | |
| wavenumber | 5:b56a4592aac0 | 1017 | if(ReadThermocouple_FAULT() & (1<<Channel)) | 
| wavenumber | 5:b56a4592aac0 | 1018 | { | 
| wavenumber | 5:b56a4592aac0 | 1019 | Status = 1; | 
| wavenumber | 5:b56a4592aac0 | 1020 | } | 
| wavenumber | 5:b56a4592aac0 | 1021 | else | 
| wavenumber | 5:b56a4592aac0 | 1022 | { | 
| wavenumber | 5:b56a4592aac0 | 1023 | Status = 0; | 
| wavenumber | 5:b56a4592aac0 | 1024 | } | 
| wavenumber | 5:b56a4592aac0 | 1025 | |
| wavenumber | 5:b56a4592aac0 | 1026 | PC.printf("TEMP:%d:%.2f:%d\r\n",Channel,Temp,Status); | 
| emh203 | 0:7798270c1f52 | 1027 | } | 
| emh203 | 0:7798270c1f52 | 1028 | } | 
| emh203 | 0:7798270c1f52 | 1029 | } | 
| emh203 | 0:7798270c1f52 | 1030 | |
| emh203 | 0:7798270c1f52 | 1031 | void TerminalCmd_Buzz(char *arg) | 
| emh203 | 0:7798270c1f52 | 1032 | { | 
| emh203 | 0:7798270c1f52 | 1033 | |
| emh203 | 0:7798270c1f52 | 1034 | float T = -1.0; | 
| emh203 | 0:7798270c1f52 | 1035 | |
| emh203 | 0:7798270c1f52 | 1036 | if(sscanf(arg,"%f",&T) == 1) | 
| emh203 | 0:7798270c1f52 | 1037 | { | 
| emh203 | 0:7798270c1f52 | 1038 | if(T>=0.0 && T<=5.0) | 
| emh203 | 0:7798270c1f52 | 1039 | { | 
| emh203 | 0:7798270c1f52 | 1040 | Buzz(T); | 
| emh203 | 0:7798270c1f52 | 1041 | } | 
| emh203 | 0:7798270c1f52 | 1042 | else | 
| emh203 | 0:7798270c1f52 | 1043 | { | 
| emh203 | 0:7798270c1f52 | 1044 | PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T); | 
| emh203 | 0:7798270c1f52 | 1045 | } | 
| emh203 | 0:7798270c1f52 | 1046 | } | 
| emh203 | 0:7798270c1f52 | 1047 | else | 
| emh203 | 0:7798270c1f52 | 1048 | { | 
| emh203 | 0:7798270c1f52 | 1049 | PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg); | 
| emh203 | 0:7798270c1f52 | 1050 | } | 
| emh203 | 0:7798270c1f52 | 1051 | |
| emh203 | 0:7798270c1f52 | 1052 | } | 
| emh203 | 0:7798270c1f52 | 1053 | |
| emh203 | 0:7798270c1f52 | 1054 | |
| emh203 | 0:7798270c1f52 | 1055 | |
| emh203 | 0:7798270c1f52 | 1056 | |
| emh203 | 0:7798270c1f52 | 1057 | //***************************************************************** | 
| emh203 | 0:7798270c1f52 | 1058 | //Plumbing..... | 
| emh203 | 0:7798270c1f52 | 1059 | //***************************************************************** | 
| emh203 | 0:7798270c1f52 | 1060 | |
| emh203 | 0:7798270c1f52 | 1061 | #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord)) | 
| emh203 | 0:7798270c1f52 | 1062 | |
| emh203 | 0:7798270c1f52 | 1063 | char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS]; | 
| emh203 | 0:7798270c1f52 | 1064 | uint8_t TerminalPos; | 
| emh203 | 0:7798270c1f52 | 1065 | char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1]; | 
| emh203 | 0:7798270c1f52 | 1066 | char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS]; | 
| emh203 | 0:7798270c1f52 | 1067 | uint8_t NextCharIn; | 
| emh203 | 0:7798270c1f52 | 1068 | uint8_t CmdFound; | 
| emh203 | 0:7798270c1f52 | 1069 | |
| emh203 | 0:7798270c1f52 | 1070 | void TerminalBootMsg() | 
| emh203 | 0:7798270c1f52 | 1071 | { | 
| emh203 | 0:7798270c1f52 | 1072 | |
| emh203 | 0:7798270c1f52 | 1073 | PC.printf("\r\n\r\n"); | 
| emh203 | 0:7798270c1f52 | 1074 | PC.printf("***********************************\r\n"); | 
| emh203 | 0:7798270c1f52 | 1075 | PC.printf("CHEM Control Box \r\n"); | 
| emh203 | 0:7798270c1f52 | 1076 | PC.printf("API Version %s \r\n",API_VERSION); | 
| emh203 | 0:7798270c1f52 | 1077 | PC.printf("Copyright (C) <2013> Eli Hughes\r\n"); | 
| emh203 | 0:7798270c1f52 | 1078 | PC.printf("Wavenumber LLC\r\n"); | 
| emh203 | 0:7798270c1f52 | 1079 | PC.printf("***********************************\r\n\r\n>"); | 
| emh203 | 0:7798270c1f52 | 1080 | |
| emh203 | 0:7798270c1f52 | 1081 | } | 
| emh203 | 0:7798270c1f52 | 1082 | |
| emh203 | 0:7798270c1f52 | 1083 | void InitTerminal() | 
| emh203 | 0:7798270c1f52 | 1084 | { | 
| emh203 | 0:7798270c1f52 | 1085 | |
| emh203 | 0:7798270c1f52 | 1086 | PC.baud(115200); | 
| emh203 | 0:7798270c1f52 | 1087 | TerminalPos = 0; | 
| emh203 | 0:7798270c1f52 | 1088 | CmdFound = 0; | 
| emh203 | 0:7798270c1f52 | 1089 | TerminalBootMsg(); | 
| emh203 | 0:7798270c1f52 | 1090 | } | 
| emh203 | 0:7798270c1f52 | 1091 | |
| emh203 | 0:7798270c1f52 | 1092 | void TerminalCmd_Help(char *arg) | 
| emh203 | 0:7798270c1f52 | 1093 | { | 
| emh203 | 0:7798270c1f52 | 1094 | uint8_t i; | 
| emh203 | 0:7798270c1f52 | 1095 | |
| emh203 | 0:7798270c1f52 | 1096 | PC.printf("\r\n\r\nCommand List:\r\n"); | 
| emh203 | 0:7798270c1f52 | 1097 | PC.printf("----------------------\r\n"); | 
| emh203 | 0:7798270c1f52 | 1098 | |
| emh203 | 0:7798270c1f52 | 1099 | for(i=0;i<NUM_TERMINAL_COMMANDS;i++) | 
| emh203 | 0:7798270c1f52 | 1100 | { | 
| emh203 | 0:7798270c1f52 | 1101 | PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString); | 
| emh203 | 0:7798270c1f52 | 1102 | } | 
| emh203 | 0:7798270c1f52 | 1103 | |
| emh203 | 0:7798270c1f52 | 1104 | PC.printf("\r\n\r\n"); | 
| emh203 | 0:7798270c1f52 | 1105 | } | 
| emh203 | 0:7798270c1f52 | 1106 | |
| emh203 | 0:7798270c1f52 | 1107 | void TerminalCmd_Reboot(char *arg) | 
| emh203 | 0:7798270c1f52 | 1108 | { | 
| emh203 | 0:7798270c1f52 | 1109 | TerminalBootMsg(); | 
| emh203 | 0:7798270c1f52 | 1110 | } | 
| emh203 | 0:7798270c1f52 | 1111 | |
| emh203 | 0:7798270c1f52 | 1112 | void ProcessTerminal() | 
| emh203 | 0:7798270c1f52 | 1113 | { | 
| emh203 | 0:7798270c1f52 | 1114 | uint8_t i,j; | 
| emh203 | 0:7798270c1f52 | 1115 | uint8_t ArgsFound; | 
| emh203 | 0:7798270c1f52 | 1116 | |
| emh203 | 0:7798270c1f52 | 1117 | if(PC.readable()) | 
| emh203 | 0:7798270c1f52 | 1118 | { | 
| emh203 | 0:7798270c1f52 | 1119 | NextCharIn = PC.getc(); | 
| emh203 | 0:7798270c1f52 | 1120 | |
| emh203 | 0:7798270c1f52 | 1121 | switch(NextCharIn) | 
| emh203 | 0:7798270c1f52 | 1122 | { | 
| emh203 | 0:7798270c1f52 | 1123 | case '\r': | 
| emh203 | 0:7798270c1f52 | 1124 | |
| emh203 | 0:7798270c1f52 | 1125 | TerminalLineBuf[TerminalPos++] = 0x0; | 
| wavenumber | 2:73a028278c5c | 1126 | |
| wavenumber | 2:73a028278c5c | 1127 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1128 | { | 
| wavenumber | 2:73a028278c5c | 1129 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1130 | } | 
| wavenumber | 2:73a028278c5c | 1131 | |
| emh203 | 0:7798270c1f52 | 1132 | if(TerminalPos > 1) | 
| emh203 | 0:7798270c1f52 | 1133 | { | 
| emh203 | 0:7798270c1f52 | 1134 | //find the command | 
| emh203 | 0:7798270c1f52 | 1135 | i=0; | 
| emh203 | 0:7798270c1f52 | 1136 | while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f) | 
| emh203 | 0:7798270c1f52 | 1137 | { | 
| emh203 | 0:7798270c1f52 | 1138 | TerminalCmdBuf[i] = TerminalLineBuf[i]; | 
| emh203 | 0:7798270c1f52 | 1139 | i++; | 
| emh203 | 0:7798270c1f52 | 1140 | |
| emh203 | 0:7798270c1f52 | 1141 | if(i==MAX_TERMINAL_CMD_CHARS) | 
| emh203 | 0:7798270c1f52 | 1142 | { | 
| emh203 | 0:7798270c1f52 | 1143 | break; | 
| emh203 | 0:7798270c1f52 | 1144 | } | 
| emh203 | 0:7798270c1f52 | 1145 | } | 
| emh203 | 0:7798270c1f52 | 1146 | |
| emh203 | 0:7798270c1f52 | 1147 | TerminalCmdBuf[i] = 0; | 
| emh203 | 0:7798270c1f52 | 1148 | TerminalCmdBuf[i+1] = 0; | 
| emh203 | 0:7798270c1f52 | 1149 | |
| emh203 | 0:7798270c1f52 | 1150 | |
| emh203 | 0:7798270c1f52 | 1151 | ArgsFound = TRUE; | 
| emh203 | 0:7798270c1f52 | 1152 | memset(TerminalArgs,0x00,sizeof(TerminalArgs)); | 
| emh203 | 0:7798270c1f52 | 1153 | //scan for num terminator or next non whitespace | 
| emh203 | 0:7798270c1f52 | 1154 | while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS)) | 
| emh203 | 0:7798270c1f52 | 1155 | { | 
| emh203 | 0:7798270c1f52 | 1156 | if(TerminalLineBuf[i] == 0x00) | 
| emh203 | 0:7798270c1f52 | 1157 | { | 
| emh203 | 0:7798270c1f52 | 1158 | |
| emh203 | 0:7798270c1f52 | 1159 | //if we find a NULL terminator before a non whitespace character they flag for no arguments | 
| emh203 | 0:7798270c1f52 | 1160 | ArgsFound = FALSE; | 
| emh203 | 0:7798270c1f52 | 1161 | break; | 
| emh203 | 0:7798270c1f52 | 1162 | } | 
| emh203 | 0:7798270c1f52 | 1163 | i++; | 
| emh203 | 0:7798270c1f52 | 1164 | } | 
| emh203 | 0:7798270c1f52 | 1165 | |
| emh203 | 0:7798270c1f52 | 1166 | if(ArgsFound == TRUE) | 
| emh203 | 0:7798270c1f52 | 1167 | { | 
| emh203 | 0:7798270c1f52 | 1168 | strcpy(TerminalArgs,&TerminalLineBuf[i]); | 
| emh203 | 0:7798270c1f52 | 1169 | |
| emh203 | 0:7798270c1f52 | 1170 | //trim trailing whitespace | 
| emh203 | 0:7798270c1f52 | 1171 | i = sizeof(TerminalArgs)-1; | 
| emh203 | 0:7798270c1f52 | 1172 | |
| emh203 | 0:7798270c1f52 | 1173 | while((TerminalArgs[i]<0x21) && (i>0)) | 
| emh203 | 0:7798270c1f52 | 1174 | { | 
| emh203 | 0:7798270c1f52 | 1175 | TerminalArgs[i]= 0x00; | 
| emh203 | 0:7798270c1f52 | 1176 | i--; | 
| emh203 | 0:7798270c1f52 | 1177 | } | 
| emh203 | 0:7798270c1f52 | 1178 | } | 
| emh203 | 0:7798270c1f52 | 1179 | |
| emh203 | 0:7798270c1f52 | 1180 | CmdFound = FALSE; | 
| emh203 | 0:7798270c1f52 | 1181 | for(j=0;j<NUM_TERMINAL_COMMANDS;j++) | 
| emh203 | 0:7798270c1f52 | 1182 | { | 
| emh203 | 0:7798270c1f52 | 1183 | if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0) | 
| emh203 | 0:7798270c1f52 | 1184 | { | 
| emh203 | 0:7798270c1f52 | 1185 | PC.printf("\r\n"); | 
| emh203 | 0:7798270c1f52 | 1186 | if(MyTerminalCallbackRecords[j].Callback != NULL) | 
| emh203 | 0:7798270c1f52 | 1187 | MyTerminalCallbackRecords[j].Callback(TerminalArgs); | 
| emh203 | 0:7798270c1f52 | 1188 | |
| emh203 | 0:7798270c1f52 | 1189 | CmdFound = TRUE; | 
| emh203 | 0:7798270c1f52 | 1190 | break; | 
| emh203 | 0:7798270c1f52 | 1191 | } | 
| emh203 | 0:7798270c1f52 | 1192 | } | 
| emh203 | 0:7798270c1f52 | 1193 | if(CmdFound == FALSE) | 
| emh203 | 0:7798270c1f52 | 1194 | { | 
| emh203 | 0:7798270c1f52 | 1195 | PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf); | 
| emh203 | 0:7798270c1f52 | 1196 | TerminalCmd_Help("no arg"); | 
| emh203 | 0:7798270c1f52 | 1197 | |
| emh203 | 0:7798270c1f52 | 1198 | } | 
| emh203 | 0:7798270c1f52 | 1199 | } | 
| wavenumber | 2:73a028278c5c | 1200 | PC.printf("\r\n"); | 
| emh203 | 0:7798270c1f52 | 1201 | TerminalPos = 0; | 
| emh203 | 0:7798270c1f52 | 1202 | |
| emh203 | 0:7798270c1f52 | 1203 | break; | 
| emh203 | 0:7798270c1f52 | 1204 | |
| emh203 | 0:7798270c1f52 | 1205 | case '\b': | 
| emh203 | 0:7798270c1f52 | 1206 | if(TerminalPos > 0) | 
| emh203 | 0:7798270c1f52 | 1207 | { | 
| wavenumber | 2:73a028278c5c | 1208 | TerminalPos--; | 
| wavenumber | 2:73a028278c5c | 1209 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1210 | { | 
| wavenumber | 2:73a028278c5c | 1211 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1212 | } | 
| emh203 | 0:7798270c1f52 | 1213 | } | 
| emh203 | 0:7798270c1f52 | 1214 | break; | 
| emh203 | 0:7798270c1f52 | 1215 | |
| emh203 | 0:7798270c1f52 | 1216 | default: | 
| emh203 | 0:7798270c1f52 | 1217 | |
| emh203 | 0:7798270c1f52 | 1218 | if(TerminalPos == 0 && NextCharIn == 0x020) | 
| emh203 | 0:7798270c1f52 | 1219 | { | 
| emh203 | 0:7798270c1f52 | 1220 | //Do nothing if space bar is pressed at beginning of line | 
| emh203 | 0:7798270c1f52 | 1221 | } | 
| emh203 | 0:7798270c1f52 | 1222 | else if(NextCharIn >= 0x20 && NextCharIn<0x7F) | 
| emh203 | 0:7798270c1f52 | 1223 | { | 
| emh203 | 0:7798270c1f52 | 1224 | |
| emh203 | 0:7798270c1f52 | 1225 | if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1) | 
| emh203 | 0:7798270c1f52 | 1226 | { | 
| emh203 | 0:7798270c1f52 | 1227 | TerminalLineBuf[TerminalPos++] = NextCharIn; | 
| wavenumber | 2:73a028278c5c | 1228 | if(TerminalEcho) | 
| wavenumber | 2:73a028278c5c | 1229 | { | 
| wavenumber | 2:73a028278c5c | 1230 | PC.putc(NextCharIn); | 
| wavenumber | 2:73a028278c5c | 1231 | } | 
| emh203 | 0:7798270c1f52 | 1232 | } | 
| emh203 | 0:7798270c1f52 | 1233 | } | 
| emh203 | 0:7798270c1f52 | 1234 | |
| emh203 | 0:7798270c1f52 | 1235 | break; | 
| emh203 | 0:7798270c1f52 | 1236 | |
| emh203 | 0:7798270c1f52 | 1237 | } | 
| emh203 | 0:7798270c1f52 | 1238 | } | 
| emh203 | 0:7798270c1f52 | 1239 | |
| emh203 | 0:7798270c1f52 | 1240 | } | 
| emh203 | 0:7798270c1f52 | 1241 | |
| emh203 | 0:7798270c1f52 | 1242 | |
| emh203 | 0:7798270c1f52 | 1243 | |
| emh203 | 0:7798270c1f52 | 1244 | 
