Example project for the Rioux Chem control box
Rioux Chem Control Box
This is the example project for the Rioux Chem Control Box. I have posted some youtube videos to guide you through the hardware and software:
Rioux Chem Control Box - Hardware
http://www.youtube.com/watch?v=MoZ92GRYa4s
Rioux Chem Control Box - Software - Part I
http://www.youtube.com/watch?v=_MwaTLL4dyA==
Rioux Chem Control Box - Software - Part II
http://www.youtube.com/watch?v=j_P89izfgoQ
DRIVERS/CHEM_BOX_COMMON.cpp@2:73a028278c5c, 2020-08-31 (annotated)
- Committer:
- wavenumber
- Date:
- Mon Aug 31 13:00:37 2020 +0000
- Revision:
- 2:73a028278c5c
- Parent:
- 1:d64ac853223c
- Child:
- 3:cb48919cd5e8
Fixed issue with Thermocouple bit masking. Added Echo off command
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 | |
emh203 | 0:7798270c1f52 | 23 | DigitalOut MFC_POWER_CONTROL(p22); |
emh203 | 0:7798270c1f52 | 24 | |
emh203 | 0:7798270c1f52 | 25 | PwmOut FAN_CONTROL(p21); |
emh203 | 0:7798270c1f52 | 26 | |
emh203 | 0:7798270c1f52 | 27 | SPI SPI1(p5,p6,p7); |
emh203 | 0:7798270c1f52 | 28 | |
emh203 | 0:7798270c1f52 | 29 | DigitalOut MCU_SR_LOAD(p8); |
emh203 | 0:7798270c1f52 | 30 | |
emh203 | 0:7798270c1f52 | 31 | SPI SPI0(p11,p12,p13); |
emh203 | 0:7798270c1f52 | 32 | |
emh203 | 0:7798270c1f52 | 33 | DigitalOut SmartSwitch_SS(p14); |
emh203 | 0:7798270c1f52 | 34 | |
emh203 | 0:7798270c1f52 | 35 | BusOut TEMP_SENSE_ADDRESS(p15,p16,p17,p18); |
emh203 | 0:7798270c1f52 | 36 | |
emh203 | 0:7798270c1f52 | 37 | DigitalOut TEMP_SENSE_CS(p19); |
emh203 | 0:7798270c1f52 | 38 | |
emh203 | 0:7798270c1f52 | 39 | DigitalIn LCD_SWITCH(p20); |
emh203 | 0:7798270c1f52 | 40 | |
emh203 | 0:7798270c1f52 | 41 | MODSERIAL RS232_0(p9, p10, 1024, 1024); |
emh203 | 0:7798270c1f52 | 42 | |
emh203 | 0:7798270c1f52 | 43 | MODSERIAL RS232_1(p28, p27, 1024, 1024); |
emh203 | 0:7798270c1f52 | 44 | |
emh203 | 0:7798270c1f52 | 45 | // Make TX buffer 1024bytes and RX buffer use 512bytes. |
emh203 | 0:7798270c1f52 | 46 | MODSERIAL PC(USBTX, USBRX, 1024, 1024); // tx, rx |
emh203 | 0:7798270c1f52 | 47 | |
emh203 | 0:7798270c1f52 | 48 | //Local Variables |
emh203 | 0:7798270c1f52 | 49 | |
emh203 | 0:7798270c1f52 | 50 | |
wavenumber | 2:73a028278c5c | 51 | static uint8_t TerminalEcho = 1; |
wavenumber | 2:73a028278c5c | 52 | |
emh203 | 0:7798270c1f52 | 53 | static uint8_t HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 54 | |
emh203 | 0:7798270c1f52 | 55 | static uint16_t SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 56 | |
emh203 | 0:7798270c1f52 | 57 | static uint8_t DigitalOutputBits = 0; |
emh203 | 0:7798270c1f52 | 58 | |
emh203 | 0:7798270c1f52 | 59 | Timeout BuzzTimeout; |
emh203 | 0:7798270c1f52 | 60 | |
emh203 | 0:7798270c1f52 | 61 | static uint16_t Thermocouple_FAULT = 0; |
emh203 | 0:7798270c1f52 | 62 | |
emh203 | 0:7798270c1f52 | 63 | static uint16_t Thermocouple_SCV = 0; |
emh203 | 0:7798270c1f52 | 64 | |
emh203 | 0:7798270c1f52 | 65 | static uint16_t Thermocouple_SCG = 0; |
emh203 | 0:7798270c1f52 | 66 | |
emh203 | 0:7798270c1f52 | 67 | static uint16_t Thermocouple_OC= 0; |
emh203 | 0:7798270c1f52 | 68 | |
emh203 | 0:7798270c1f52 | 69 | static float Temperature[12]; |
emh203 | 0:7798270c1f52 | 70 | |
emh203 | 0:7798270c1f52 | 71 | static float InternalTemperature[12]; |
emh203 | 0:7798270c1f52 | 72 | |
emh203 | 0:7798270c1f52 | 73 | static uint16_t ReadRawADC(uint8_t Channel); |
emh203 | 0:7798270c1f52 | 74 | |
emh203 | 0:7798270c1f52 | 75 | |
emh203 | 0:7798270c1f52 | 76 | //Local Functions |
emh203 | 0:7798270c1f52 | 77 | |
emh203 | 0:7798270c1f52 | 78 | void InitTerminal(); |
emh203 | 0:7798270c1f52 | 79 | |
emh203 | 0:7798270c1f52 | 80 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data); |
emh203 | 0:7798270c1f52 | 81 | |
emh203 | 0:7798270c1f52 | 82 | |
emh203 | 0:7798270c1f52 | 83 | |
emh203 | 0:7798270c1f52 | 84 | void InitChemBox() |
emh203 | 0:7798270c1f52 | 85 | { |
emh203 | 0:7798270c1f52 | 86 | |
emh203 | 0:7798270c1f52 | 87 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 88 | |
emh203 | 0:7798270c1f52 | 89 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 90 | |
emh203 | 0:7798270c1f52 | 91 | BUZZER_CONTROL.period_ms(1.0); |
emh203 | 0:7798270c1f52 | 92 | |
emh203 | 0:7798270c1f52 | 93 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 94 | |
emh203 | 0:7798270c1f52 | 95 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 96 | |
emh203 | 0:7798270c1f52 | 97 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 98 | |
emh203 | 0:7798270c1f52 | 99 | MFC_POWER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 100 | |
emh203 | 0:7798270c1f52 | 101 | FAN_CONTROL.period_us(1000); |
emh203 | 0:7798270c1f52 | 102 | |
emh203 | 0:7798270c1f52 | 103 | FAN_CONTROL.write(0); |
emh203 | 0:7798270c1f52 | 104 | |
emh203 | 0:7798270c1f52 | 105 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 106 | |
emh203 | 0:7798270c1f52 | 107 | SPI1.frequency(4000000); |
emh203 | 0:7798270c1f52 | 108 | |
emh203 | 0:7798270c1f52 | 109 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 110 | |
emh203 | 0:7798270c1f52 | 111 | SPI0.format(8,0); |
emh203 | 0:7798270c1f52 | 112 | |
emh203 | 0:7798270c1f52 | 113 | SPI0.frequency(4000000); |
emh203 | 0:7798270c1f52 | 114 | |
emh203 | 0:7798270c1f52 | 115 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 116 | |
emh203 | 0:7798270c1f52 | 117 | TEMP_SENSE_ADDRESS = 0; |
emh203 | 0:7798270c1f52 | 118 | |
emh203 | 0:7798270c1f52 | 119 | TEMP_SENSE_CS = 1; |
emh203 | 0:7798270c1f52 | 120 | |
emh203 | 0:7798270c1f52 | 121 | HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 122 | |
emh203 | 0:7798270c1f52 | 123 | SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 124 | |
emh203 | 0:7798270c1f52 | 125 | DigitalOutputBits = 0; |
emh203 | 0:7798270c1f52 | 126 | |
emh203 | 0:7798270c1f52 | 127 | Thermocouple_FAULT = 0; |
emh203 | 0:7798270c1f52 | 128 | |
emh203 | 0:7798270c1f52 | 129 | Thermocouple_SCV = 0; |
emh203 | 0:7798270c1f52 | 130 | |
emh203 | 0:7798270c1f52 | 131 | Thermocouple_SCG = 0; |
emh203 | 0:7798270c1f52 | 132 | |
emh203 | 0:7798270c1f52 | 133 | Thermocouple_OC= 0; |
emh203 | 0:7798270c1f52 | 134 | |
emh203 | 0:7798270c1f52 | 135 | InitTerminal(); |
emh203 | 0:7798270c1f52 | 136 | |
emh203 | 0:7798270c1f52 | 137 | GFX_Init(); |
emh203 | 0:7798270c1f52 | 138 | } |
emh203 | 0:7798270c1f52 | 139 | |
emh203 | 0:7798270c1f52 | 140 | |
emh203 | 0:7798270c1f52 | 141 | void SetFanSpeed(uint8_t S) |
emh203 | 0:7798270c1f52 | 142 | { |
emh203 | 0:7798270c1f52 | 143 | if(S>100) |
emh203 | 0:7798270c1f52 | 144 | S = 100; |
emh203 | 0:7798270c1f52 | 145 | |
emh203 | 0:7798270c1f52 | 146 | FAN_CONTROL = (float)(S)/100.0; |
emh203 | 0:7798270c1f52 | 147 | |
emh203 | 0:7798270c1f52 | 148 | } |
emh203 | 0:7798270c1f52 | 149 | |
emh203 | 0:7798270c1f52 | 150 | void EnableFan() |
emh203 | 0:7798270c1f52 | 151 | { |
emh203 | 0:7798270c1f52 | 152 | SetFanSpeed(100); |
emh203 | 0:7798270c1f52 | 153 | } |
emh203 | 0:7798270c1f52 | 154 | |
emh203 | 0:7798270c1f52 | 155 | void DisableFan() |
emh203 | 0:7798270c1f52 | 156 | { |
emh203 | 0:7798270c1f52 | 157 | SetFanSpeed(0); |
emh203 | 0:7798270c1f52 | 158 | } |
emh203 | 0:7798270c1f52 | 159 | |
emh203 | 0:7798270c1f52 | 160 | void BuzzOff() |
emh203 | 0:7798270c1f52 | 161 | { |
emh203 | 0:7798270c1f52 | 162 | BUZZER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 163 | } |
emh203 | 0:7798270c1f52 | 164 | |
emh203 | 0:7798270c1f52 | 165 | void Buzz(float Time) |
emh203 | 0:7798270c1f52 | 166 | { |
emh203 | 0:7798270c1f52 | 167 | BUZZER_CONTROL = 0.5; |
emh203 | 0:7798270c1f52 | 168 | BuzzTimeout.attach(&BuzzOff, Time); |
emh203 | 0:7798270c1f52 | 169 | |
emh203 | 0:7798270c1f52 | 170 | } |
emh203 | 0:7798270c1f52 | 171 | |
emh203 | 0:7798270c1f52 | 172 | |
emh203 | 0:7798270c1f52 | 173 | void EnableHeater(uint8_t RelayIndex) |
emh203 | 0:7798270c1f52 | 174 | { |
emh203 | 0:7798270c1f52 | 175 | HeaterBits |= (1<<RelayIndex); |
emh203 | 0:7798270c1f52 | 176 | } |
emh203 | 0:7798270c1f52 | 177 | |
emh203 | 0:7798270c1f52 | 178 | void DisableHeater(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 EnableSolenoidValve(uint8_t SolenoidIndex) |
emh203 | 0:7798270c1f52 | 184 | { |
emh203 | 0:7798270c1f52 | 185 | SolenoidBits |= (1<<SolenoidIndex); |
emh203 | 0:7798270c1f52 | 186 | } |
emh203 | 0:7798270c1f52 | 187 | |
emh203 | 0:7798270c1f52 | 188 | void DisableSolenoidValue(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 DisableAllHeatersAndSolenoids() |
emh203 | 0:7798270c1f52 | 194 | { |
emh203 | 0:7798270c1f52 | 195 | |
emh203 | 0:7798270c1f52 | 196 | SolenoidBits = 0; |
emh203 | 0:7798270c1f52 | 197 | HeaterBits = 0; |
emh203 | 0:7798270c1f52 | 198 | |
emh203 | 0:7798270c1f52 | 199 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 200 | |
emh203 | 0:7798270c1f52 | 201 | MCU_SR_CLEAR = 0; |
emh203 | 0:7798270c1f52 | 202 | |
emh203 | 0:7798270c1f52 | 203 | MCU_SR_CLEAR = 1; |
emh203 | 0:7798270c1f52 | 204 | |
emh203 | 0:7798270c1f52 | 205 | MCU_SR_LOAD = 1; |
emh203 | 0:7798270c1f52 | 206 | |
emh203 | 0:7798270c1f52 | 207 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 208 | } |
emh203 | 0:7798270c1f52 | 209 | |
emh203 | 0:7798270c1f52 | 210 | void EnableMiscDigitalOutput(uint8_t DigitalOutIndex) |
emh203 | 0:7798270c1f52 | 211 | { |
emh203 | 0:7798270c1f52 | 212 | DigitalOutputBits |= (1<<DigitalOutIndex); |
emh203 | 0:7798270c1f52 | 213 | } |
emh203 | 0:7798270c1f52 | 214 | |
emh203 | 0:7798270c1f52 | 215 | void DisableMiscDigitalOutput(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 FlushDigitalIO() |
emh203 | 0:7798270c1f52 | 221 | { |
emh203 | 0:7798270c1f52 | 222 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 223 | |
emh203 | 0:7798270c1f52 | 224 | SPI1.write((SolenoidBits >> 8) & 0xFF); |
emh203 | 0:7798270c1f52 | 225 | SPI1.write(SolenoidBits & 0xFF); |
emh203 | 0:7798270c1f52 | 226 | SPI1.write(HeaterBits & 0xFF); |
emh203 | 0:7798270c1f52 | 227 | SPI1.write(DigitalOutputBits & 0xFF); |
emh203 | 0:7798270c1f52 | 228 | |
emh203 | 0:7798270c1f52 | 229 | MCU_SR_LOAD = 1; |
emh203 | 0:7798270c1f52 | 230 | MCU_SR_LOAD = 0; |
emh203 | 0:7798270c1f52 | 231 | } |
emh203 | 0:7798270c1f52 | 232 | |
wavenumber | 2:73a028278c5c | 233 | //Make sure to call ReadThermocouple before you call this so internal variables are updated |
emh203 | 0:7798270c1f52 | 234 | uint16_t ReadThermocouple_OC() |
emh203 | 0:7798270c1f52 | 235 | { |
emh203 | 0:7798270c1f52 | 236 | return Thermocouple_OC; |
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_SCG() |
emh203 | 0:7798270c1f52 | 240 | { |
emh203 | 0:7798270c1f52 | 241 | return Thermocouple_SCG; |
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_SCV() |
emh203 | 0:7798270c1f52 | 245 | { |
emh203 | 0:7798270c1f52 | 246 | return Thermocouple_SCV; |
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_FAULT() |
emh203 | 0:7798270c1f52 | 250 | { |
emh203 | 0:7798270c1f52 | 251 | return Thermocouple_FAULT; |
emh203 | 0:7798270c1f52 | 252 | } |
emh203 | 0:7798270c1f52 | 253 | |
emh203 | 0:7798270c1f52 | 254 | |
emh203 | 0:7798270c1f52 | 255 | float ReadInternalTemperature(uint8_t ThermocoupleIndex) |
emh203 | 0:7798270c1f52 | 256 | { |
emh203 | 0:7798270c1f52 | 257 | ReadThermocouple(ThermocoupleIndex); //this will yank out the Data |
emh203 | 0:7798270c1f52 | 258 | return InternalTemperature[ThermocoupleIndex]; |
emh203 | 0:7798270c1f52 | 259 | } |
emh203 | 0:7798270c1f52 | 260 | |
emh203 | 0:7798270c1f52 | 261 | |
emh203 | 0:7798270c1f52 | 262 | |
emh203 | 0:7798270c1f52 | 263 | float ReadThermocouple(uint8_t ThermocoupleIndex) |
emh203 | 0:7798270c1f52 | 264 | { |
emh203 | 0:7798270c1f52 | 265 | uint8_t i=0; |
emh203 | 0:7798270c1f52 | 266 | uint32_t ThermocoupleData = 0; |
emh203 | 0:7798270c1f52 | 267 | uint8_t TempData[4]; |
emh203 | 0:7798270c1f52 | 268 | |
emh203 | 0:7798270c1f52 | 269 | int16_t InternalTemp = 0; |
emh203 | 0:7798270c1f52 | 270 | int16_t ThermocoupleTemp = 0; |
emh203 | 0:7798270c1f52 | 271 | |
emh203 | 0:7798270c1f52 | 272 | //reset SPi format |
emh203 | 0:7798270c1f52 | 273 | SPI1.format(8,0); |
emh203 | 0:7798270c1f52 | 274 | |
emh203 | 0:7798270c1f52 | 275 | TEMP_SENSE_ADDRESS = ThermocoupleIndex & 0x1f; |
emh203 | 0:7798270c1f52 | 276 | |
emh203 | 0:7798270c1f52 | 277 | TEMP_SENSE_CS = 0; |
emh203 | 0:7798270c1f52 | 278 | |
emh203 | 0:7798270c1f52 | 279 | for(i=0;i<4;i++) |
emh203 | 0:7798270c1f52 | 280 | TempData[i] = SPI1.write(0); |
emh203 | 0:7798270c1f52 | 281 | |
emh203 | 0:7798270c1f52 | 282 | TEMP_SENSE_CS = 1; |
emh203 | 0:7798270c1f52 | 283 | |
emh203 | 0:7798270c1f52 | 284 | |
emh203 | 0:7798270c1f52 | 285 | ThermocoupleData = (uint32_t)(TempData[3]) | |
emh203 | 0:7798270c1f52 | 286 | (((uint32_t)(TempData[2]))<<8) | |
emh203 | 0:7798270c1f52 | 287 | (((uint32_t)(TempData[1]))<<16) | |
emh203 | 0:7798270c1f52 | 288 | (((uint32_t)(TempData[0]))<<24); |
emh203 | 0:7798270c1f52 | 289 | |
emh203 | 0:7798270c1f52 | 290 | |
emh203 | 0:7798270c1f52 | 291 | if(ThermocoupleData & 0x01) |
emh203 | 0:7798270c1f52 | 292 | Thermocouple_OC |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 293 | else |
emh203 | 0:7798270c1f52 | 294 | Thermocouple_OC &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 295 | |
emh203 | 0:7798270c1f52 | 296 | if(ThermocoupleData & 0x02) |
emh203 | 0:7798270c1f52 | 297 | Thermocouple_SCG |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 298 | else |
emh203 | 0:7798270c1f52 | 299 | Thermocouple_SCG &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 300 | |
emh203 | 0:7798270c1f52 | 301 | if(ThermocoupleData & 0x04) |
emh203 | 0:7798270c1f52 | 302 | Thermocouple_SCV |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 303 | else |
emh203 | 0:7798270c1f52 | 304 | Thermocouple_SCV &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 305 | |
emh203 | 0:7798270c1f52 | 306 | if(ThermocoupleData & (1<<16)) |
emh203 | 0:7798270c1f52 | 307 | Thermocouple_FAULT |= (1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 308 | else |
emh203 | 0:7798270c1f52 | 309 | Thermocouple_FAULT &= ~(1<<ThermocoupleIndex); |
emh203 | 0:7798270c1f52 | 310 | |
emh203 | 0:7798270c1f52 | 311 | if(ThermocoupleData & (1<<15)) |
emh203 | 0:7798270c1f52 | 312 | 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 | 313 | else |
emh203 | 0:7798270c1f52 | 314 | InternalTemp = (int16_t)( ( (ThermocoupleData>>4) & 0xFFF)); |
emh203 | 0:7798270c1f52 | 315 | |
emh203 | 0:7798270c1f52 | 316 | |
emh203 | 0:7798270c1f52 | 317 | if(ThermocoupleData & (0x10000000)) |
emh203 | 0:7798270c1f52 | 318 | 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 | 319 | else |
emh203 | 0:7798270c1f52 | 320 | ThermocoupleTemp = (int16_t)(((ThermocoupleData>>18) & 0x2FFF)); |
emh203 | 0:7798270c1f52 | 321 | |
emh203 | 0:7798270c1f52 | 322 | Temperature[ThermocoupleIndex] = (float)ThermocoupleTemp/4.0; |
emh203 | 0:7798270c1f52 | 323 | |
emh203 | 0:7798270c1f52 | 324 | InternalTemperature[ThermocoupleIndex] = (float)InternalTemp/16.0;; |
emh203 | 0:7798270c1f52 | 325 | |
emh203 | 0:7798270c1f52 | 326 | return Temperature[ThermocoupleIndex]; |
emh203 | 0:7798270c1f52 | 327 | } |
emh203 | 0:7798270c1f52 | 328 | |
emh203 | 0:7798270c1f52 | 329 | float ReadMFC_AnalogInput(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 330 | { |
emh203 | 0:7798270c1f52 | 331 | if(Channel > 7) |
emh203 | 0:7798270c1f52 | 332 | Channel = 7; |
emh203 | 0:7798270c1f52 | 333 | |
emh203 | 0:7798270c1f52 | 334 | return ((float)(ReadRawADC(Channel)) /4095.0) * 5.0; |
emh203 | 0:7798270c1f52 | 335 | |
emh203 | 0:7798270c1f52 | 336 | } |
emh203 | 0:7798270c1f52 | 337 | |
emh203 | 0:7798270c1f52 | 338 | void EnableMFC_Power() |
emh203 | 0:7798270c1f52 | 339 | { |
emh203 | 0:7798270c1f52 | 340 | MFC_POWER_CONTROL = 1; |
emh203 | 0:7798270c1f52 | 341 | } |
emh203 | 0:7798270c1f52 | 342 | |
emh203 | 0:7798270c1f52 | 343 | void DisableMFC_Power() |
emh203 | 0:7798270c1f52 | 344 | { |
emh203 | 0:7798270c1f52 | 345 | MFC_POWER_CONTROL = 0; |
emh203 | 0:7798270c1f52 | 346 | } |
emh203 | 0:7798270c1f52 | 347 | |
emh203 | 0:7798270c1f52 | 348 | |
emh203 | 0:7798270c1f52 | 349 | float ReadMISC_AnalogInput(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 350 | { |
emh203 | 0:7798270c1f52 | 351 | |
emh203 | 0:7798270c1f52 | 352 | if(Channel > 3) |
emh203 | 0:7798270c1f52 | 353 | Channel = 3; |
emh203 | 0:7798270c1f52 | 354 | |
emh203 | 0:7798270c1f52 | 355 | return ((float)(ReadRawADC(Channel + 9)) /4095.0) * 5.0; |
emh203 | 0:7798270c1f52 | 356 | |
emh203 | 0:7798270c1f52 | 357 | } |
emh203 | 0:7798270c1f52 | 358 | |
emh203 | 0:7798270c1f52 | 359 | float Read4to20(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 360 | { |
emh203 | 0:7798270c1f52 | 361 | |
emh203 | 0:7798270c1f52 | 362 | if(Channel > 1) |
emh203 | 0:7798270c1f52 | 363 | Channel = 1; |
emh203 | 0:7798270c1f52 | 364 | |
emh203 | 1:d64ac853223c | 365 | return (((float)(ReadRawADC(Channel + 7)) /4095.0) * 5.0) / 82; |
emh203 | 0:7798270c1f52 | 366 | |
emh203 | 0:7798270c1f52 | 367 | } |
emh203 | 0:7798270c1f52 | 368 | |
emh203 | 0:7798270c1f52 | 369 | |
emh203 | 0:7798270c1f52 | 370 | static uint16_t ReadRawADC(uint8_t Channel) |
emh203 | 0:7798270c1f52 | 371 | { |
emh203 | 0:7798270c1f52 | 372 | uint8_t ControlByte[3]; |
emh203 | 0:7798270c1f52 | 373 | uint8_t ADC_Data[3]; |
emh203 | 0:7798270c1f52 | 374 | uint16_t V; |
emh203 | 0:7798270c1f52 | 375 | |
emh203 | 0:7798270c1f52 | 376 | SPI0.format(8,0); //The ADC requires mode 0,0 |
emh203 | 0:7798270c1f52 | 377 | |
emh203 | 0:7798270c1f52 | 378 | /*See Microchip manual DS21298E-page 21*/ |
emh203 | 0:7798270c1f52 | 379 | |
emh203 | 0:7798270c1f52 | 380 | ControlByte[0] = (((Channel&0x07)>>2) & 0x01) | (3<<1); |
emh203 | 0:7798270c1f52 | 381 | ControlByte[1] = Channel<<6; |
emh203 | 0:7798270c1f52 | 382 | ControlByte[2] = 0; |
emh203 | 0:7798270c1f52 | 383 | |
emh203 | 0:7798270c1f52 | 384 | |
emh203 | 0:7798270c1f52 | 385 | if(Channel<8) |
emh203 | 0:7798270c1f52 | 386 | AIO_ADC1_CS = 0; |
emh203 | 0:7798270c1f52 | 387 | else |
emh203 | 0:7798270c1f52 | 388 | AIO_ADC2_CS = 0; |
emh203 | 0:7798270c1f52 | 389 | |
emh203 | 0:7798270c1f52 | 390 | //unroll the loop |
emh203 | 0:7798270c1f52 | 391 | ADC_Data[0] = SPI0.write(ControlByte[0]); |
emh203 | 0:7798270c1f52 | 392 | ADC_Data[1] = SPI0.write(ControlByte[1]); |
emh203 | 0:7798270c1f52 | 393 | ADC_Data[2] = SPI0.write(ControlByte[2]); |
emh203 | 0:7798270c1f52 | 394 | |
emh203 | 0:7798270c1f52 | 395 | AIO_ADC1_CS = 1; |
emh203 | 0:7798270c1f52 | 396 | AIO_ADC2_CS = 1; |
emh203 | 0:7798270c1f52 | 397 | |
emh203 | 0:7798270c1f52 | 398 | |
emh203 | 0:7798270c1f52 | 399 | V = ((uint16_t)(ADC_Data[1])<<8 | (uint16_t)(ADC_Data[2])) & 0xFFF; |
emh203 | 0:7798270c1f52 | 400 | |
emh203 | 0:7798270c1f52 | 401 | return (V); |
emh203 | 0:7798270c1f52 | 402 | |
emh203 | 0:7798270c1f52 | 403 | } |
emh203 | 0:7798270c1f52 | 404 | |
emh203 | 0:7798270c1f52 | 405 | |
emh203 | 0:7798270c1f52 | 406 | void WriteMFC_AnalogOut(uint8_t Channel,float Value) |
emh203 | 0:7798270c1f52 | 407 | { |
emh203 | 0:7798270c1f52 | 408 | |
emh203 | 0:7798270c1f52 | 409 | if(Channel>7) |
emh203 | 0:7798270c1f52 | 410 | Channel = 7; |
emh203 | 0:7798270c1f52 | 411 | |
emh203 | 0:7798270c1f52 | 412 | if(Value >5.0) |
emh203 | 0:7798270c1f52 | 413 | Value = 5.0; |
emh203 | 0:7798270c1f52 | 414 | |
emh203 | 0:7798270c1f52 | 415 | if(Value<0.0) |
emh203 | 0:7798270c1f52 | 416 | Value = 0.0; |
emh203 | 0:7798270c1f52 | 417 | |
emh203 | 0:7798270c1f52 | 418 | WriteRAW_DAC_Value(Channel,(uint16_t)((Value/5.0) * 4095)); |
emh203 | 0:7798270c1f52 | 419 | |
emh203 | 0:7798270c1f52 | 420 | } |
emh203 | 0:7798270c1f52 | 421 | |
emh203 | 0:7798270c1f52 | 422 | void WriteMISC_AnalogOut(uint8_t Channel,float Value) |
emh203 | 0:7798270c1f52 | 423 | { |
emh203 | 0:7798270c1f52 | 424 | if(Channel>3) |
emh203 | 0:7798270c1f52 | 425 | Channel = 3; |
emh203 | 0:7798270c1f52 | 426 | |
emh203 | 0:7798270c1f52 | 427 | if(Value >5.0) |
emh203 | 0:7798270c1f52 | 428 | Value = 5.0; |
emh203 | 0:7798270c1f52 | 429 | |
emh203 | 0:7798270c1f52 | 430 | if(Value<0.0) |
emh203 | 0:7798270c1f52 | 431 | Value = 0.0; |
emh203 | 0:7798270c1f52 | 432 | |
emh203 | 0:7798270c1f52 | 433 | WriteRAW_DAC_Value(8+Channel,(uint16_t)((Value/5.0)*4095)); |
emh203 | 0:7798270c1f52 | 434 | } |
emh203 | 0:7798270c1f52 | 435 | |
emh203 | 0:7798270c1f52 | 436 | |
emh203 | 0:7798270c1f52 | 437 | void WriteRAW_DAC_Value(uint8_t Channel,uint16_t Data) |
emh203 | 0:7798270c1f52 | 438 | { |
emh203 | 0:7798270c1f52 | 439 | |
emh203 | 0:7798270c1f52 | 440 | uint16_t DataOut; |
emh203 | 0:7798270c1f52 | 441 | |
emh203 | 0:7798270c1f52 | 442 | if(Channel<8) |
emh203 | 0:7798270c1f52 | 443 | AIO_DAC1_CS = 0; |
emh203 | 0:7798270c1f52 | 444 | else |
emh203 | 0:7798270c1f52 | 445 | AIO_DAC2_CS = 0; |
emh203 | 0:7798270c1f52 | 446 | |
emh203 | 0:7798270c1f52 | 447 | SPI0.format(8,1); //The DAC requires mode 0,1 |
emh203 | 0:7798270c1f52 | 448 | |
emh203 | 0:7798270c1f52 | 449 | DataOut = ((uint16_t)(Channel) & 0x7)<<12 | (Data & 0xFFF); |
emh203 | 0:7798270c1f52 | 450 | |
emh203 | 0:7798270c1f52 | 451 | SPI0.write((DataOut>>8)&0xFF); |
emh203 | 0:7798270c1f52 | 452 | SPI0.write(DataOut&0xFF); |
emh203 | 0:7798270c1f52 | 453 | |
emh203 | 0:7798270c1f52 | 454 | AIO_DAC1_CS = 1; |
emh203 | 0:7798270c1f52 | 455 | AIO_DAC2_CS = 1; |
emh203 | 0:7798270c1f52 | 456 | |
emh203 | 0:7798270c1f52 | 457 | } |
emh203 | 0:7798270c1f52 | 458 | |
emh203 | 0:7798270c1f52 | 459 | |
emh203 | 0:7798270c1f52 | 460 | |
emh203 | 0:7798270c1f52 | 461 | |
emh203 | 0:7798270c1f52 | 462 | #define MAX_TERMINAL_LINE_CHARS 128 |
emh203 | 0:7798270c1f52 | 463 | #define MAX_TERMINAL_CMD_CHARS 64 |
emh203 | 0:7798270c1f52 | 464 | |
emh203 | 0:7798270c1f52 | 465 | #ifndef TRUE |
emh203 | 0:7798270c1f52 | 466 | #define TRUE 1 |
emh203 | 0:7798270c1f52 | 467 | #endif |
emh203 | 0:7798270c1f52 | 468 | |
emh203 | 0:7798270c1f52 | 469 | #ifndef FALSE |
emh203 | 0:7798270c1f52 | 470 | #define FALSE 0 |
emh203 | 0:7798270c1f52 | 471 | #endif |
emh203 | 0:7798270c1f52 | 472 | |
emh203 | 0:7798270c1f52 | 473 | typedef void (*TerminalCallback)(char *); |
emh203 | 0:7798270c1f52 | 474 | |
emh203 | 0:7798270c1f52 | 475 | |
emh203 | 0:7798270c1f52 | 476 | typedef struct |
emh203 | 0:7798270c1f52 | 477 | { |
emh203 | 0:7798270c1f52 | 478 | const char *CommandString; |
emh203 | 0:7798270c1f52 | 479 | TerminalCallback Callback; |
emh203 | 0:7798270c1f52 | 480 | const char *HelpString; |
emh203 | 0:7798270c1f52 | 481 | |
emh203 | 0:7798270c1f52 | 482 | } TerminalCallbackRecord; |
emh203 | 0:7798270c1f52 | 483 | |
emh203 | 0:7798270c1f52 | 484 | //Callback function prototypes |
emh203 | 0:7798270c1f52 | 485 | void TerminalCmd_Help(char *arg); |
emh203 | 0:7798270c1f52 | 486 | void TerminalCmd_Stub(char *arg); |
emh203 | 0:7798270c1f52 | 487 | void TerminalCmd_EnableHeater(char *arg); |
emh203 | 0:7798270c1f52 | 488 | void TerminalCmd_DisableHeater(char *arg); |
emh203 | 0:7798270c1f52 | 489 | void TerminalCmd_EnableSolenoidValve(char *arg); |
emh203 | 0:7798270c1f52 | 490 | void TerminalCmd_DisableSolenoidValue(char *arg); |
emh203 | 0:7798270c1f52 | 491 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg); |
emh203 | 0:7798270c1f52 | 492 | void TerminalCmd_EnableMiscDigitalOutput(char *arg); |
emh203 | 0:7798270c1f52 | 493 | void TerminalCmd_DisableMiscDigitalOutput(char *arg); |
emh203 | 0:7798270c1f52 | 494 | void TerminalCmd_FlushDigitalIO(char *arg); |
emh203 | 0:7798270c1f52 | 495 | void TerminalCmd_FanOn(char *arg); |
emh203 | 0:7798270c1f52 | 496 | void TerminalCmd_FanOff(char *arg); |
emh203 | 0:7798270c1f52 | 497 | void TerminalCmd_Buzz(char *arg); |
emh203 | 0:7798270c1f52 | 498 | void TerminalCmd_T(char *arg); |
emh203 | 0:7798270c1f52 | 499 | void TerminalCmd_MFCI(char *arg); |
emh203 | 0:7798270c1f52 | 500 | void TerminalCmd_MFCO(char *arg); |
emh203 | 0:7798270c1f52 | 501 | void TerminalCmd_4TO20(char *arg); |
emh203 | 0:7798270c1f52 | 502 | void TerminalCmd_AIN(char *arg); |
emh203 | 0:7798270c1f52 | 503 | void TerminalCmd_MFCON(char *arg); |
emh203 | 0:7798270c1f52 | 504 | void TerminalCmd_MFCOFF(char *arg); |
emh203 | 0:7798270c1f52 | 505 | void TerminalCmd_AOUT(char *arg); |
emh203 | 0:7798270c1f52 | 506 | void TerminalCmd_Reset(char *arg); |
wavenumber | 2:73a028278c5c | 507 | void TerminalCmd_ECHO_OFF(char *arg); |
emh203 | 0:7798270c1f52 | 508 | |
emh203 | 0:7798270c1f52 | 509 | //Populate this array with the callback functions and their terminal command string |
emh203 | 0:7798270c1f52 | 510 | TerminalCallbackRecord MyTerminalCallbackRecords[] ={ {"reset",TerminalCmd_Reset,"Resets the CHEM box"}, |
emh203 | 0:7798270c1f52 | 511 | |
emh203 | 0:7798270c1f52 | 512 | {"help",TerminalCmd_Help,"Lists available commands"}, |
emh203 | 0:7798270c1f52 | 513 | |
emh203 | 0:7798270c1f52 | 514 | {"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 | 515 | |
emh203 | 0:7798270c1f52 | 516 | {"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 | 517 | |
emh203 | 0:7798270c1f52 | 518 | {"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 | 519 | |
emh203 | 0:7798270c1f52 | 520 | {"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 | 521 | |
emh203 | 0:7798270c1f52 | 522 | {"DAHAS",TerminalCmd_DisableAllHeatersAndSolenoids,"Disables all heaters and solenoids. Command is immediately executed."}, |
emh203 | 0:7798270c1f52 | 523 | |
emh203 | 0:7798270c1f52 | 524 | {"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 | 525 | |
emh203 | 0:7798270c1f52 | 526 | {"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 | 527 | |
emh203 | 0:7798270c1f52 | 528 | {"FDIO",TerminalCmd_FlushDigitalIO,"Updates the all of the digital IO channels"}, |
emh203 | 0:7798270c1f52 | 529 | |
emh203 | 0:7798270c1f52 | 530 | {"FON",TerminalCmd_FanOn,"Turns on the fans"}, |
emh203 | 0:7798270c1f52 | 531 | |
emh203 | 0:7798270c1f52 | 532 | {"FOFF",TerminalCmd_FanOff,"Turns off the fans"}, |
emh203 | 0:7798270c1f52 | 533 | |
emh203 | 0:7798270c1f52 | 534 | {"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 | 535 | |
emh203 | 0:7798270c1f52 | 536 | {"T",TerminalCmd_T,"Read thermocouple channel"}, |
emh203 | 0:7798270c1f52 | 537 | |
emh203 | 0:7798270c1f52 | 538 | {"MFCI",TerminalCmd_MFCI,"Reads in voltage from MFC channel"}, |
emh203 | 0:7798270c1f52 | 539 | |
emh203 | 0:7798270c1f52 | 540 | {"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 | 541 | |
emh203 | 0:7798270c1f52 | 542 | {"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 | 543 | |
emh203 | 0:7798270c1f52 | 544 | {"4TO20",TerminalCmd_4TO20,"Reads a 4 to 20 mA channel"}, |
emh203 | 0:7798270c1f52 | 545 | |
emh203 | 0:7798270c1f52 | 546 | {"AIN",TerminalCmd_AIN,"Reads a general purpose analog in channel"}, |
emh203 | 0:7798270c1f52 | 547 | |
emh203 | 0:7798270c1f52 | 548 | {"MFCON",TerminalCmd_MFCON,"Turns on the MFC power"}, |
emh203 | 0:7798270c1f52 | 549 | |
wavenumber | 2:73a028278c5c | 550 | {"MFCOFF",TerminalCmd_MFCOFF,"Turns off the MFC power"}, |
wavenumber | 2:73a028278c5c | 551 | |
wavenumber | 2:73a028278c5c | 552 | {"ECHO_OFF",TerminalCmd_ECHO_OFF,"Disables echoing of characters"} |
emh203 | 0:7798270c1f52 | 553 | }; |
emh203 | 0:7798270c1f52 | 554 | |
emh203 | 0:7798270c1f52 | 555 | |
emh203 | 0:7798270c1f52 | 556 | extern "C" void mbed_reset(); |
emh203 | 0:7798270c1f52 | 557 | |
emh203 | 0:7798270c1f52 | 558 | void TerminalCmd_Reset(char *arg) |
emh203 | 0:7798270c1f52 | 559 | { |
emh203 | 0:7798270c1f52 | 560 | mbed_reset(); |
emh203 | 0:7798270c1f52 | 561 | } |
emh203 | 0:7798270c1f52 | 562 | |
wavenumber | 2:73a028278c5c | 563 | |
wavenumber | 2:73a028278c5c | 564 | |
emh203 | 0:7798270c1f52 | 565 | void TerminalCmd_Stub(char *arg) |
emh203 | 0:7798270c1f52 | 566 | { |
emh203 | 0:7798270c1f52 | 567 | PC.printf("stub \r\n"); |
emh203 | 0:7798270c1f52 | 568 | } |
emh203 | 0:7798270c1f52 | 569 | |
wavenumber | 2:73a028278c5c | 570 | void TerminalCmd_ECHO_OFF(char *arg) |
wavenumber | 2:73a028278c5c | 571 | { |
wavenumber | 2:73a028278c5c | 572 | TerminalEcho = 0; |
wavenumber | 2:73a028278c5c | 573 | } |
wavenumber | 2:73a028278c5c | 574 | |
emh203 | 0:7798270c1f52 | 575 | void TerminalCmd_MFCI(char *arg) |
emh203 | 0:7798270c1f52 | 576 | { |
emh203 | 0:7798270c1f52 | 577 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 578 | float Data; |
emh203 | 0:7798270c1f52 | 579 | |
emh203 | 0:7798270c1f52 | 580 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 581 | { |
emh203 | 0:7798270c1f52 | 582 | if(Channel>=0 && Channel <=6) |
emh203 | 0:7798270c1f52 | 583 | { |
emh203 | 0:7798270c1f52 | 584 | Data = ReadMFC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 585 | PC.printf("MFCI:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 586 | } |
emh203 | 0:7798270c1f52 | 587 | else |
emh203 | 0:7798270c1f52 | 588 | { |
emh203 | 0:7798270c1f52 | 589 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 6",Channel); |
emh203 | 0:7798270c1f52 | 590 | } |
emh203 | 0:7798270c1f52 | 591 | } |
emh203 | 0:7798270c1f52 | 592 | else |
emh203 | 0:7798270c1f52 | 593 | { |
emh203 | 0:7798270c1f52 | 594 | for(Channel = 0; Channel<=6; Channel++) |
emh203 | 0:7798270c1f52 | 595 | { |
emh203 | 0:7798270c1f52 | 596 | Data = ReadMFC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 597 | PC.printf("MFCI:%d:%.3f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 598 | } |
emh203 | 0:7798270c1f52 | 599 | } |
emh203 | 0:7798270c1f52 | 600 | } |
emh203 | 0:7798270c1f52 | 601 | |
emh203 | 0:7798270c1f52 | 602 | void TerminalCmd_MFCON(char *arg) |
emh203 | 0:7798270c1f52 | 603 | { |
emh203 | 0:7798270c1f52 | 604 | EnableMFC_Power(); |
emh203 | 0:7798270c1f52 | 605 | } |
emh203 | 0:7798270c1f52 | 606 | |
emh203 | 0:7798270c1f52 | 607 | |
emh203 | 0:7798270c1f52 | 608 | void TerminalCmd_MFCOFF(char *arg) |
emh203 | 0:7798270c1f52 | 609 | { |
emh203 | 0:7798270c1f52 | 610 | DisableMFC_Power(); |
emh203 | 0:7798270c1f52 | 611 | } |
emh203 | 0:7798270c1f52 | 612 | |
emh203 | 0:7798270c1f52 | 613 | |
emh203 | 0:7798270c1f52 | 614 | void TerminalCmd_MFCO(char *arg) |
emh203 | 0:7798270c1f52 | 615 | { |
emh203 | 0:7798270c1f52 | 616 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 617 | float Data = 0.0; |
emh203 | 0:7798270c1f52 | 618 | |
emh203 | 0:7798270c1f52 | 619 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) |
emh203 | 0:7798270c1f52 | 620 | { |
emh203 | 0:7798270c1f52 | 621 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 622 | { |
emh203 | 0:7798270c1f52 | 623 | WriteMFC_AnalogOut(Channel,Data); |
emh203 | 0:7798270c1f52 | 624 | } |
emh203 | 0:7798270c1f52 | 625 | else |
emh203 | 0:7798270c1f52 | 626 | { |
emh203 | 0:7798270c1f52 | 627 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); |
emh203 | 0:7798270c1f52 | 628 | } |
emh203 | 0:7798270c1f52 | 629 | } |
emh203 | 0:7798270c1f52 | 630 | else |
emh203 | 0:7798270c1f52 | 631 | { |
emh203 | 0:7798270c1f52 | 632 | 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 | 633 | } |
emh203 | 0:7798270c1f52 | 634 | } |
emh203 | 0:7798270c1f52 | 635 | |
emh203 | 0:7798270c1f52 | 636 | void TerminalCmd_AOUT(char *arg) |
emh203 | 0:7798270c1f52 | 637 | { |
emh203 | 0:7798270c1f52 | 638 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 639 | float Data = 0.0; |
emh203 | 0:7798270c1f52 | 640 | |
emh203 | 0:7798270c1f52 | 641 | if(sscanf(arg,"%d %f",&Channel,&Data) == 2) |
emh203 | 0:7798270c1f52 | 642 | { |
emh203 | 0:7798270c1f52 | 643 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 644 | { |
emh203 | 0:7798270c1f52 | 645 | WriteMISC_AnalogOut(Channel,Data); |
emh203 | 0:7798270c1f52 | 646 | } |
emh203 | 0:7798270c1f52 | 647 | else |
emh203 | 0:7798270c1f52 | 648 | { |
emh203 | 0:7798270c1f52 | 649 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 650 | } |
emh203 | 0:7798270c1f52 | 651 | } |
emh203 | 0:7798270c1f52 | 652 | else |
emh203 | 0:7798270c1f52 | 653 | { |
emh203 | 0:7798270c1f52 | 654 | 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 | 655 | } |
emh203 | 0:7798270c1f52 | 656 | } |
emh203 | 0:7798270c1f52 | 657 | |
emh203 | 0:7798270c1f52 | 658 | void TerminalCmd_4TO20(char *arg) |
emh203 | 0:7798270c1f52 | 659 | { |
emh203 | 0:7798270c1f52 | 660 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 661 | float Data; |
emh203 | 0:7798270c1f52 | 662 | |
emh203 | 0:7798270c1f52 | 663 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 664 | { |
emh203 | 0:7798270c1f52 | 665 | if(Channel>=0 && Channel <=1) |
emh203 | 0:7798270c1f52 | 666 | { |
emh203 | 0:7798270c1f52 | 667 | Data = Read4to20(Channel); |
emh203 | 0:7798270c1f52 | 668 | PC.printf("4TO20:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 669 | } |
emh203 | 0:7798270c1f52 | 670 | else |
emh203 | 0:7798270c1f52 | 671 | { |
emh203 | 0:7798270c1f52 | 672 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 1",Channel); |
emh203 | 0:7798270c1f52 | 673 | } |
emh203 | 0:7798270c1f52 | 674 | } |
emh203 | 0:7798270c1f52 | 675 | else |
emh203 | 0:7798270c1f52 | 676 | { |
emh203 | 0:7798270c1f52 | 677 | |
emh203 | 0:7798270c1f52 | 678 | for(Channel = 0;Channel<=1;Channel++) |
emh203 | 0:7798270c1f52 | 679 | { |
emh203 | 0:7798270c1f52 | 680 | Data = Read4to20(Channel); |
emh203 | 1:d64ac853223c | 681 | PC.printf("4TO20:%d:%.5f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 682 | } |
emh203 | 0:7798270c1f52 | 683 | |
emh203 | 0:7798270c1f52 | 684 | } |
emh203 | 0:7798270c1f52 | 685 | |
emh203 | 0:7798270c1f52 | 686 | |
emh203 | 0:7798270c1f52 | 687 | } |
emh203 | 0:7798270c1f52 | 688 | |
emh203 | 0:7798270c1f52 | 689 | void TerminalCmd_AIN(char *arg) |
emh203 | 0:7798270c1f52 | 690 | { |
emh203 | 0:7798270c1f52 | 691 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 692 | float Data; |
emh203 | 0:7798270c1f52 | 693 | |
emh203 | 0:7798270c1f52 | 694 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 695 | { |
emh203 | 0:7798270c1f52 | 696 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 697 | { |
emh203 | 0:7798270c1f52 | 698 | Data = ReadMISC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 699 | PC.printf("AIN:%d:%.3f",Channel,Data); |
emh203 | 0:7798270c1f52 | 700 | } |
emh203 | 0:7798270c1f52 | 701 | else |
emh203 | 0:7798270c1f52 | 702 | { |
emh203 | 0:7798270c1f52 | 703 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 704 | } |
emh203 | 0:7798270c1f52 | 705 | } |
emh203 | 0:7798270c1f52 | 706 | else |
emh203 | 0:7798270c1f52 | 707 | { |
emh203 | 0:7798270c1f52 | 708 | for(Channel = 0;Channel<=3;Channel++) |
emh203 | 0:7798270c1f52 | 709 | { |
emh203 | 0:7798270c1f52 | 710 | Data = ReadMISC_AnalogInput(Channel); |
emh203 | 0:7798270c1f52 | 711 | PC.printf("AIN:%d:%.3f\r\n",Channel,Data); |
emh203 | 0:7798270c1f52 | 712 | } |
emh203 | 0:7798270c1f52 | 713 | } |
emh203 | 0:7798270c1f52 | 714 | } |
emh203 | 0:7798270c1f52 | 715 | |
emh203 | 0:7798270c1f52 | 716 | |
emh203 | 0:7798270c1f52 | 717 | |
emh203 | 0:7798270c1f52 | 718 | void TerminalCmd_EnableHeater(char *arg) |
emh203 | 0:7798270c1f52 | 719 | { |
emh203 | 0:7798270c1f52 | 720 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 721 | |
emh203 | 0:7798270c1f52 | 722 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 723 | { |
emh203 | 0:7798270c1f52 | 724 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 725 | { |
emh203 | 0:7798270c1f52 | 726 | EnableHeater(Channel); |
emh203 | 0:7798270c1f52 | 727 | } |
emh203 | 0:7798270c1f52 | 728 | else |
emh203 | 0:7798270c1f52 | 729 | { |
emh203 | 0:7798270c1f52 | 730 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); |
emh203 | 0:7798270c1f52 | 731 | } |
emh203 | 0:7798270c1f52 | 732 | } |
emh203 | 0:7798270c1f52 | 733 | else |
emh203 | 0:7798270c1f52 | 734 | { |
emh203 | 0:7798270c1f52 | 735 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); |
emh203 | 0:7798270c1f52 | 736 | } |
emh203 | 0:7798270c1f52 | 737 | } |
emh203 | 0:7798270c1f52 | 738 | |
emh203 | 0:7798270c1f52 | 739 | void TerminalCmd_DisableHeater(char *arg) |
emh203 | 0:7798270c1f52 | 740 | { |
emh203 | 0:7798270c1f52 | 741 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 742 | |
emh203 | 0:7798270c1f52 | 743 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 744 | { |
emh203 | 0:7798270c1f52 | 745 | if(Channel>=0 && Channel <=7) |
emh203 | 0:7798270c1f52 | 746 | { |
emh203 | 0:7798270c1f52 | 747 | DisableHeater(Channel); |
emh203 | 0:7798270c1f52 | 748 | } |
emh203 | 0:7798270c1f52 | 749 | else |
emh203 | 0:7798270c1f52 | 750 | { |
emh203 | 0:7798270c1f52 | 751 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 7",Channel); |
emh203 | 0:7798270c1f52 | 752 | } |
emh203 | 0:7798270c1f52 | 753 | } |
emh203 | 0:7798270c1f52 | 754 | else |
emh203 | 0:7798270c1f52 | 755 | { |
emh203 | 0:7798270c1f52 | 756 | PC.printf("Bad argument... %s. Should be integer between 0 and 7",arg); |
emh203 | 0:7798270c1f52 | 757 | } |
emh203 | 0:7798270c1f52 | 758 | |
emh203 | 0:7798270c1f52 | 759 | } |
emh203 | 0:7798270c1f52 | 760 | |
emh203 | 0:7798270c1f52 | 761 | void TerminalCmd_EnableSolenoidValve(char *arg) |
emh203 | 0:7798270c1f52 | 762 | { |
emh203 | 0:7798270c1f52 | 763 | |
emh203 | 0:7798270c1f52 | 764 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 765 | |
emh203 | 0:7798270c1f52 | 766 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 767 | { |
emh203 | 0:7798270c1f52 | 768 | if(Channel>=0 && Channel <=11) |
emh203 | 0:7798270c1f52 | 769 | { |
emh203 | 0:7798270c1f52 | 770 | EnableSolenoidValve(Channel); |
emh203 | 0:7798270c1f52 | 771 | } |
emh203 | 0:7798270c1f52 | 772 | else |
emh203 | 0:7798270c1f52 | 773 | { |
emh203 | 0:7798270c1f52 | 774 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); |
emh203 | 0:7798270c1f52 | 775 | } |
emh203 | 0:7798270c1f52 | 776 | } |
emh203 | 0:7798270c1f52 | 777 | else |
emh203 | 0:7798270c1f52 | 778 | { |
emh203 | 0:7798270c1f52 | 779 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); |
emh203 | 0:7798270c1f52 | 780 | } |
emh203 | 0:7798270c1f52 | 781 | } |
emh203 | 0:7798270c1f52 | 782 | |
emh203 | 0:7798270c1f52 | 783 | void TerminalCmd_DisableSolenoidValue(char *arg) |
emh203 | 0:7798270c1f52 | 784 | { |
emh203 | 0:7798270c1f52 | 785 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 786 | |
emh203 | 0:7798270c1f52 | 787 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 788 | { |
emh203 | 0:7798270c1f52 | 789 | if( Channel >= 0 && Channel <= 11) |
emh203 | 0:7798270c1f52 | 790 | { |
emh203 | 0:7798270c1f52 | 791 | DisableSolenoidValue(Channel); |
emh203 | 0:7798270c1f52 | 792 | } |
emh203 | 0:7798270c1f52 | 793 | else |
emh203 | 0:7798270c1f52 | 794 | { |
emh203 | 0:7798270c1f52 | 795 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 11",Channel); |
emh203 | 0:7798270c1f52 | 796 | } |
emh203 | 0:7798270c1f52 | 797 | } |
emh203 | 0:7798270c1f52 | 798 | else |
emh203 | 0:7798270c1f52 | 799 | { |
emh203 | 0:7798270c1f52 | 800 | PC.printf("Bad argument... %s. Should be integer between 0 and 11",arg); |
emh203 | 0:7798270c1f52 | 801 | } |
emh203 | 0:7798270c1f52 | 802 | |
emh203 | 0:7798270c1f52 | 803 | } |
emh203 | 0:7798270c1f52 | 804 | void TerminalCmd_DisableAllHeatersAndSolenoids(char *arg) |
emh203 | 0:7798270c1f52 | 805 | { |
emh203 | 0:7798270c1f52 | 806 | |
emh203 | 0:7798270c1f52 | 807 | DisableAllHeatersAndSolenoids(); |
emh203 | 0:7798270c1f52 | 808 | |
emh203 | 0:7798270c1f52 | 809 | } |
emh203 | 0:7798270c1f52 | 810 | |
emh203 | 0:7798270c1f52 | 811 | void TerminalCmd_EnableMiscDigitalOutput(char *arg) |
emh203 | 0:7798270c1f52 | 812 | { |
emh203 | 0:7798270c1f52 | 813 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 814 | |
emh203 | 0:7798270c1f52 | 815 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 816 | { |
emh203 | 0:7798270c1f52 | 817 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 818 | { |
emh203 | 0:7798270c1f52 | 819 | EnableMiscDigitalOutput(Channel); |
emh203 | 0:7798270c1f52 | 820 | } |
emh203 | 0:7798270c1f52 | 821 | else |
emh203 | 0:7798270c1f52 | 822 | { |
emh203 | 0:7798270c1f52 | 823 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 824 | } |
emh203 | 0:7798270c1f52 | 825 | } |
emh203 | 0:7798270c1f52 | 826 | else |
emh203 | 0:7798270c1f52 | 827 | { |
emh203 | 0:7798270c1f52 | 828 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); |
emh203 | 0:7798270c1f52 | 829 | } |
emh203 | 0:7798270c1f52 | 830 | |
emh203 | 0:7798270c1f52 | 831 | } |
emh203 | 0:7798270c1f52 | 832 | |
emh203 | 0:7798270c1f52 | 833 | void TerminalCmd_DisableMiscDigitalOutput(char *arg) |
emh203 | 0:7798270c1f52 | 834 | { |
emh203 | 0:7798270c1f52 | 835 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 836 | |
emh203 | 0:7798270c1f52 | 837 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 838 | { |
emh203 | 0:7798270c1f52 | 839 | if(Channel>=0 && Channel <=3) |
emh203 | 0:7798270c1f52 | 840 | { |
emh203 | 0:7798270c1f52 | 841 | DisableMiscDigitalOutput(Channel); |
emh203 | 0:7798270c1f52 | 842 | } |
emh203 | 0:7798270c1f52 | 843 | else |
emh203 | 0:7798270c1f52 | 844 | { |
emh203 | 0:7798270c1f52 | 845 | PC.printf("%d is an invalid channel. Channel should be integer between 0 and 3",Channel); |
emh203 | 0:7798270c1f52 | 846 | } |
emh203 | 0:7798270c1f52 | 847 | } |
emh203 | 0:7798270c1f52 | 848 | else |
emh203 | 0:7798270c1f52 | 849 | { |
emh203 | 0:7798270c1f52 | 850 | PC.printf("Bad argument... %s. Should be integer between 0 and 3",arg); |
emh203 | 0:7798270c1f52 | 851 | } |
emh203 | 0:7798270c1f52 | 852 | |
emh203 | 0:7798270c1f52 | 853 | } |
emh203 | 0:7798270c1f52 | 854 | |
emh203 | 0:7798270c1f52 | 855 | void TerminalCmd_FlushDigitalIO(char *arg) |
emh203 | 0:7798270c1f52 | 856 | { |
emh203 | 0:7798270c1f52 | 857 | FlushDigitalIO(); |
emh203 | 0:7798270c1f52 | 858 | } |
emh203 | 0:7798270c1f52 | 859 | |
emh203 | 0:7798270c1f52 | 860 | void TerminalCmd_FanOn(char *arg) |
emh203 | 0:7798270c1f52 | 861 | { |
emh203 | 0:7798270c1f52 | 862 | SetFanSpeed(100); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off |
wavenumber | 2:73a028278c5c | 863 | MBED_LED1 = 1; |
emh203 | 0:7798270c1f52 | 864 | } |
emh203 | 0:7798270c1f52 | 865 | |
emh203 | 0:7798270c1f52 | 866 | void TerminalCmd_FanOff(char *arg) |
emh203 | 0:7798270c1f52 | 867 | { |
emh203 | 0:7798270c1f52 | 868 | SetFanSpeed(0); //PWMing the FANs doesn't work with the ME40100V1 models! WE will just on or off |
wavenumber | 2:73a028278c5c | 869 | MBED_LED1 = 0; |
emh203 | 0:7798270c1f52 | 870 | } |
emh203 | 0:7798270c1f52 | 871 | |
emh203 | 0:7798270c1f52 | 872 | void TerminalCmd_Fan(char *arg) |
emh203 | 0:7798270c1f52 | 873 | { |
emh203 | 0:7798270c1f52 | 874 | int Speed = -1; |
emh203 | 0:7798270c1f52 | 875 | |
emh203 | 0:7798270c1f52 | 876 | if(sscanf(arg,"%d",&Speed) == 1) |
emh203 | 0:7798270c1f52 | 877 | { |
emh203 | 0:7798270c1f52 | 878 | if(Speed>=0 && Speed<=100) |
emh203 | 0:7798270c1f52 | 879 | { |
emh203 | 0:7798270c1f52 | 880 | SetFanSpeed(Speed); |
emh203 | 0:7798270c1f52 | 881 | } |
emh203 | 0:7798270c1f52 | 882 | else |
emh203 | 0:7798270c1f52 | 883 | { |
emh203 | 0:7798270c1f52 | 884 | PC.printf("%d is an invalid speed. Speed should be between 0 and 100",Speed); |
emh203 | 0:7798270c1f52 | 885 | } |
emh203 | 0:7798270c1f52 | 886 | } |
emh203 | 0:7798270c1f52 | 887 | else |
emh203 | 0:7798270c1f52 | 888 | { |
emh203 | 0:7798270c1f52 | 889 | PC.printf("Bad argument... %s. Should be integer between 0 and 100",arg); |
emh203 | 0:7798270c1f52 | 890 | } |
emh203 | 0:7798270c1f52 | 891 | |
emh203 | 0:7798270c1f52 | 892 | } |
emh203 | 0:7798270c1f52 | 893 | |
emh203 | 0:7798270c1f52 | 894 | |
emh203 | 0:7798270c1f52 | 895 | void TerminalCmd_T(char *arg) |
emh203 | 0:7798270c1f52 | 896 | { |
emh203 | 0:7798270c1f52 | 897 | float Temp = 0; |
emh203 | 0:7798270c1f52 | 898 | int Channel = -1; |
emh203 | 0:7798270c1f52 | 899 | |
emh203 | 0:7798270c1f52 | 900 | if(sscanf(arg,"%d",&Channel) == 1) |
emh203 | 0:7798270c1f52 | 901 | { |
emh203 | 0:7798270c1f52 | 902 | Temp = ReadThermocouple(Channel); |
emh203 | 0:7798270c1f52 | 903 | PC.printf("TEMP:%d:%.2f\r\n",Channel,Temp); |
emh203 | 0:7798270c1f52 | 904 | } |
emh203 | 0:7798270c1f52 | 905 | else |
emh203 | 0:7798270c1f52 | 906 | { |
emh203 | 0:7798270c1f52 | 907 | for(Channel = 0; Channel<12;Channel++) |
emh203 | 0:7798270c1f52 | 908 | { |
emh203 | 0:7798270c1f52 | 909 | Temp = ReadThermocouple(Channel); |
emh203 | 0:7798270c1f52 | 910 | PC.printf("TEMP:%d:%.2f\r\n",Channel,Temp); |
emh203 | 0:7798270c1f52 | 911 | } |
emh203 | 0:7798270c1f52 | 912 | } |
emh203 | 0:7798270c1f52 | 913 | } |
emh203 | 0:7798270c1f52 | 914 | |
emh203 | 0:7798270c1f52 | 915 | void TerminalCmd_Buzz(char *arg) |
emh203 | 0:7798270c1f52 | 916 | { |
emh203 | 0:7798270c1f52 | 917 | |
emh203 | 0:7798270c1f52 | 918 | float T = -1.0; |
emh203 | 0:7798270c1f52 | 919 | |
emh203 | 0:7798270c1f52 | 920 | if(sscanf(arg,"%f",&T) == 1) |
emh203 | 0:7798270c1f52 | 921 | { |
emh203 | 0:7798270c1f52 | 922 | if(T>=0.0 && T<=5.0) |
emh203 | 0:7798270c1f52 | 923 | { |
emh203 | 0:7798270c1f52 | 924 | Buzz(T); |
emh203 | 0:7798270c1f52 | 925 | } |
emh203 | 0:7798270c1f52 | 926 | else |
emh203 | 0:7798270c1f52 | 927 | { |
emh203 | 0:7798270c1f52 | 928 | PC.printf("%f is an invalid time period for buzz. Time should be between 0.0 and 5.0 seconds",T); |
emh203 | 0:7798270c1f52 | 929 | } |
emh203 | 0:7798270c1f52 | 930 | } |
emh203 | 0:7798270c1f52 | 931 | else |
emh203 | 0:7798270c1f52 | 932 | { |
emh203 | 0:7798270c1f52 | 933 | PC.printf("Bad argument... %s. Should be float between 0.0 and 5.0",arg); |
emh203 | 0:7798270c1f52 | 934 | } |
emh203 | 0:7798270c1f52 | 935 | |
emh203 | 0:7798270c1f52 | 936 | } |
emh203 | 0:7798270c1f52 | 937 | |
emh203 | 0:7798270c1f52 | 938 | |
emh203 | 0:7798270c1f52 | 939 | |
emh203 | 0:7798270c1f52 | 940 | |
emh203 | 0:7798270c1f52 | 941 | //***************************************************************** |
emh203 | 0:7798270c1f52 | 942 | //Plumbing..... |
emh203 | 0:7798270c1f52 | 943 | //***************************************************************** |
emh203 | 0:7798270c1f52 | 944 | |
emh203 | 0:7798270c1f52 | 945 | #define NUM_TERMINAL_COMMANDS (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord)) |
emh203 | 0:7798270c1f52 | 946 | |
emh203 | 0:7798270c1f52 | 947 | char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS]; |
emh203 | 0:7798270c1f52 | 948 | uint8_t TerminalPos; |
emh203 | 0:7798270c1f52 | 949 | char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1]; |
emh203 | 0:7798270c1f52 | 950 | char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS]; |
emh203 | 0:7798270c1f52 | 951 | uint8_t NextCharIn; |
emh203 | 0:7798270c1f52 | 952 | uint8_t CmdFound; |
emh203 | 0:7798270c1f52 | 953 | |
emh203 | 0:7798270c1f52 | 954 | void TerminalBootMsg() |
emh203 | 0:7798270c1f52 | 955 | { |
emh203 | 0:7798270c1f52 | 956 | |
emh203 | 0:7798270c1f52 | 957 | PC.printf("\r\n\r\n"); |
emh203 | 0:7798270c1f52 | 958 | PC.printf("***********************************\r\n"); |
emh203 | 0:7798270c1f52 | 959 | PC.printf("CHEM Control Box \r\n"); |
emh203 | 0:7798270c1f52 | 960 | PC.printf("API Version %s \r\n",API_VERSION); |
emh203 | 0:7798270c1f52 | 961 | PC.printf("Copyright (C) <2013> Eli Hughes\r\n"); |
emh203 | 0:7798270c1f52 | 962 | PC.printf("Wavenumber LLC\r\n"); |
emh203 | 0:7798270c1f52 | 963 | PC.printf("***********************************\r\n\r\n>"); |
emh203 | 0:7798270c1f52 | 964 | |
emh203 | 0:7798270c1f52 | 965 | } |
emh203 | 0:7798270c1f52 | 966 | |
emh203 | 0:7798270c1f52 | 967 | void InitTerminal() |
emh203 | 0:7798270c1f52 | 968 | { |
emh203 | 0:7798270c1f52 | 969 | |
emh203 | 0:7798270c1f52 | 970 | PC.baud(115200); |
emh203 | 0:7798270c1f52 | 971 | TerminalPos = 0; |
emh203 | 0:7798270c1f52 | 972 | CmdFound = 0; |
emh203 | 0:7798270c1f52 | 973 | TerminalBootMsg(); |
emh203 | 0:7798270c1f52 | 974 | } |
emh203 | 0:7798270c1f52 | 975 | |
emh203 | 0:7798270c1f52 | 976 | void TerminalCmd_Help(char *arg) |
emh203 | 0:7798270c1f52 | 977 | { |
emh203 | 0:7798270c1f52 | 978 | uint8_t i; |
emh203 | 0:7798270c1f52 | 979 | |
emh203 | 0:7798270c1f52 | 980 | PC.printf("\r\n\r\nCommand List:\r\n"); |
emh203 | 0:7798270c1f52 | 981 | PC.printf("----------------------\r\n"); |
emh203 | 0:7798270c1f52 | 982 | |
emh203 | 0:7798270c1f52 | 983 | for(i=0;i<NUM_TERMINAL_COMMANDS;i++) |
emh203 | 0:7798270c1f52 | 984 | { |
emh203 | 0:7798270c1f52 | 985 | PC.printf("%s ----> %s\r\n\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString); |
emh203 | 0:7798270c1f52 | 986 | } |
emh203 | 0:7798270c1f52 | 987 | |
emh203 | 0:7798270c1f52 | 988 | PC.printf("\r\n\r\n"); |
emh203 | 0:7798270c1f52 | 989 | } |
emh203 | 0:7798270c1f52 | 990 | |
emh203 | 0:7798270c1f52 | 991 | void TerminalCmd_Reboot(char *arg) |
emh203 | 0:7798270c1f52 | 992 | { |
emh203 | 0:7798270c1f52 | 993 | TerminalBootMsg(); |
emh203 | 0:7798270c1f52 | 994 | } |
emh203 | 0:7798270c1f52 | 995 | |
emh203 | 0:7798270c1f52 | 996 | void ProcessTerminal() |
emh203 | 0:7798270c1f52 | 997 | { |
emh203 | 0:7798270c1f52 | 998 | uint8_t i,j; |
emh203 | 0:7798270c1f52 | 999 | uint8_t ArgsFound; |
emh203 | 0:7798270c1f52 | 1000 | |
emh203 | 0:7798270c1f52 | 1001 | if(PC.readable()) |
emh203 | 0:7798270c1f52 | 1002 | { |
emh203 | 0:7798270c1f52 | 1003 | NextCharIn = PC.getc(); |
emh203 | 0:7798270c1f52 | 1004 | |
emh203 | 0:7798270c1f52 | 1005 | switch(NextCharIn) |
emh203 | 0:7798270c1f52 | 1006 | { |
emh203 | 0:7798270c1f52 | 1007 | case '\r': |
emh203 | 0:7798270c1f52 | 1008 | |
emh203 | 0:7798270c1f52 | 1009 | TerminalLineBuf[TerminalPos++] = 0x0; |
wavenumber | 2:73a028278c5c | 1010 | |
wavenumber | 2:73a028278c5c | 1011 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1012 | { |
wavenumber | 2:73a028278c5c | 1013 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1014 | } |
wavenumber | 2:73a028278c5c | 1015 | |
emh203 | 0:7798270c1f52 | 1016 | if(TerminalPos > 1) |
emh203 | 0:7798270c1f52 | 1017 | { |
emh203 | 0:7798270c1f52 | 1018 | //find the command |
emh203 | 0:7798270c1f52 | 1019 | i=0; |
emh203 | 0:7798270c1f52 | 1020 | while(TerminalLineBuf[i]>0x20 && TerminalLineBuf[i]<0x7f) |
emh203 | 0:7798270c1f52 | 1021 | { |
emh203 | 0:7798270c1f52 | 1022 | TerminalCmdBuf[i] = TerminalLineBuf[i]; |
emh203 | 0:7798270c1f52 | 1023 | i++; |
emh203 | 0:7798270c1f52 | 1024 | |
emh203 | 0:7798270c1f52 | 1025 | if(i==MAX_TERMINAL_CMD_CHARS) |
emh203 | 0:7798270c1f52 | 1026 | { |
emh203 | 0:7798270c1f52 | 1027 | break; |
emh203 | 0:7798270c1f52 | 1028 | } |
emh203 | 0:7798270c1f52 | 1029 | } |
emh203 | 0:7798270c1f52 | 1030 | |
emh203 | 0:7798270c1f52 | 1031 | TerminalCmdBuf[i] = 0; |
emh203 | 0:7798270c1f52 | 1032 | TerminalCmdBuf[i+1] = 0; |
emh203 | 0:7798270c1f52 | 1033 | |
emh203 | 0:7798270c1f52 | 1034 | |
emh203 | 0:7798270c1f52 | 1035 | ArgsFound = TRUE; |
emh203 | 0:7798270c1f52 | 1036 | memset(TerminalArgs,0x00,sizeof(TerminalArgs)); |
emh203 | 0:7798270c1f52 | 1037 | //scan for num terminator or next non whitespace |
emh203 | 0:7798270c1f52 | 1038 | while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS)) |
emh203 | 0:7798270c1f52 | 1039 | { |
emh203 | 0:7798270c1f52 | 1040 | if(TerminalLineBuf[i] == 0x00) |
emh203 | 0:7798270c1f52 | 1041 | { |
emh203 | 0:7798270c1f52 | 1042 | |
emh203 | 0:7798270c1f52 | 1043 | //if we find a NULL terminator before a non whitespace character they flag for no arguments |
emh203 | 0:7798270c1f52 | 1044 | ArgsFound = FALSE; |
emh203 | 0:7798270c1f52 | 1045 | break; |
emh203 | 0:7798270c1f52 | 1046 | } |
emh203 | 0:7798270c1f52 | 1047 | i++; |
emh203 | 0:7798270c1f52 | 1048 | } |
emh203 | 0:7798270c1f52 | 1049 | |
emh203 | 0:7798270c1f52 | 1050 | if(ArgsFound == TRUE) |
emh203 | 0:7798270c1f52 | 1051 | { |
emh203 | 0:7798270c1f52 | 1052 | strcpy(TerminalArgs,&TerminalLineBuf[i]); |
emh203 | 0:7798270c1f52 | 1053 | |
emh203 | 0:7798270c1f52 | 1054 | //trim trailing whitespace |
emh203 | 0:7798270c1f52 | 1055 | i = sizeof(TerminalArgs)-1; |
emh203 | 0:7798270c1f52 | 1056 | |
emh203 | 0:7798270c1f52 | 1057 | while((TerminalArgs[i]<0x21) && (i>0)) |
emh203 | 0:7798270c1f52 | 1058 | { |
emh203 | 0:7798270c1f52 | 1059 | TerminalArgs[i]= 0x00; |
emh203 | 0:7798270c1f52 | 1060 | i--; |
emh203 | 0:7798270c1f52 | 1061 | } |
emh203 | 0:7798270c1f52 | 1062 | } |
emh203 | 0:7798270c1f52 | 1063 | |
emh203 | 0:7798270c1f52 | 1064 | CmdFound = FALSE; |
emh203 | 0:7798270c1f52 | 1065 | for(j=0;j<NUM_TERMINAL_COMMANDS;j++) |
emh203 | 0:7798270c1f52 | 1066 | { |
emh203 | 0:7798270c1f52 | 1067 | if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0) |
emh203 | 0:7798270c1f52 | 1068 | { |
emh203 | 0:7798270c1f52 | 1069 | PC.printf("\r\n"); |
emh203 | 0:7798270c1f52 | 1070 | if(MyTerminalCallbackRecords[j].Callback != NULL) |
emh203 | 0:7798270c1f52 | 1071 | MyTerminalCallbackRecords[j].Callback(TerminalArgs); |
emh203 | 0:7798270c1f52 | 1072 | |
emh203 | 0:7798270c1f52 | 1073 | CmdFound = TRUE; |
emh203 | 0:7798270c1f52 | 1074 | break; |
emh203 | 0:7798270c1f52 | 1075 | } |
emh203 | 0:7798270c1f52 | 1076 | } |
emh203 | 0:7798270c1f52 | 1077 | if(CmdFound == FALSE) |
emh203 | 0:7798270c1f52 | 1078 | { |
emh203 | 0:7798270c1f52 | 1079 | PC.printf("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf); |
emh203 | 0:7798270c1f52 | 1080 | TerminalCmd_Help("no arg"); |
emh203 | 0:7798270c1f52 | 1081 | |
emh203 | 0:7798270c1f52 | 1082 | } |
emh203 | 0:7798270c1f52 | 1083 | } |
wavenumber | 2:73a028278c5c | 1084 | PC.printf("\r\n"); |
emh203 | 0:7798270c1f52 | 1085 | TerminalPos = 0; |
emh203 | 0:7798270c1f52 | 1086 | |
emh203 | 0:7798270c1f52 | 1087 | break; |
emh203 | 0:7798270c1f52 | 1088 | |
emh203 | 0:7798270c1f52 | 1089 | case '\b': |
emh203 | 0:7798270c1f52 | 1090 | if(TerminalPos > 0) |
emh203 | 0:7798270c1f52 | 1091 | { |
wavenumber | 2:73a028278c5c | 1092 | TerminalPos--; |
wavenumber | 2:73a028278c5c | 1093 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1094 | { |
wavenumber | 2:73a028278c5c | 1095 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1096 | } |
emh203 | 0:7798270c1f52 | 1097 | } |
emh203 | 0:7798270c1f52 | 1098 | break; |
emh203 | 0:7798270c1f52 | 1099 | |
emh203 | 0:7798270c1f52 | 1100 | default: |
emh203 | 0:7798270c1f52 | 1101 | |
emh203 | 0:7798270c1f52 | 1102 | if(TerminalPos == 0 && NextCharIn == 0x020) |
emh203 | 0:7798270c1f52 | 1103 | { |
emh203 | 0:7798270c1f52 | 1104 | //Do nothing if space bar is pressed at beginning of line |
emh203 | 0:7798270c1f52 | 1105 | } |
emh203 | 0:7798270c1f52 | 1106 | else if(NextCharIn >= 0x20 && NextCharIn<0x7F) |
emh203 | 0:7798270c1f52 | 1107 | { |
emh203 | 0:7798270c1f52 | 1108 | |
emh203 | 0:7798270c1f52 | 1109 | if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1) |
emh203 | 0:7798270c1f52 | 1110 | { |
emh203 | 0:7798270c1f52 | 1111 | TerminalLineBuf[TerminalPos++] = NextCharIn; |
wavenumber | 2:73a028278c5c | 1112 | if(TerminalEcho) |
wavenumber | 2:73a028278c5c | 1113 | { |
wavenumber | 2:73a028278c5c | 1114 | PC.putc(NextCharIn); |
wavenumber | 2:73a028278c5c | 1115 | } |
emh203 | 0:7798270c1f52 | 1116 | } |
emh203 | 0:7798270c1f52 | 1117 | } |
emh203 | 0:7798270c1f52 | 1118 | |
emh203 | 0:7798270c1f52 | 1119 | break; |
emh203 | 0:7798270c1f52 | 1120 | |
emh203 | 0:7798270c1f52 | 1121 | } |
emh203 | 0:7798270c1f52 | 1122 | } |
emh203 | 0:7798270c1f52 | 1123 | |
emh203 | 0:7798270c1f52 | 1124 | } |
emh203 | 0:7798270c1f52 | 1125 | |
emh203 | 0:7798270c1f52 | 1126 | |
emh203 | 0:7798270c1f52 | 1127 | |
emh203 | 0:7798270c1f52 | 1128 | |
emh203 | 0:7798270c1f52 | 1129 | |
emh203 | 0:7798270c1f52 | 1130 | // _ _____ _____ _______ _____ _____ _ _ _____ _____ _____ |
emh203 | 0:7798270c1f52 | 1131 | // | | / ____| __ \ / / ____| __ \ /\ | __ \| | | |_ _/ ____|/ ____| |
emh203 | 0:7798270c1f52 | 1132 | // | | | | | | | | / / | __| |__) | / \ | |__) | |__| | | || | | (___ |
emh203 | 0:7798270c1f52 | 1133 | // | | | | | | | |/ /| | |_ | _ / / /\ \ | ___/| __ | | || | \___ \ |
emh203 | 0:7798270c1f52 | 1134 | // | |___| |____| |__| / / | |__| | | \ \ / ____ \| | | | | |_| || |____ ____) | |
emh203 | 0:7798270c1f52 | 1135 | // |______\_____|_____/_/ \_____|_| \_\/_/ \_\_| |_| |_|_____\_____|_____/ |
emh203 | 0:7798270c1f52 | 1136 | // |
emh203 | 0:7798270c1f52 | 1137 | // |
emh203 | 0:7798270c1f52 | 1138 | |
emh203 | 0:7798270c1f52 | 1139 | void SmartSwitch_Reset(); |
emh203 | 0:7798270c1f52 | 1140 | void SmartSwitch_SetBrightness(uint8_t Brightness); |
emh203 | 0:7798270c1f52 | 1141 | void InitSmartSwitch(); |
emh203 | 0:7798270c1f52 | 1142 | void PowerUpSmartSwitch(); |
emh203 | 0:7798270c1f52 | 1143 | void PowerDownSmartSwitch(); |
emh203 | 0:7798270c1f52 | 1144 | void SmartSwitchWriteByte(uint8_t DataOut); |
emh203 | 0:7798270c1f52 | 1145 | void SmartSwitch_SetBackLightColor2(uint8_t RGB); |
emh203 | 0:7798270c1f52 | 1146 | void SmartSwitch_ImageDump(uint8_t *Img); |
emh203 | 0:7798270c1f52 | 1147 | void SmartSwitchClear(); |
emh203 | 0:7798270c1f52 | 1148 | |
emh203 | 0:7798270c1f52 | 1149 | |
emh203 | 0:7798270c1f52 | 1150 | |
emh203 | 0:7798270c1f52 | 1151 | |
emh203 | 0:7798270c1f52 | 1152 | #define BACK_BUFFER_SIZE_X (64) |
emh203 | 0:7798270c1f52 | 1153 | #define BACK_BUFFER_SIZE_Y (32) |
emh203 | 0:7798270c1f52 | 1154 | |
emh203 | 0:7798270c1f52 | 1155 | #define PHYSICAL_DISPLAY_XRES (uint8_t)(64) |
emh203 | 0:7798270c1f52 | 1156 | #define PHYSICAL_DISPLAY_YRES (uint8_t)(32) |
emh203 | 0:7798270c1f52 | 1157 | #define DISPLAY_X_WIDTH_BYTE (PHYSICAL_DISPLAY_XRES>>3) |
emh203 | 0:7798270c1f52 | 1158 | #define DISPLAY_BUFFER_TOTAL_SIZE (DISPLAY_X_WIDTH_BYTE*PHYSICAL_DISPLAY_YRES*2) |
emh203 | 0:7798270c1f52 | 1159 | #define GREEN_DATA_BUFFER_OFFSET (DISPLAY_X_WIDTH_BYTE * PHYSICAL_DISPLAY_YRES) |
emh203 | 0:7798270c1f52 | 1160 | #define PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES (PHYSICAL_DISPLAY_XRES>>3) |
emh203 | 0:7798270c1f52 | 1161 | #define PHYSICAL_DISPLAY_PLANE_BUFFER_SIZE (PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES * PHYSICAL_DISPLAY_YRES) |
emh203 | 0:7798270c1f52 | 1162 | #define PHYSICAL_DISPLAY_BUFFER_TOTAL_SIZE (PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES * PHYSICAL_DISPLAY_YRES*2) |
emh203 | 0:7798270c1f52 | 1163 | |
emh203 | 0:7798270c1f52 | 1164 | #define SMART_SWITCH_CMD_DISPLAY_DATA 0x55 |
emh203 | 0:7798270c1f52 | 1165 | #define SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR 0x40 |
emh203 | 0:7798270c1f52 | 1166 | #define SMART_SWITCH_CMD_SET_BRIGHTNESS 0x41 |
emh203 | 0:7798270c1f52 | 1167 | #define SMART_SWITCH_CMD_RESET 0x5E |
emh203 | 0:7798270c1f52 | 1168 | #define SMART_SWITCH_CMD_RESET_PARAMETER 0x03 |
emh203 | 0:7798270c1f52 | 1169 | |
emh203 | 0:7798270c1f52 | 1170 | #define SMART_SWITCH_BACKLIGHT_RED (0x03<<4) |
emh203 | 0:7798270c1f52 | 1171 | #define SMART_SWITCH_BACKLIGHT_YELLOW (0x03<<4)|(0x03<<2) |
emh203 | 0:7798270c1f52 | 1172 | #define SMART_SWITCH_BACKLIGHT_GREEN (0x03<<2) |
emh203 | 0:7798270c1f52 | 1173 | |
emh203 | 0:7798270c1f52 | 1174 | #define GFX_MAX_STRING_LEN 32 |
emh203 | 0:7798270c1f52 | 1175 | |
emh203 | 0:7798270c1f52 | 1176 | void SmartSwitch_ImageDump(uint8_t *Img) |
emh203 | 0:7798270c1f52 | 1177 | { |
emh203 | 0:7798270c1f52 | 1178 | int i; |
emh203 | 0:7798270c1f52 | 1179 | |
emh203 | 0:7798270c1f52 | 1180 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1181 | |
emh203 | 0:7798270c1f52 | 1182 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1183 | SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA); |
emh203 | 0:7798270c1f52 | 1184 | |
emh203 | 0:7798270c1f52 | 1185 | for(i=0;i<256;i++) |
emh203 | 0:7798270c1f52 | 1186 | { |
emh203 | 0:7798270c1f52 | 1187 | SmartSwitchWriteByte(Img[i]); |
emh203 | 0:7798270c1f52 | 1188 | } |
emh203 | 0:7798270c1f52 | 1189 | |
emh203 | 0:7798270c1f52 | 1190 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1191 | } |
emh203 | 0:7798270c1f52 | 1192 | |
emh203 | 0:7798270c1f52 | 1193 | void SmartSwitchClear() |
emh203 | 0:7798270c1f52 | 1194 | { |
emh203 | 0:7798270c1f52 | 1195 | int i; |
emh203 | 0:7798270c1f52 | 1196 | |
emh203 | 0:7798270c1f52 | 1197 | |
emh203 | 0:7798270c1f52 | 1198 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1199 | |
emh203 | 0:7798270c1f52 | 1200 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1201 | SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA); |
emh203 | 0:7798270c1f52 | 1202 | |
emh203 | 0:7798270c1f52 | 1203 | for(i=0;i<256;i++) |
emh203 | 0:7798270c1f52 | 1204 | { |
emh203 | 0:7798270c1f52 | 1205 | SmartSwitchWriteByte(0x00); |
emh203 | 0:7798270c1f52 | 1206 | } |
emh203 | 0:7798270c1f52 | 1207 | |
emh203 | 0:7798270c1f52 | 1208 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1209 | } |
emh203 | 0:7798270c1f52 | 1210 | |
emh203 | 0:7798270c1f52 | 1211 | void SmartSwitch_Reset() |
emh203 | 0:7798270c1f52 | 1212 | { |
emh203 | 0:7798270c1f52 | 1213 | |
emh203 | 0:7798270c1f52 | 1214 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1215 | |
emh203 | 0:7798270c1f52 | 1216 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1217 | SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET); |
emh203 | 0:7798270c1f52 | 1218 | SmartSwitchWriteByte(SMART_SWITCH_CMD_RESET_PARAMETER); |
emh203 | 0:7798270c1f52 | 1219 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1220 | } |
emh203 | 0:7798270c1f52 | 1221 | |
emh203 | 0:7798270c1f52 | 1222 | void SmartSwitch_SetBackLightColor(uint8_t Red,uint8_t Green,uint8_t Blue) |
emh203 | 0:7798270c1f52 | 1223 | { |
emh203 | 0:7798270c1f52 | 1224 | |
emh203 | 0:7798270c1f52 | 1225 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1226 | |
emh203 | 0:7798270c1f52 | 1227 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1228 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR); |
emh203 | 0:7798270c1f52 | 1229 | SmartSwitchWriteByte(Red<<6 | Green<<4 | Blue <<2 | 0x3); |
emh203 | 0:7798270c1f52 | 1230 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1231 | } |
emh203 | 0:7798270c1f52 | 1232 | |
emh203 | 0:7798270c1f52 | 1233 | void SmartSwitch_SetBackLightColor2(uint8_t RGB) |
emh203 | 0:7798270c1f52 | 1234 | { |
emh203 | 0:7798270c1f52 | 1235 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1236 | |
emh203 | 0:7798270c1f52 | 1237 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1238 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BACKLIGHT_COLOR); |
emh203 | 0:7798270c1f52 | 1239 | SmartSwitchWriteByte(RGB<<2 | 0x3); |
emh203 | 0:7798270c1f52 | 1240 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1241 | } |
emh203 | 0:7798270c1f52 | 1242 | |
emh203 | 0:7798270c1f52 | 1243 | void SmartSwitch_SetBrightness(uint8_t Brightness) |
emh203 | 0:7798270c1f52 | 1244 | { |
emh203 | 0:7798270c1f52 | 1245 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1246 | |
emh203 | 0:7798270c1f52 | 1247 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1248 | SmartSwitchWriteByte(SMART_SWITCH_CMD_SET_BRIGHTNESS); |
emh203 | 0:7798270c1f52 | 1249 | SmartSwitchWriteByte(Brightness<<5 | 0x1F); |
emh203 | 0:7798270c1f52 | 1250 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1251 | } |
emh203 | 0:7798270c1f52 | 1252 | |
emh203 | 0:7798270c1f52 | 1253 | void InitSmartSwitch() |
emh203 | 0:7798270c1f52 | 1254 | { |
emh203 | 0:7798270c1f52 | 1255 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1256 | SmartSwitch_Reset(); |
emh203 | 0:7798270c1f52 | 1257 | } |
emh203 | 0:7798270c1f52 | 1258 | |
emh203 | 0:7798270c1f52 | 1259 | void SmartSwitchWriteByte(uint8_t DataOut) |
emh203 | 0:7798270c1f52 | 1260 | { |
emh203 | 0:7798270c1f52 | 1261 | |
emh203 | 0:7798270c1f52 | 1262 | SPI1.write(DataOut); |
emh203 | 0:7798270c1f52 | 1263 | |
emh203 | 0:7798270c1f52 | 1264 | } |
emh203 | 0:7798270c1f52 | 1265 | |
emh203 | 0:7798270c1f52 | 1266 | |
emh203 | 0:7798270c1f52 | 1267 | //Linking Functions to Physical Screen |
emh203 | 0:7798270c1f52 | 1268 | //*********************************************************************************** |
emh203 | 0:7798270c1f52 | 1269 | |
emh203 | 0:7798270c1f52 | 1270 | void GFX_InitPhysicalScreen() |
emh203 | 0:7798270c1f52 | 1271 | { |
emh203 | 0:7798270c1f52 | 1272 | InitSmartSwitch(); |
emh203 | 0:7798270c1f52 | 1273 | } |
emh203 | 0:7798270c1f52 | 1274 | |
emh203 | 0:7798270c1f52 | 1275 | |
emh203 | 0:7798270c1f52 | 1276 | const uint8_t BitReverseTable[256] = |
emh203 | 0:7798270c1f52 | 1277 | { |
emh203 | 0:7798270c1f52 | 1278 | 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, |
emh203 | 0:7798270c1f52 | 1279 | 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, |
emh203 | 0:7798270c1f52 | 1280 | 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, |
emh203 | 0:7798270c1f52 | 1281 | 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, |
emh203 | 0:7798270c1f52 | 1282 | 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, |
emh203 | 0:7798270c1f52 | 1283 | 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, |
emh203 | 0:7798270c1f52 | 1284 | 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, |
emh203 | 0:7798270c1f52 | 1285 | 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, |
emh203 | 0:7798270c1f52 | 1286 | 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, |
emh203 | 0:7798270c1f52 | 1287 | 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, |
emh203 | 0:7798270c1f52 | 1288 | 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, |
emh203 | 0:7798270c1f52 | 1289 | 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, |
emh203 | 0:7798270c1f52 | 1290 | 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, |
emh203 | 0:7798270c1f52 | 1291 | 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, |
emh203 | 0:7798270c1f52 | 1292 | 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, |
emh203 | 0:7798270c1f52 | 1293 | 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, |
emh203 | 0:7798270c1f52 | 1294 | 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, |
emh203 | 0:7798270c1f52 | 1295 | 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, |
emh203 | 0:7798270c1f52 | 1296 | 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, |
emh203 | 0:7798270c1f52 | 1297 | 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, |
emh203 | 0:7798270c1f52 | 1298 | 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, |
emh203 | 0:7798270c1f52 | 1299 | 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, |
emh203 | 0:7798270c1f52 | 1300 | 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, |
emh203 | 0:7798270c1f52 | 1301 | 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, |
emh203 | 0:7798270c1f52 | 1302 | 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, |
emh203 | 0:7798270c1f52 | 1303 | 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, |
emh203 | 0:7798270c1f52 | 1304 | 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, |
emh203 | 0:7798270c1f52 | 1305 | 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, |
emh203 | 0:7798270c1f52 | 1306 | 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, |
emh203 | 0:7798270c1f52 | 1307 | 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, |
emh203 | 0:7798270c1f52 | 1308 | 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, |
emh203 | 0:7798270c1f52 | 1309 | 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff |
emh203 | 0:7798270c1f52 | 1310 | }; |
emh203 | 0:7798270c1f52 | 1311 | |
emh203 | 0:7798270c1f52 | 1312 | void GFX_DumpRenderContextToPhysicalScreen(RenderContext *Image) |
emh203 | 0:7798270c1f52 | 1313 | { |
emh203 | 0:7798270c1f52 | 1314 | int x,y; |
emh203 | 0:7798270c1f52 | 1315 | uint8_t NextByteOut; |
emh203 | 0:7798270c1f52 | 1316 | |
emh203 | 0:7798270c1f52 | 1317 | SPI1.format(8,2); |
emh203 | 0:7798270c1f52 | 1318 | |
emh203 | 0:7798270c1f52 | 1319 | SmartSwitch_SS = 0; |
emh203 | 0:7798270c1f52 | 1320 | SmartSwitchWriteByte(SMART_SWITCH_CMD_DISPLAY_DATA); |
emh203 | 0:7798270c1f52 | 1321 | |
emh203 | 0:7798270c1f52 | 1322 | for(y=0;y<PHYSICAL_DISPLAY_YRES;y++) |
emh203 | 0:7798270c1f52 | 1323 | { |
emh203 | 0:7798270c1f52 | 1324 | for(x=0;x<PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES;x++) |
emh203 | 0:7798270c1f52 | 1325 | { |
emh203 | 0:7798270c1f52 | 1326 | //Need to rotate the display 180 degrees |
emh203 | 0:7798270c1f52 | 1327 | NextByteOut = Image->RenderPlane.BitPlaneSpace[(((PHYSICAL_DISPLAY_YRES - y - 1) * PHYSICAL_DISPLAY_X_WIDTH_IN_BYTES)) + x]; |
emh203 | 0:7798270c1f52 | 1328 | SmartSwitchWriteByte(BitReverseTable[NextByteOut]); |
emh203 | 0:7798270c1f52 | 1329 | } |
emh203 | 0:7798270c1f52 | 1330 | } |
emh203 | 0:7798270c1f52 | 1331 | SmartSwitch_SS = 1; |
emh203 | 0:7798270c1f52 | 1332 | } |
emh203 | 0:7798270c1f52 | 1333 | |
emh203 | 0:7798270c1f52 | 1334 | |
emh203 | 0:7798270c1f52 | 1335 | //Device Independent Functions |
emh203 | 0:7798270c1f52 | 1336 | //*********************************************************************************** |
emh203 | 0:7798270c1f52 | 1337 | |
emh203 | 0:7798270c1f52 | 1338 | //Reserve Space for the backbuffer |
emh203 | 0:7798270c1f52 | 1339 | |
emh203 | 0:7798270c1f52 | 1340 | RenderContext BackBuffer; |
emh203 | 0:7798270c1f52 | 1341 | uint8_t BackBufferRenderPlaneSpace[PHYSICAL_DISPLAY_PLANE_BUFFER_SIZE]; |
emh203 | 0:7798270c1f52 | 1342 | |
emh203 | 0:7798270c1f52 | 1343 | int16_t GFX_Drawcharacter(RenderContext *Image, uint8_t character, int16_t StartX, int16_t StartY, GFXFont *MyFont); |
emh203 | 0:7798270c1f52 | 1344 | int16_t GFX_GetStringWidth(char * String,GFXFont * MyFont); |
emh203 | 0:7798270c1f52 | 1345 | |
emh203 | 0:7798270c1f52 | 1346 | //FontData |
emh203 | 0:7798270c1f52 | 1347 | |
emh203 | 0:7798270c1f52 | 1348 | #define FONT5x7_FONT_WIDTH 5 |
emh203 | 0:7798270c1f52 | 1349 | #define FONT5x7_FONT_HEIGHT 8 |
emh203 | 0:7798270c1f52 | 1350 | #define FONT5x7_FONT_ELEMENTS 128 |
emh203 | 0:7798270c1f52 | 1351 | #define FONT5x7_FONT_COLUMN_SIZE_IN_BYTE 1 |
emh203 | 0:7798270c1f52 | 1352 | |
emh203 | 0:7798270c1f52 | 1353 | uint8_t FontTable_Font5x7 [640] = { |
emh203 | 0:7798270c1f52 | 1354 | 0x00 ,0x08 ,0x0C ,0xFA ,0x81 ,0xFA ,0x0C ,0x08 ,0x00 ,0x00 ,0x00 ,0x10 ,0x30 ,0x5F ,0x81 ,0x5F , |
emh203 | 0:7798270c1f52 | 1355 | 0x30 ,0x10 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1356 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1357 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1358 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1359 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1360 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1361 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1362 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1363 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1364 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xBE ,0x00 ,0x00 ,0x00 ,0x00 ,0x06 ,0x00 ,0x06 ,0x00 ,0x00 ,0x28 , |
emh203 | 0:7798270c1f52 | 1365 | 0xFE ,0x28 ,0xFE ,0x28 ,0x48 ,0xFE ,0x54 ,0xFE ,0x24 ,0x06 ,0xE6 ,0x10 ,0xCE ,0xC0 ,0x60 ,0x92 , |
emh203 | 0:7798270c1f52 | 1366 | 0x94 ,0x78 ,0x10 ,0x06 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7C ,0x82 ,0x00 ,0x00 ,0x00 ,0x82 ,0x7C ,0x00 , |
emh203 | 0:7798270c1f52 | 1367 | 0x00 ,0x00 ,0x54 ,0x38 ,0xFE ,0x38 ,0x54 ,0x10 ,0x10 ,0x7C ,0x10 ,0x10 ,0x80 ,0x60 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1368 | 0x00 ,0x10 ,0x10 ,0x10 ,0x10 ,0x10 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0xC0 ,0x30 ,0x0C ,0x02 ,0x00 , |
emh203 | 0:7798270c1f52 | 1369 | 0x7C ,0xA2 ,0x92 ,0x8A ,0x7C ,0x88 ,0x84 ,0xFE ,0x80 ,0x80 ,0x84 ,0xC2 ,0xA2 ,0x92 ,0x8C ,0x44 , |
emh203 | 0:7798270c1f52 | 1370 | 0x92 ,0x92 ,0x92 ,0x6C ,0x10 ,0x18 ,0x14 ,0xFE ,0x10 ,0x4E ,0x8A ,0x8A ,0x8A ,0x72 ,0x7C ,0x92 , |
emh203 | 0:7798270c1f52 | 1371 | 0x92 ,0x92 ,0x64 ,0x02 ,0xC2 ,0x22 ,0x12 ,0x0E ,0x6C ,0x92 ,0x92 ,0x92 ,0x6C ,0x0C ,0x92 ,0x92 , |
emh203 | 0:7798270c1f52 | 1372 | 0x92 ,0x7C ,0x48 ,0x00 ,0x00 ,0x00 ,0x00 ,0x80 ,0x68 ,0x00 ,0x00 ,0x00 ,0x10 ,0x28 ,0x44 ,0x82 , |
emh203 | 0:7798270c1f52 | 1373 | 0x00 ,0x28 ,0x28 ,0x28 ,0x28 ,0x00 ,0x82 ,0x44 ,0x28 ,0x10 ,0x00 ,0x04 ,0x02 ,0xA2 ,0x12 ,0x0C , |
emh203 | 0:7798270c1f52 | 1374 | 0x3C ,0x42 ,0x9A ,0xA2 ,0x1C ,0xF8 ,0x14 ,0x12 ,0x14 ,0xF8 ,0xFE ,0x92 ,0x92 ,0x92 ,0x6C ,0x7C , |
emh203 | 0:7798270c1f52 | 1375 | 0x82 ,0x82 ,0x82 ,0x44 ,0xFE ,0x82 ,0x82 ,0x44 ,0x38 ,0xFE ,0x92 ,0x92 ,0x82 ,0x82 ,0xFE ,0x12 , |
emh203 | 0:7798270c1f52 | 1376 | 0x12 ,0x02 ,0x02 ,0x7C ,0x92 ,0x92 ,0x92 ,0x74 ,0xFE ,0x10 ,0x10 ,0x10 ,0xFE ,0x82 ,0x82 ,0xFE , |
emh203 | 0:7798270c1f52 | 1377 | 0x82 ,0x82 ,0x40 ,0x80 ,0x80 ,0x80 ,0x7E ,0xFE ,0x10 ,0x28 ,0x44 ,0x82 ,0xFE ,0x80 ,0x80 ,0x80 , |
emh203 | 0:7798270c1f52 | 1378 | 0x00 ,0xFE ,0x04 ,0x08 ,0x04 ,0xFE ,0xFE ,0x04 ,0x18 ,0x20 ,0xFE ,0x7C ,0x82 ,0x82 ,0x82 ,0x7C , |
emh203 | 0:7798270c1f52 | 1379 | 0xFE ,0x12 ,0x12 ,0x12 ,0x0C ,0x7C ,0x82 ,0xA2 ,0xC2 ,0xFC ,0xFE ,0x12 ,0x32 ,0x52 ,0x8C ,0x4C , |
emh203 | 0:7798270c1f52 | 1380 | 0x92 ,0x92 ,0x92 ,0x64 ,0x02 ,0x02 ,0xFE ,0x02 ,0x02 ,0x7E ,0x80 ,0x80 ,0x80 ,0x7E ,0x3E ,0x40 , |
emh203 | 0:7798270c1f52 | 1381 | 0x80 ,0x40 ,0x3E ,0xFE ,0x40 ,0x20 ,0x40 ,0xFE ,0xC6 ,0x28 ,0x10 ,0x28 ,0xC6 ,0x02 ,0x04 ,0xF8 , |
emh203 | 0:7798270c1f52 | 1382 | 0x04 ,0x02 ,0xC2 ,0xA2 ,0x92 ,0x8A ,0x86 ,0xFE ,0x82 ,0x82 ,0x00 ,0x00 ,0x02 ,0x0C ,0x30 ,0xC0 , |
emh203 | 0:7798270c1f52 | 1383 | 0x00 ,0x82 ,0x82 ,0xFE ,0x00 ,0x00 ,0x04 ,0x02 ,0x04 ,0x00 ,0x00 ,0x80 ,0x80 ,0x80 ,0x80 ,0x80 , |
emh203 | 0:7798270c1f52 | 1384 | 0x06 ,0x08 ,0x00 ,0x00 ,0x00 ,0x70 ,0x88 ,0x88 ,0x70 ,0x80 ,0xFC ,0x90 ,0x90 ,0x60 ,0x00 ,0x70 , |
emh203 | 0:7798270c1f52 | 1385 | 0x88 ,0x88 ,0x88 ,0x00 ,0x60 ,0x90 ,0x90 ,0x7C ,0x80 ,0x70 ,0xA8 ,0xA8 ,0x90 ,0x00 ,0x10 ,0xF8 , |
emh203 | 0:7798270c1f52 | 1386 | 0x14 ,0x04 ,0x00 ,0x98 ,0xA4 ,0xA4 ,0x78 ,0x00 ,0xFC ,0x20 ,0x10 ,0xE0 ,0x00 ,0xE8 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1387 | 0x00 ,0x00 ,0x40 ,0x80 ,0x80 ,0x74 ,0x00 ,0xFC ,0x20 ,0x50 ,0x88 ,0x00 ,0xFC ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1388 | 0x00 ,0xF0 ,0x08 ,0x30 ,0x08 ,0xF0 ,0xF8 ,0x08 ,0x08 ,0xF0 ,0x00 ,0x70 ,0x88 ,0x88 ,0x70 ,0x00 , |
emh203 | 0:7798270c1f52 | 1389 | 0xF8 ,0x24 ,0x24 ,0x18 ,0x00 ,0x18 ,0x24 ,0x24 ,0xF8 ,0x00 ,0xF0 ,0x08 ,0x08 ,0x10 ,0x00 ,0x90 , |
emh203 | 0:7798270c1f52 | 1390 | 0xA8 ,0xA8 ,0x48 ,0x00 ,0x08 ,0x7C ,0x88 ,0x00 ,0x00 ,0x78 ,0x80 ,0x80 ,0x78 ,0x00 ,0x38 ,0x40 , |
emh203 | 0:7798270c1f52 | 1391 | 0x80 ,0x40 ,0x38 ,0x78 ,0x80 ,0x40 ,0x80 ,0x78 ,0x88 ,0x50 ,0x20 ,0x50 ,0x88 ,0x08 ,0x10 ,0xE0 , |
emh203 | 0:7798270c1f52 | 1392 | 0x10 ,0x08 ,0xC8 ,0xA8 ,0x98 ,0x00 ,0x00 ,0x10 ,0x6C ,0x82 ,0x00 ,0x00 ,0xFE ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1393 | 0x00 ,0x82 ,0x6C ,0x10 ,0x00 ,0x00 ,0x08 ,0x04 ,0x08 ,0x10 ,0x08 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; |
emh203 | 0:7798270c1f52 | 1394 | |
emh203 | 0:7798270c1f52 | 1395 | uint8_t CharacterWidthTable_Font5x7 [128] = { |
emh203 | 0:7798270c1f52 | 1396 | 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 , |
emh203 | 0:7798270c1f52 | 1397 | 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 , |
emh203 | 0:7798270c1f52 | 1398 | 0x05 ,0x01 ,0x03 ,0x05 ,0x05 ,0x05 ,0x05 ,0x01 ,0x02 ,0x02 ,0x05 ,0x05 ,0x02 ,0x05 ,0x01 ,0x04 , |
emh203 | 0:7798270c1f52 | 1399 | 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x01 ,0x01 ,0x04 ,0x04 ,0x04 ,0x05 , |
emh203 | 0:7798270c1f52 | 1400 | 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x04 ,0x05 ,0x05 ,0x05 , |
emh203 | 0:7798270c1f52 | 1401 | 0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x05 ,0x03 ,0x04 ,0x05 ,0x03 ,0x05 , |
emh203 | 0:7798270c1f52 | 1402 | 0x02 ,0x05 ,0x04 ,0x04 ,0x05 ,0x04 ,0x04 ,0x04 ,0x04 ,0x01 ,0x04 ,0x04 ,0x01 ,0x05 ,0x04 ,0x05 , |
emh203 | 0:7798270c1f52 | 1403 | 0x05 ,0x05 ,0x04 ,0x04 ,0x03 ,0x04 ,0x05 ,0x05 ,0x05 ,0x05 ,0x03 ,0x03 ,0x01 ,0x05 ,0x05 ,0x05 }; |
emh203 | 0:7798270c1f52 | 1404 | |
emh203 | 0:7798270c1f52 | 1405 | #define FONT3x5_FONT_WIDTH 3 |
emh203 | 0:7798270c1f52 | 1406 | #define FONT3x5_FONT_HEIGHT 5 |
emh203 | 0:7798270c1f52 | 1407 | #define FONT3x5_ELEMENTS 128 |
emh203 | 0:7798270c1f52 | 1408 | #define FONT3x5_FONT_COLUMN_SIZE_IN_BYTE 1 |
emh203 | 0:7798270c1f52 | 1409 | |
emh203 | 0:7798270c1f52 | 1410 | |
emh203 | 0:7798270c1f52 | 1411 | uint8_t FontTable_Font3x5 [384] = { |
emh203 | 0:7798270c1f52 | 1412 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1413 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1414 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1415 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1416 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1417 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , |
emh203 | 0:7798270c1f52 | 1418 | 0x00 ,0x00 ,0x00 ,0x17 ,0x00 ,0x00 ,0x03 ,0x00 ,0x03 ,0x0E ,0x1F ,0x0E ,0x14 ,0x1F ,0x0A ,0x00 , |
emh203 | 0:7798270c1f52 | 1419 | 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x00 ,0x00 ,0x0E ,0x11 ,0x00 ,0x11 ,0x0E ,0x00 ,0x15 ,0x0E , |
emh203 | 0:7798270c1f52 | 1420 | 0x15 ,0x04 ,0x0E ,0x04 ,0x10 ,0x08 ,0x00 ,0x04 ,0x04 ,0x04 ,0x10 ,0x00 ,0x00 ,0x18 ,0x04 ,0x03 , |
emh203 | 0:7798270c1f52 | 1421 | 0x0E ,0x11 ,0x0E ,0x12 ,0x1F ,0x10 ,0x19 ,0x15 ,0x16 ,0x11 ,0x15 ,0x0A ,0x07 ,0x04 ,0x1F ,0x17 , |
emh203 | 0:7798270c1f52 | 1422 | 0x15 ,0x09 ,0x1E ,0x15 ,0x18 ,0x01 ,0x1D ,0x03 ,0x1B ,0x15 ,0x1B ,0x06 ,0x15 ,0x0E ,0x0A ,0x00 , |
emh203 | 0:7798270c1f52 | 1423 | 0x00 ,0x10 ,0x0A ,0x00 ,0x04 ,0x0A ,0x11 ,0x00 ,0x00 ,0x00 ,0x11 ,0x0A ,0x04 ,0x01 ,0x15 ,0x02 , |
emh203 | 0:7798270c1f52 | 1424 | 0x09 ,0x15 ,0x0E ,0x1E ,0x05 ,0x1E ,0x1F ,0x15 ,0x0A ,0x0E ,0x11 ,0x0A ,0x1F ,0x11 ,0x0E ,0x1F , |
emh203 | 0:7798270c1f52 | 1425 | 0x15 ,0x11 ,0x1F ,0x05 ,0x05 ,0x1E ,0x15 ,0x1D ,0x1F ,0x04 ,0x1F ,0x11 ,0x1F ,0x11 ,0x08 ,0x10 , |
emh203 | 0:7798270c1f52 | 1426 | 0x0F ,0x1F ,0x06 ,0x19 ,0x1F ,0x10 ,0x10 ,0x1F ,0x02 ,0x1F ,0x1F ,0x06 ,0x1F ,0x1F ,0x11 ,0x1F , |
emh203 | 0:7798270c1f52 | 1427 | 0x1F ,0x05 ,0x07 ,0x1F ,0x19 ,0x1F ,0x1F ,0x0D ,0x16 ,0x16 ,0x15 ,0x1D ,0x01 ,0x1F ,0x01 ,0x1F , |
emh203 | 0:7798270c1f52 | 1428 | 0x10 ,0x1F ,0x0F ,0x10 ,0x0F ,0x1F ,0x08 ,0x1F ,0x1B ,0x04 ,0x1B ,0x01 ,0x1E ,0x01 ,0x19 ,0x15 , |
emh203 | 0:7798270c1f52 | 1429 | 0x13 ,0x1F ,0x11 ,0x00 ,0x03 ,0x0C ,0x10 ,0x11 ,0x1F ,0x00 ,0x02 ,0x01 ,0x02 ,0x10 ,0x10 ,0x10 , |
emh203 | 0:7798270c1f52 | 1430 | 0x01 ,0x02 ,0x00 ,0x08 ,0x14 ,0x1C ,0x1F ,0x14 ,0x08 ,0x0C ,0x12 ,0x12 ,0x08 ,0x14 ,0x1F ,0x0C , |
emh203 | 0:7798270c1f52 | 1431 | 0x16 ,0x16 ,0x14 ,0x0E ,0x05 ,0x06 ,0x15 ,0x0F ,0x1F ,0x04 ,0x18 ,0x1D ,0x00 ,0x00 ,0x10 ,0x0D , |
emh203 | 0:7798270c1f52 | 1432 | 0x00 ,0x1F ,0x0C ,0x12 ,0x1F ,0x00 ,0x00 ,0x1C ,0x08 ,0x1C ,0x1C ,0x02 ,0x1C ,0x0C ,0x12 ,0x0C , |
emh203 | 0:7798270c1f52 | 1433 | 0x1E ,0x05 ,0x02 ,0x02 ,0x05 ,0x1E ,0x1C ,0x02 ,0x04 ,0x14 ,0x1A ,0x00 ,0x04 ,0x1E ,0x04 ,0x1E , |
emh203 | 0:7798270c1f52 | 1434 | 0x10 ,0x1E ,0x0E ,0x10 ,0x0E ,0x1C ,0x08 ,0x1C ,0x12 ,0x0C ,0x12 ,0x12 ,0x0C ,0x02 ,0x12 ,0x1A , |
emh203 | 0:7798270c1f52 | 1435 | 0x16 ,0x04 ,0x0E ,0x11 ,0x1F ,0x00 ,0x00 ,0x11 ,0x0E ,0x04 ,0x02 ,0x02 ,0x04 ,0x00 ,0x00 ,0x00 }; |
emh203 | 0:7798270c1f52 | 1436 | |
emh203 | 0:7798270c1f52 | 1437 | |
emh203 | 0:7798270c1f52 | 1438 | uint8_t CharacterWidthTable_Font3x5 [128] = { |
emh203 | 0:7798270c1f52 | 1439 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1440 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1441 | 0x03 ,0x01 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x02 ,0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x01 ,0x03 , |
emh203 | 0:7798270c1f52 | 1442 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1443 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1444 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x02 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1445 | 0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x03 , |
emh203 | 0:7798270c1f52 | 1446 | 0x03 ,0x03 ,0x03 ,0x02 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x03 ,0x01 ,0x03 ,0x03 ,0x03 }; |
emh203 | 0:7798270c1f52 | 1447 | |
emh203 | 0:7798270c1f52 | 1448 | GFXFont Font5x7; |
emh203 | 0:7798270c1f52 | 1449 | GFXFont Font3x5; |
emh203 | 0:7798270c1f52 | 1450 | |
emh203 | 0:7798270c1f52 | 1451 | void GFX_Init() |
emh203 | 0:7798270c1f52 | 1452 | { |
emh203 | 0:7798270c1f52 | 1453 | |
emh203 | 0:7798270c1f52 | 1454 | //Staticially Allocate and setup the backbuffer space; |
emh203 | 0:7798270c1f52 | 1455 | |
emh203 | 0:7798270c1f52 | 1456 | BackBuffer.RenderPlane.BitPlaneSpace = &BackBufferRenderPlaneSpace[0]; |
emh203 | 0:7798270c1f52 | 1457 | |
emh203 | 0:7798270c1f52 | 1458 | BackBuffer.SizeX = BACK_BUFFER_SIZE_X; |
emh203 | 0:7798270c1f52 | 1459 | BackBuffer.SizeY = BACK_BUFFER_SIZE_Y; |
emh203 | 0:7798270c1f52 | 1460 | |
emh203 | 0:7798270c1f52 | 1461 | BackBuffer.RenderPlane.SizeX = BACK_BUFFER_SIZE_X; |
emh203 | 0:7798270c1f52 | 1462 | BackBuffer.RenderPlane.SizeY = BACK_BUFFER_SIZE_Y; |
emh203 | 0:7798270c1f52 | 1463 | |
emh203 | 0:7798270c1f52 | 1464 | |
emh203 | 0:7798270c1f52 | 1465 | GFX_FullDisplayBufferClear(&BackBuffer); |
emh203 | 0:7798270c1f52 | 1466 | |
emh203 | 0:7798270c1f52 | 1467 | //Initialize the stock fonts |
emh203 | 0:7798270c1f52 | 1468 | |
emh203 | 0:7798270c1f52 | 1469 | Font5x7.CharacterWidthTable = (uint8_t *)CharacterWidthTable_Font5x7; |
emh203 | 0:7798270c1f52 | 1470 | Font5x7.FontBuffer = (uint8_t *)FontTable_Font5x7; |
emh203 | 0:7798270c1f52 | 1471 | Font5x7.FontHeight = FONT5x7_FONT_HEIGHT; |
emh203 | 0:7798270c1f52 | 1472 | Font5x7.FontWidth = FONT5x7_FONT_WIDTH; |
emh203 | 0:7798270c1f52 | 1473 | Font5x7.BytesPerColumn = FONT5x7_FONT_COLUMN_SIZE_IN_BYTE; |
emh203 | 0:7798270c1f52 | 1474 | |
emh203 | 0:7798270c1f52 | 1475 | Font3x5.CharacterWidthTable = (uint8_t *)CharacterWidthTable_Font3x5; |
emh203 | 0:7798270c1f52 | 1476 | Font3x5.FontBuffer = (uint8_t *)FontTable_Font3x5; |
emh203 | 0:7798270c1f52 | 1477 | Font3x5.FontHeight = FONT3x5_FONT_HEIGHT; |
emh203 | 0:7798270c1f52 | 1478 | Font3x5.FontWidth = FONT3x5_FONT_WIDTH; |
emh203 | 0:7798270c1f52 | 1479 | Font3x5.BytesPerColumn = FONT3x5_FONT_COLUMN_SIZE_IN_BYTE; |
emh203 | 0:7798270c1f52 | 1480 | |
emh203 | 0:7798270c1f52 | 1481 | GFX_InitPhysicalScreen(); |
emh203 | 0:7798270c1f52 | 1482 | |
emh203 | 0:7798270c1f52 | 1483 | } |
emh203 | 0:7798270c1f52 | 1484 | |
emh203 | 0:7798270c1f52 | 1485 | |
emh203 | 0:7798270c1f52 | 1486 | |
emh203 | 0:7798270c1f52 | 1487 | void GFX_FullDisplayBufferClear(RenderContext *Image) |
emh203 | 0:7798270c1f52 | 1488 | { |
emh203 | 0:7798270c1f52 | 1489 | BitPlane_Clear(&Image->RenderPlane); |
emh203 | 0:7798270c1f52 | 1490 | } |
emh203 | 0:7798270c1f52 | 1491 | |
emh203 | 0:7798270c1f52 | 1492 | |
emh203 | 0:7798270c1f52 | 1493 | void GFX_PutPixel(RenderContext *Image, int16_t x, int16_t y) |
emh203 | 0:7798270c1f52 | 1494 | { |
emh203 | 0:7798270c1f52 | 1495 | if((x<Image->SizeX) && (y<Image->SizeY) && (x>=0) && (y>=0)) |
emh203 | 0:7798270c1f52 | 1496 | { |
emh203 | 0:7798270c1f52 | 1497 | BitPlane_Put(&Image->RenderPlane,Image->SizeX-x-1,Image->SizeY-y-1,TRUE); |
emh203 | 0:7798270c1f52 | 1498 | } |
emh203 | 0:7798270c1f52 | 1499 | } |
emh203 | 0:7798270c1f52 | 1500 | |
emh203 | 0:7798270c1f52 | 1501 | |
emh203 | 0:7798270c1f52 | 1502 | |
emh203 | 0:7798270c1f52 | 1503 | #ifndef _INLINE_GFX_GET_PIXEL |
emh203 | 0:7798270c1f52 | 1504 | uint8_t GFX_GetPixel(RenderContext *Image, int16_t x, int16_t y) |
emh203 | 0:7798270c1f52 | 1505 | { |
emh203 | 0:7798270c1f52 | 1506 | uint8_t PixelColor = 0; |
emh203 | 0:7798270c1f52 | 1507 | |
emh203 | 0:7798270c1f52 | 1508 | if((x<Image->SizeX) && (y<Image->SizeY) && (x>=0) && (y>=0)) |
emh203 | 0:7798270c1f52 | 1509 | { |
emh203 | 0:7798270c1f52 | 1510 | |
emh203 | 0:7798270c1f52 | 1511 | PixelColor = BitPlane_Get(&Image->RenderPlane,x,y); |
emh203 | 0:7798270c1f52 | 1512 | } |
emh203 | 0:7798270c1f52 | 1513 | |
emh203 | 0:7798270c1f52 | 1514 | return PixelColor; |
emh203 | 0:7798270c1f52 | 1515 | } |
emh203 | 0:7798270c1f52 | 1516 | #endif |
emh203 | 0:7798270c1f52 | 1517 | |
emh203 | 0:7798270c1f52 | 1518 | |
emh203 | 0:7798270c1f52 | 1519 | void GFX_DrawHline(RenderContext *Image, int16_t XStart, int16_t XStop, int16_t Y) |
emh203 | 0:7798270c1f52 | 1520 | { |
emh203 | 0:7798270c1f52 | 1521 | int16_t LineStart; |
emh203 | 0:7798270c1f52 | 1522 | int16_t LineStop; |
emh203 | 0:7798270c1f52 | 1523 | uint16_t i; |
emh203 | 0:7798270c1f52 | 1524 | |
emh203 | 0:7798270c1f52 | 1525 | if((Y<Image->SizeY) && (Y>=0)) |
emh203 | 0:7798270c1f52 | 1526 | { |
emh203 | 0:7798270c1f52 | 1527 | if(XStart>XStop) |
emh203 | 0:7798270c1f52 | 1528 | { |
emh203 | 0:7798270c1f52 | 1529 | LineStart = XStop; |
emh203 | 0:7798270c1f52 | 1530 | LineStop = XStart; |
emh203 | 0:7798270c1f52 | 1531 | } |
emh203 | 0:7798270c1f52 | 1532 | else |
emh203 | 0:7798270c1f52 | 1533 | { |
emh203 | 0:7798270c1f52 | 1534 | LineStart = XStart; |
emh203 | 0:7798270c1f52 | 1535 | LineStop = XStop; |
emh203 | 0:7798270c1f52 | 1536 | } |
emh203 | 0:7798270c1f52 | 1537 | |
emh203 | 0:7798270c1f52 | 1538 | if(LineStart<0) |
emh203 | 0:7798270c1f52 | 1539 | { |
emh203 | 0:7798270c1f52 | 1540 | LineStart = 0; |
emh203 | 0:7798270c1f52 | 1541 | } |
emh203 | 0:7798270c1f52 | 1542 | |
emh203 | 0:7798270c1f52 | 1543 | if(LineStop>Image->SizeX) |
emh203 | 0:7798270c1f52 | 1544 | { |
emh203 | 0:7798270c1f52 | 1545 | LineStop = Image->SizeX-1; |
emh203 | 0:7798270c1f52 | 1546 | } |
emh203 | 0:7798270c1f52 | 1547 | |
emh203 | 0:7798270c1f52 | 1548 | if(LineStart == LineStop) |
emh203 | 0:7798270c1f52 | 1549 | { |
emh203 | 0:7798270c1f52 | 1550 | GFX_PutPixel(Image,LineStart,Y); |
emh203 | 0:7798270c1f52 | 1551 | } |
emh203 | 0:7798270c1f52 | 1552 | else |
emh203 | 0:7798270c1f52 | 1553 | { |
emh203 | 0:7798270c1f52 | 1554 | for(i=LineStart; i<=LineStop ; i++) |
emh203 | 0:7798270c1f52 | 1555 | { |
emh203 | 0:7798270c1f52 | 1556 | GFX_PutPixel(Image,i,Y); |
emh203 | 0:7798270c1f52 | 1557 | } |
emh203 | 0:7798270c1f52 | 1558 | } |
emh203 | 0:7798270c1f52 | 1559 | } |
emh203 | 0:7798270c1f52 | 1560 | |
emh203 | 0:7798270c1f52 | 1561 | } |
emh203 | 0:7798270c1f52 | 1562 | |
emh203 | 0:7798270c1f52 | 1563 | |
emh203 | 0:7798270c1f52 | 1564 | |
emh203 | 0:7798270c1f52 | 1565 | void GFX_DrawVline(RenderContext *Image, int16_t YStart, int16_t YStop, int16_t X) |
emh203 | 0:7798270c1f52 | 1566 | { |
emh203 | 0:7798270c1f52 | 1567 | int16_t LineStart; |
emh203 | 0:7798270c1f52 | 1568 | int16_t LineStop; |
emh203 | 0:7798270c1f52 | 1569 | int16_t i; |
emh203 | 0:7798270c1f52 | 1570 | |
emh203 | 0:7798270c1f52 | 1571 | if((X<Image->SizeX) && (X>=0)) |
emh203 | 0:7798270c1f52 | 1572 | { |
emh203 | 0:7798270c1f52 | 1573 | |
emh203 | 0:7798270c1f52 | 1574 | if(YStart>YStop) |
emh203 | 0:7798270c1f52 | 1575 | { |
emh203 | 0:7798270c1f52 | 1576 | LineStart = YStop; |
emh203 | 0:7798270c1f52 | 1577 | LineStop = YStart; |
emh203 | 0:7798270c1f52 | 1578 | } |
emh203 | 0:7798270c1f52 | 1579 | else |
emh203 | 0:7798270c1f52 | 1580 | { |
emh203 | 0:7798270c1f52 | 1581 | LineStart = YStart; |
emh203 | 0:7798270c1f52 | 1582 | LineStop = YStop; |
emh203 | 0:7798270c1f52 | 1583 | } |
emh203 | 0:7798270c1f52 | 1584 | |
emh203 | 0:7798270c1f52 | 1585 | if(LineStart<0) |
emh203 | 0:7798270c1f52 | 1586 | { |
emh203 | 0:7798270c1f52 | 1587 | LineStart = 0; |
emh203 | 0:7798270c1f52 | 1588 | } |
emh203 | 0:7798270c1f52 | 1589 | |
emh203 | 0:7798270c1f52 | 1590 | |
emh203 | 0:7798270c1f52 | 1591 | if(LineStop>Image->SizeY) |
emh203 | 0:7798270c1f52 | 1592 | { |
emh203 | 0:7798270c1f52 | 1593 | LineStop = Image->SizeY-1; |
emh203 | 0:7798270c1f52 | 1594 | } |
emh203 | 0:7798270c1f52 | 1595 | |
emh203 | 0:7798270c1f52 | 1596 | for(i=LineStart; i<=LineStop ; i++) |
emh203 | 0:7798270c1f52 | 1597 | { |
emh203 | 0:7798270c1f52 | 1598 | GFX_PutPixel(Image,X,i); |
emh203 | 0:7798270c1f52 | 1599 | } |
emh203 | 0:7798270c1f52 | 1600 | } |
emh203 | 0:7798270c1f52 | 1601 | } |
emh203 | 0:7798270c1f52 | 1602 | |
emh203 | 0:7798270c1f52 | 1603 | |
emh203 | 0:7798270c1f52 | 1604 | void GFX_DrawLine(RenderContext * Image, int16_t X1,int16_t Y1, int16_t X2,int16_t Y2) |
emh203 | 0:7798270c1f52 | 1605 | { |
emh203 | 0:7798270c1f52 | 1606 | //A simple Implementation of Bresenham's line Algorithm |
emh203 | 0:7798270c1f52 | 1607 | int16_t StartX,StopX,StartY,StopY; |
emh203 | 0:7798270c1f52 | 1608 | int16_t dX,dY; |
emh203 | 0:7798270c1f52 | 1609 | int16_t Y_Numerator; |
emh203 | 0:7798270c1f52 | 1610 | int16_t X_Numerator; |
emh203 | 0:7798270c1f52 | 1611 | int16_t Y; |
emh203 | 0:7798270c1f52 | 1612 | int16_t X; |
emh203 | 0:7798270c1f52 | 1613 | int16_t i; |
emh203 | 0:7798270c1f52 | 1614 | uint8_t YDir = 0; |
emh203 | 0:7798270c1f52 | 1615 | //First Make sure that it is left to right |
emh203 | 0:7798270c1f52 | 1616 | //If not them flop them |
emh203 | 0:7798270c1f52 | 1617 | if(X2>X1) |
emh203 | 0:7798270c1f52 | 1618 | { |
emh203 | 0:7798270c1f52 | 1619 | StartX = X1; |
emh203 | 0:7798270c1f52 | 1620 | StopX = X2; |
emh203 | 0:7798270c1f52 | 1621 | StartY = Y1; |
emh203 | 0:7798270c1f52 | 1622 | StopY = Y2; |
emh203 | 0:7798270c1f52 | 1623 | } |
emh203 | 0:7798270c1f52 | 1624 | else |
emh203 | 0:7798270c1f52 | 1625 | { |
emh203 | 0:7798270c1f52 | 1626 | StartX = X2; |
emh203 | 0:7798270c1f52 | 1627 | StopX = X1; |
emh203 | 0:7798270c1f52 | 1628 | StartY = Y2; |
emh203 | 0:7798270c1f52 | 1629 | StopY = Y1; |
emh203 | 0:7798270c1f52 | 1630 | } |
emh203 | 0:7798270c1f52 | 1631 | GFX_PutPixel(Image, StopX,StopY); |
emh203 | 0:7798270c1f52 | 1632 | if(StopY>=StartY) |
emh203 | 0:7798270c1f52 | 1633 | { |
emh203 | 0:7798270c1f52 | 1634 | dY = StopY - StartY; |
emh203 | 0:7798270c1f52 | 1635 | YDir = 0; |
emh203 | 0:7798270c1f52 | 1636 | } |
emh203 | 0:7798270c1f52 | 1637 | else |
emh203 | 0:7798270c1f52 | 1638 | { |
emh203 | 0:7798270c1f52 | 1639 | dY = StartY - StopY; |
emh203 | 0:7798270c1f52 | 1640 | YDir = 1; |
emh203 | 0:7798270c1f52 | 1641 | } |
emh203 | 0:7798270c1f52 | 1642 | dX = StopX - StartX; |
emh203 | 0:7798270c1f52 | 1643 | //Now, if the slope is less greater than one, we need to swap all X/Y operations |
emh203 | 0:7798270c1f52 | 1644 | if(dY<=dX) |
emh203 | 0:7798270c1f52 | 1645 | { |
emh203 | 0:7798270c1f52 | 1646 | //Slope is less than one, proceed at normal and step along the x axis |
emh203 | 0:7798270c1f52 | 1647 | Y=StartY; //start the whole part of the Y value at the starting pixeel. |
emh203 | 0:7798270c1f52 | 1648 | X=StartX; |
emh203 | 0:7798270c1f52 | 1649 | //We need to start the numerator of the fraction half way through the fraction so evertyhing rounds at |
emh203 | 0:7798270c1f52 | 1650 | //fraction midpoint |
emh203 | 0:7798270c1f52 | 1651 | Y_Numerator = dX>>1; //The fraction demonimator is assumeed to be dX |
emh203 | 0:7798270c1f52 | 1652 | // out fixed point Y value is Y + (Y_Numerator / dX) |
emh203 | 0:7798270c1f52 | 1653 | //Every time we step the X coordinate by one, we need to step |
emh203 | 0:7798270c1f52 | 1654 | //out Y coordinate by dY/dX. We do this by just adding dY to our |
emh203 | 0:7798270c1f52 | 1655 | //numerator. When the numerator gets bigger than the |
emh203 | 0:7798270c1f52 | 1656 | //denomiator, the increment the whole part by one and decrement the numerator |
emh203 | 0:7798270c1f52 | 1657 | //by the denominator |
emh203 | 0:7798270c1f52 | 1658 | for(i=0;i<dX;i++) |
emh203 | 0:7798270c1f52 | 1659 | { |
emh203 | 0:7798270c1f52 | 1660 | GFX_PutPixel(Image,X,Y); |
emh203 | 0:7798270c1f52 | 1661 | X++; |
emh203 | 0:7798270c1f52 | 1662 | //Now do all the fractional stuff |
emh203 | 0:7798270c1f52 | 1663 | Y_Numerator += dY; |
emh203 | 0:7798270c1f52 | 1664 | if(Y_Numerator >= dX) |
emh203 | 0:7798270c1f52 | 1665 | { |
emh203 | 0:7798270c1f52 | 1666 | Y_Numerator-=dX; |
emh203 | 0:7798270c1f52 | 1667 | if(StopY > StartY) |
emh203 | 0:7798270c1f52 | 1668 | { |
emh203 | 0:7798270c1f52 | 1669 | Y++; |
emh203 | 0:7798270c1f52 | 1670 | } |
emh203 | 0:7798270c1f52 | 1671 | else |
emh203 | 0:7798270c1f52 | 1672 | { |
emh203 | 0:7798270c1f52 | 1673 | Y--; |
emh203 | 0:7798270c1f52 | 1674 | } |
emh203 | 0:7798270c1f52 | 1675 | } |
emh203 | 0:7798270c1f52 | 1676 | } |
emh203 | 0:7798270c1f52 | 1677 | } |
emh203 | 0:7798270c1f52 | 1678 | else |
emh203 | 0:7798270c1f52 | 1679 | { |
emh203 | 0:7798270c1f52 | 1680 | //Same as before by step along the y axis. |
emh203 | 0:7798270c1f52 | 1681 | Y=StartY; |
emh203 | 0:7798270c1f52 | 1682 | X=StartX; |
emh203 | 0:7798270c1f52 | 1683 | X_Numerator = dY>>1; |
emh203 | 0:7798270c1f52 | 1684 | for(i=0;i<dY;i++) |
emh203 | 0:7798270c1f52 | 1685 | { |
emh203 | 0:7798270c1f52 | 1686 | GFX_PutPixel(Image,X,Y); |
emh203 | 0:7798270c1f52 | 1687 | //Now do all the fractional stuff |
emh203 | 0:7798270c1f52 | 1688 | if(YDir) |
emh203 | 0:7798270c1f52 | 1689 | { |
emh203 | 0:7798270c1f52 | 1690 | Y--; |
emh203 | 0:7798270c1f52 | 1691 | } |
emh203 | 0:7798270c1f52 | 1692 | else |
emh203 | 0:7798270c1f52 | 1693 | { |
emh203 | 0:7798270c1f52 | 1694 | Y++; |
emh203 | 0:7798270c1f52 | 1695 | } |
emh203 | 0:7798270c1f52 | 1696 | X_Numerator += dX; |
emh203 | 0:7798270c1f52 | 1697 | if(X_Numerator >= dY) |
emh203 | 0:7798270c1f52 | 1698 | { |
emh203 | 0:7798270c1f52 | 1699 | X_Numerator-=dY; |
emh203 | 0:7798270c1f52 | 1700 | if(StopX > StartX) |
emh203 | 0:7798270c1f52 | 1701 | { |
emh203 | 0:7798270c1f52 | 1702 | X++; |
emh203 | 0:7798270c1f52 | 1703 | } |
emh203 | 0:7798270c1f52 | 1704 | else |
emh203 | 0:7798270c1f52 | 1705 | { |
emh203 | 0:7798270c1f52 | 1706 | X--; |
emh203 | 0:7798270c1f52 | 1707 | } |
emh203 | 0:7798270c1f52 | 1708 | } |
emh203 | 0:7798270c1f52 | 1709 | } |
emh203 | 0:7798270c1f52 | 1710 | } |
emh203 | 0:7798270c1f52 | 1711 | } |
emh203 | 0:7798270c1f52 | 1712 | |
emh203 | 0:7798270c1f52 | 1713 | void GFX_DrawBox(RenderContext *Image, GFXDisplayBox *Box) |
emh203 | 0:7798270c1f52 | 1714 | { |
emh203 | 0:7798270c1f52 | 1715 | GFX_DrawHline(Image,Box->P1.X,Box->P2.X,Box->P1.Y); |
emh203 | 0:7798270c1f52 | 1716 | GFX_DrawHline(Image,Box->P1.X,Box->P2.X,Box->P2.Y); |
emh203 | 0:7798270c1f52 | 1717 | GFX_DrawVline(Image,Box->P1.Y,Box->P2.Y,Box->P1.X); |
emh203 | 0:7798270c1f52 | 1718 | GFX_DrawVline(Image,Box->P1.Y,Box->P2.Y,Box->P2.X); |
emh203 | 0:7798270c1f52 | 1719 | } |
emh203 | 0:7798270c1f52 | 1720 | |
emh203 | 0:7798270c1f52 | 1721 | int16_t GFX_DrawCharacter(RenderContext * Image,uint8_t Character,int16_t StartX, int16_t StartY, GFXFont * MyFont) |
emh203 | 0:7798270c1f52 | 1722 | { |
emh203 | 0:7798270c1f52 | 1723 | uint8_t i,j,Mask; |
emh203 | 0:7798270c1f52 | 1724 | uint16_t CharStartIndex,ColumnStartIndex,ByteOffset; |
emh203 | 0:7798270c1f52 | 1725 | |
emh203 | 0:7798270c1f52 | 1726 | CharStartIndex = (Character * (MyFont->BytesPerColumn) * (MyFont->FontWidth)); |
emh203 | 0:7798270c1f52 | 1727 | |
emh203 | 0:7798270c1f52 | 1728 | for(j=0;j<MyFont->CharacterWidthTable[Character];j++) |
emh203 | 0:7798270c1f52 | 1729 | { |
emh203 | 0:7798270c1f52 | 1730 | //Draw the current slice |
emh203 | 0:7798270c1f52 | 1731 | ColumnStartIndex = j* (MyFont->BytesPerColumn); |
emh203 | 0:7798270c1f52 | 1732 | |
emh203 | 0:7798270c1f52 | 1733 | for(i=0;i<MyFont->FontHeight;i++) |
emh203 | 0:7798270c1f52 | 1734 | { |
emh203 | 0:7798270c1f52 | 1735 | ByteOffset = i>>3; |
emh203 | 0:7798270c1f52 | 1736 | Mask = 0x01 << (i&0x07); |
emh203 | 0:7798270c1f52 | 1737 | |
emh203 | 0:7798270c1f52 | 1738 | if( (MyFont->FontBuffer[CharStartIndex + ColumnStartIndex + ByteOffset]) & Mask) |
emh203 | 0:7798270c1f52 | 1739 | { |
emh203 | 0:7798270c1f52 | 1740 | GFX_PutPixel(Image, StartX, StartY + i); |
emh203 | 0:7798270c1f52 | 1741 | } |
emh203 | 0:7798270c1f52 | 1742 | } |
emh203 | 0:7798270c1f52 | 1743 | StartX++; |
emh203 | 0:7798270c1f52 | 1744 | } |
emh203 | 0:7798270c1f52 | 1745 | return StartX; |
emh203 | 0:7798270c1f52 | 1746 | } |
emh203 | 0:7798270c1f52 | 1747 | |
emh203 | 0:7798270c1f52 | 1748 | |
emh203 | 0:7798270c1f52 | 1749 | int16_t GFX_GetStringWidth(char * String,GFXFont * MyFont) |
emh203 | 0:7798270c1f52 | 1750 | { |
emh203 | 0:7798270c1f52 | 1751 | uint8_t Ptr = 0; |
emh203 | 0:7798270c1f52 | 1752 | uint8_t NextChar; |
emh203 | 0:7798270c1f52 | 1753 | int16_t StringSize = 0; |
emh203 | 0:7798270c1f52 | 1754 | |
emh203 | 0:7798270c1f52 | 1755 | NextChar = String[Ptr]; |
emh203 | 0:7798270c1f52 | 1756 | Ptr++; |
emh203 | 0:7798270c1f52 | 1757 | |
emh203 | 0:7798270c1f52 | 1758 | while((NextChar!=0) && (Ptr <GFX_MAX_STRING_LEN)) |
emh203 | 0:7798270c1f52 | 1759 | { |
emh203 | 0:7798270c1f52 | 1760 | StringSize += MyFont->CharacterWidthTable[NextChar] + 1; |
emh203 | 0:7798270c1f52 | 1761 | NextChar = String[Ptr]; |
emh203 | 0:7798270c1f52 | 1762 | Ptr++; |
emh203 | 0:7798270c1f52 | 1763 | } |
emh203 | 0:7798270c1f52 | 1764 | |
emh203 | 0:7798270c1f52 | 1765 | return StringSize; |
emh203 | 0:7798270c1f52 | 1766 | } |
emh203 | 0:7798270c1f52 | 1767 | |
emh203 | 0:7798270c1f52 | 1768 | void GFX_DrawCenteredString(RenderContext * Image,char * String,int16_t StartX, int16_t StartY, GFXFont * MyFont) |
emh203 | 0:7798270c1f52 | 1769 | { |
emh203 | 0:7798270c1f52 | 1770 | StartX -= (GFX_GetStringWidth(String,MyFont)>>1); |
emh203 | 0:7798270c1f52 | 1771 | GFX_DrawString(Image,String,StartX,StartY,MyFont); |
emh203 | 0:7798270c1f52 | 1772 | } |
emh203 | 0:7798270c1f52 | 1773 | |
emh203 | 0:7798270c1f52 | 1774 | void GFX_DrawString(RenderContext * Image,char * String,int16_t StartX, int16_t StartY, GFXFont * MyFont) |
emh203 | 0:7798270c1f52 | 1775 | { |
emh203 | 0:7798270c1f52 | 1776 | |
emh203 | 0:7798270c1f52 | 1777 | uint8_t Ptr = 0; |
emh203 | 0:7798270c1f52 | 1778 | uint8_t NextChar; |
emh203 | 0:7798270c1f52 | 1779 | |
emh203 | 0:7798270c1f52 | 1780 | NextChar = String[Ptr]; |
emh203 | 0:7798270c1f52 | 1781 | |
emh203 | 0:7798270c1f52 | 1782 | while((NextChar!=0) && (Ptr <GFX_MAX_STRING_LEN)) |
emh203 | 0:7798270c1f52 | 1783 | { |
emh203 | 0:7798270c1f52 | 1784 | StartX = GFX_DrawCharacter(Image,NextChar,StartX,StartY,MyFont); |
emh203 | 0:7798270c1f52 | 1785 | Ptr++; |
emh203 | 0:7798270c1f52 | 1786 | NextChar = String[Ptr]; |
emh203 | 0:7798270c1f52 | 1787 | StartX++; |
emh203 | 0:7798270c1f52 | 1788 | } |
emh203 | 0:7798270c1f52 | 1789 | |
emh203 | 0:7798270c1f52 | 1790 | } |
emh203 | 0:7798270c1f52 | 1791 | |
emh203 | 0:7798270c1f52 | 1792 | char GFXStringBuf[64]; |
emh203 | 0:7798270c1f52 | 1793 | |
emh203 | 0:7798270c1f52 | 1794 | void GFX_printf(RenderContext * Image,int16_t StartX, int16_t StartY, GFXFont * MyFont, const char *FormatString,...) |
emh203 | 0:7798270c1f52 | 1795 | { |
emh203 | 0:7798270c1f52 | 1796 | va_list argptr; |
emh203 | 0:7798270c1f52 | 1797 | va_start(argptr,FormatString); |
emh203 | 0:7798270c1f52 | 1798 | vsprintf((char *)GFXStringBuf,FormatString,argptr); |
emh203 | 0:7798270c1f52 | 1799 | va_end(argptr); |
emh203 | 0:7798270c1f52 | 1800 | |
emh203 | 0:7798270c1f52 | 1801 | GFX_DrawString(Image,GFXStringBuf,StartX,StartY,MyFont); |
emh203 | 0:7798270c1f52 | 1802 | } |
emh203 | 0:7798270c1f52 | 1803 | |
emh203 | 0:7798270c1f52 | 1804 | #ifndef INLINE_BITPLANE_PUT |
emh203 | 0:7798270c1f52 | 1805 | void BitPlane_Put(BitPlane * BP, uint16_t X,uint16_t Y, uint8_t Value) |
emh203 | 0:7798270c1f52 | 1806 | { |
emh203 | 0:7798270c1f52 | 1807 | uint16_t Offset; |
emh203 | 0:7798270c1f52 | 1808 | uint8_t Mask; |
emh203 | 0:7798270c1f52 | 1809 | |
emh203 | 0:7798270c1f52 | 1810 | Offset = (Y * ((BP->SizeX)>>3)) + (X>>3); |
emh203 | 0:7798270c1f52 | 1811 | Mask = 0x01 << (X & 0x07); |
emh203 | 0:7798270c1f52 | 1812 | |
emh203 | 0:7798270c1f52 | 1813 | if(Value) |
emh203 | 0:7798270c1f52 | 1814 | { |
emh203 | 0:7798270c1f52 | 1815 | BP->BitPlaneSpace[Offset] |= Mask; |
emh203 | 0:7798270c1f52 | 1816 | } |
emh203 | 0:7798270c1f52 | 1817 | else |
emh203 | 0:7798270c1f52 | 1818 | { |
emh203 | 0:7798270c1f52 | 1819 | BP->BitPlaneSpace[Offset] &= ~Mask; |
emh203 | 0:7798270c1f52 | 1820 | } |
emh203 | 0:7798270c1f52 | 1821 | } |
emh203 | 0:7798270c1f52 | 1822 | #endif |
emh203 | 0:7798270c1f52 | 1823 | |
emh203 | 0:7798270c1f52 | 1824 | #ifndef INLINE_BITPLANE_GET |
emh203 | 0:7798270c1f52 | 1825 | uint8_t BitPlane_Get(BitPlane * BP, uint16_t X,uint16_t Y) |
emh203 | 0:7798270c1f52 | 1826 | { |
emh203 | 0:7798270c1f52 | 1827 | uint16_t Offset; |
emh203 | 0:7798270c1f52 | 1828 | uint8_t Mask; |
emh203 | 0:7798270c1f52 | 1829 | |
emh203 | 0:7798270c1f52 | 1830 | Offset = (Y * ((BP->SizeX)>>3)) + (X>>3); |
emh203 | 0:7798270c1f52 | 1831 | Mask = 0x01 << (X & 0x07); |
emh203 | 0:7798270c1f52 | 1832 | |
emh203 | 0:7798270c1f52 | 1833 | if((BP->BitPlaneSpace[Offset])&Mask) |
emh203 | 0:7798270c1f52 | 1834 | { |
emh203 | 0:7798270c1f52 | 1835 | return TRUE; |
emh203 | 0:7798270c1f52 | 1836 | } |
emh203 | 0:7798270c1f52 | 1837 | else |
emh203 | 0:7798270c1f52 | 1838 | { |
emh203 | 0:7798270c1f52 | 1839 | return FALSE; |
emh203 | 0:7798270c1f52 | 1840 | } |
emh203 | 0:7798270c1f52 | 1841 | } |
emh203 | 0:7798270c1f52 | 1842 | #endif |
emh203 | 0:7798270c1f52 | 1843 | |
emh203 | 0:7798270c1f52 | 1844 | void BitPlane_Clear(BitPlane * BP) |
emh203 | 0:7798270c1f52 | 1845 | { |
emh203 | 0:7798270c1f52 | 1846 | uint16_t PlaneSpaceSize; |
emh203 | 0:7798270c1f52 | 1847 | uint16_t i; |
emh203 | 0:7798270c1f52 | 1848 | |
emh203 | 0:7798270c1f52 | 1849 | PlaneSpaceSize = ((BP->SizeX)>>3) * BP->SizeY; |
emh203 | 0:7798270c1f52 | 1850 | |
emh203 | 0:7798270c1f52 | 1851 | for (i=0;i<PlaneSpaceSize;i++) { |
emh203 | 0:7798270c1f52 | 1852 | BP->BitPlaneSpace[i] = 0; |
emh203 | 0:7798270c1f52 | 1853 | } |
emh203 | 0:7798270c1f52 | 1854 | } |