Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Sat Aug 20 12:49:44 2011 +0000
Revision:
2:1dab1089c332
Child:
3:3fbfdec782f4
First commit, testloop

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 2:1dab1089c332 1 /* LF28A Simulator - Main
wim 2:1dab1089c332 2 * Copyright (c) 2011 Wim Huiskamp
wim 2:1dab1089c332 3 *
wim 2:1dab1089c332 4 * Released under the MIT License: http://mbed.org/license/mit
wim 2:1dab1089c332 5 *
wim 2:1dab1089c332 6 * version 0.2 Initial Release
wim 2:1dab1089c332 7 */
wim 2:1dab1089c332 8 #include "mbed.h"
wim 2:1dab1089c332 9 #include "BusDefines.h"
wim 2:1dab1089c332 10 #include "PCF8574_DataBus.h"
wim 2:1dab1089c332 11 #include "PCF8574_AddressBus.h"
wim 2:1dab1089c332 12 #include "PCF8574_EnableBus.h"
wim 2:1dab1089c332 13 #include "MBED_ControlBus.h"
wim 2:1dab1089c332 14 #include "HDSP253X_Display.h"
wim 2:1dab1089c332 15 #include "Status_Display.h"
wim 2:1dab1089c332 16 #include "Keyboard.h"
wim 2:1dab1089c332 17 #include "STANAG_Codes.h"
wim 2:1dab1089c332 18
wim 2:1dab1089c332 19 // Debug stuff
wim 2:1dab1089c332 20 #define __DEBUG
wim 2:1dab1089c332 21 #include "Dbg.h"
wim 2:1dab1089c332 22
wim 2:1dab1089c332 23 #define __TESTCODE
wim 2:1dab1089c332 24
wim 2:1dab1089c332 25
wim 2:1dab1089c332 26 // Software version
wim 2:1dab1089c332 27 #define LF28A_SOFTWARE_DESCRIPTOR "LF28A Testsoftware"
wim 2:1dab1089c332 28 #define LF28A_SW_VERSION_MAJOR 0
wim 2:1dab1089c332 29 #define LF28A_SW_VERSION_MINOR 2
wim 2:1dab1089c332 30 #define LF28A_COPYRIGHT_DESCRIPTOR "(C)TNO 2011"
wim 2:1dab1089c332 31
wim 2:1dab1089c332 32 // mbed Interface Hardware definitions
wim 2:1dab1089c332 33 DigitalOut myled1(LED1);
wim 2:1dab1089c332 34 DigitalOut myled2(LED2);
wim 2:1dab1089c332 35 DigitalOut myled3(LED3);
wim 2:1dab1089c332 36 DigitalOut heartbeatLED(LED4);
wim 2:1dab1089c332 37
wim 2:1dab1089c332 38 Serial pc(USBTX, USBRX);
wim 2:1dab1089c332 39
wim 2:1dab1089c332 40 I2C i2c(D_SDA, D_SCL);
wim 2:1dab1089c332 41
wim 2:1dab1089c332 42 // CDA Interface Hardware definitions
wim 2:1dab1089c332 43 PCF8574_DataBus databus = PCF8574_DataBus(i2c, D_I2C_DATA_BUS); //Copy constructors..
wim 2:1dab1089c332 44 PCF8574_AddressBus addressbus = PCF8574_AddressBus(i2c, D_I2C_ADDR_BUS);
wim 2:1dab1089c332 45 PCF8574_EnableBus enablebus = PCF8574_EnableBus(i2c, D_I2C_ENA_BUS);
wim 2:1dab1089c332 46 MBED_ControlBus controlbus = MBED_ControlBus(D_WR, D_RD, D_DTR, D_CDBUF, D_CDINT, D_FIRE);
wim 2:1dab1089c332 47
wim 2:1dab1089c332 48 // CDA Hardware definitions
wim 2:1dab1089c332 49 HDSP253X_Display LF28A_display = HDSP253X_Display(databus, addressbus, enablebus, controlbus);
wim 2:1dab1089c332 50 Status_Display LF28A_status = Status_Display(databus, enablebus, controlbus);
wim 2:1dab1089c332 51 Keyboard LF28A_keyboard = Keyboard(databus, enablebus, controlbus);
wim 2:1dab1089c332 52
wim 2:1dab1089c332 53
wim 2:1dab1089c332 54 //Enums for LF28A Statemachines
wim 2:1dab1089c332 55 enum Mode { IDLE,
wim 2:1dab1089c332 56 INIT_ENTRY, INIT, INIT_EXIT,
wim 2:1dab1089c332 57 DESIG_ENTRY, DESIG_DISP, DESIG_LASER, DESIG_EXIT,
wim 2:1dab1089c332 58 RANGE_ENTRY, RANGE_DISP, RANGE_FIRE, RANGE_EXIT,
wim 2:1dab1089c332 59 CODE_ENTRY, CODE_DISP, CODE_EDIT, CODE_EXIT,
wim 2:1dab1089c332 60 ADDR_ENTRY, ADDR, ADDR_EXIT,
wim 2:1dab1089c332 61 FREQ_ENTRY, FREQ, FREQ_EXIT,
wim 2:1dab1089c332 62 PATH_ENTRY, PATH, PATH_EXIT };
wim 2:1dab1089c332 63
wim 2:1dab1089c332 64 enum RangeSelect { RNG_F, RNG_L };
wim 2:1dab1089c332 65
wim 2:1dab1089c332 66 enum MessageToHost { LFPON, LFRDY, LFSTA };
wim 2:1dab1089c332 67 enum MessageFromHost { LFRES, LFRNG };
wim 2:1dab1089c332 68
wim 2:1dab1089c332 69 //Typedef for Laser Range finder data
wim 2:1dab1089c332 70 typedef struct {
wim 2:1dab1089c332 71 uint16_t first;
wim 2:1dab1089c332 72 uint16_t last;
wim 2:1dab1089c332 73 RangeSelect select;
wim 2:1dab1089c332 74 } Range_t;
wim 2:1dab1089c332 75
wim 2:1dab1089c332 76 // Variables for Statemachine
wim 2:1dab1089c332 77 Mode mode;
wim 2:1dab1089c332 78 Brightness brightness, graticule;
wim 2:1dab1089c332 79 Key_Code keycode;
wim 2:1dab1089c332 80 Range_t range;
wim 2:1dab1089c332 81 bool hostResetCmd;
wim 2:1dab1089c332 82 MessageToHost messageToHost;
wim 2:1dab1089c332 83 STANAG_Codes STANAG_codes;
wim 2:1dab1089c332 84
wim 2:1dab1089c332 85 // Variables for Heartbeat and Status monitoring
wim 2:1dab1089c332 86 Ticker heartbeat;
wim 2:1dab1089c332 87 bool heartbeatflag=false;
wim 2:1dab1089c332 88
wim 2:1dab1089c332 89
wim 2:1dab1089c332 90 // Local functions
wim 2:1dab1089c332 91 void clear_screen() {
wim 2:1dab1089c332 92 //ANSI Terminal Commands
wim 2:1dab1089c332 93 pc.printf("\x1B[2J");
wim 2:1dab1089c332 94 pc.printf("\x1B[H");
wim 2:1dab1089c332 95 }
wim 2:1dab1089c332 96
wim 2:1dab1089c332 97 void version_string() {
wim 2:1dab1089c332 98 pc.printf("\r\r");
wim 2:1dab1089c332 99 pc.printf("%s\r", LF28A_SOFTWARE_DESCRIPTOR);
wim 2:1dab1089c332 100 pc.printf("Version v%1d.%1d\r", LF28A_SW_VERSION_MAJOR, LF28A_SW_VERSION_MINOR);
wim 2:1dab1089c332 101 pc.printf("Build on %s at %s\r", __DATE__, __TIME__);
wim 2:1dab1089c332 102 pc.printf("%s\r", LF28A_COPYRIGHT_DESCRIPTOR);
wim 2:1dab1089c332 103 pc.printf("\r\n");
wim 2:1dab1089c332 104 }
wim 2:1dab1089c332 105
wim 2:1dab1089c332 106 void init_interfaces() {
wim 2:1dab1089c332 107 // Init Host PC communication, default is 9600
wim 2:1dab1089c332 108 pc.baud(D_BAUDRATE);
wim 2:1dab1089c332 109
wim 2:1dab1089c332 110 // Init LF28A CDA I/F hardware
wim 2:1dab1089c332 111 i2c.frequency(100000);
wim 2:1dab1089c332 112 // pc.printf("SCL0 H, L = 0x%x, 0x%x\r", LPC_I2C0->I2SCLH, LPC_I2C0->I2SCLL);
wim 2:1dab1089c332 113 // pc.printf("SCL1 H, L = 0x%x, 0x%x\r", LPC_I2C1->I2SCLH, LPC_I2C1->I2SCLL);
wim 2:1dab1089c332 114 // pc.printf("SCL2 H, L = 0x%x, 0x%x\r", LPC_I2C2->I2SCLH, LPC_I2C2->I2SCLL);
wim 2:1dab1089c332 115
wim 2:1dab1089c332 116 // Reset LF28A CDA
wim 2:1dab1089c332 117 // NOTE: On LF28A CDA the Reset* pin is connected to the Display and to the Latches.
wim 2:1dab1089c332 118 // That implies they are all reset when the Reset* pin is used !
wim 2:1dab1089c332 119 enablebus.reset(LOW);
wim 2:1dab1089c332 120 wait_ms(50);
wim 2:1dab1089c332 121 enablebus.reset(HIGH);
wim 2:1dab1089c332 122
wim 2:1dab1089c332 123 //Done, Tell me about it
wim 2:1dab1089c332 124 myled1 = 1;
wim 2:1dab1089c332 125 DBG("Init Interfaces Done, Main, Step = %d\r", 10);
wim 2:1dab1089c332 126 }
wim 2:1dab1089c332 127
wim 2:1dab1089c332 128
wim 2:1dab1089c332 129 void lamp_test() {
wim 2:1dab1089c332 130 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 131 LF28A_status.lamptest(LED_ON); // All LEDs On, including Backlight and NoGo
wim 2:1dab1089c332 132
wim 2:1dab1089c332 133 LF28A_display.locate(0);
wim 2:1dab1089c332 134 LF28A_display.printf("XXXXXXXX");
wim 2:1dab1089c332 135
wim 2:1dab1089c332 136 wait(2.0);
wim 2:1dab1089c332 137
wim 2:1dab1089c332 138 LF28A_status.lamptest(LED_OFF); // All LEDs Off, including Backlight and NoGo
wim 2:1dab1089c332 139
wim 2:1dab1089c332 140 LF28A_display.cls();
wim 2:1dab1089c332 141 // LF28A_status.set_brightness(D_STATUS_LED_BRIGHT_OFF);
wim 2:1dab1089c332 142
wim 2:1dab1089c332 143 //Done, Tell me about it
wim 2:1dab1089c332 144 DBG("Lamp Test Done, Main, Step = %d\r", 20);
wim 2:1dab1089c332 145 }
wim 2:1dab1089c332 146
wim 2:1dab1089c332 147 void BITE() {
wim 2:1dab1089c332 148 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 149 LF28A_status.NoGo(LED_OFF);
wim 2:1dab1089c332 150
wim 2:1dab1089c332 151 LF28A_display.locate(0);
wim 2:1dab1089c332 152 LF28A_display.printf("--------");
wim 2:1dab1089c332 153
wim 2:1dab1089c332 154 wait(0.5);
wim 2:1dab1089c332 155
wim 2:1dab1089c332 156 LF28A_display.cls();
wim 2:1dab1089c332 157 // LF28A_status.set_brightness(D_STATUS_LED_BRIGHT_OFF);
wim 2:1dab1089c332 158
wim 2:1dab1089c332 159 //Done, Tell me about it
wim 2:1dab1089c332 160 DBG("BITE Done, Main, Step = %d\r", 30);
wim 2:1dab1089c332 161 }
wim 2:1dab1089c332 162
wim 2:1dab1089c332 163 void init_state() {
wim 2:1dab1089c332 164 // Default modes and settings after Power On or Host Reset
wim 2:1dab1089c332 165 brightness = BRT_LOW; // Should be BRT_OFF, but then you dont see anything..
wim 2:1dab1089c332 166 graticule = BRT_LOW; // Should be BRT_OFF, but then you dont see anything..
wim 2:1dab1089c332 167
wim 2:1dab1089c332 168 range.last = 0;
wim 2:1dab1089c332 169 range.first = 0;
wim 2:1dab1089c332 170 range.select = RNG_F;
wim 2:1dab1089c332 171
wim 2:1dab1089c332 172 // Read Config File if needed..
wim 2:1dab1089c332 173 // Reload STANAG Codes ?
wim 2:1dab1089c332 174 STANAG_codes.setCodeIdx(0);
wim 2:1dab1089c332 175 STANAG_codes.setDigitIdx(0);
wim 2:1dab1089c332 176
wim 2:1dab1089c332 177 // Init Status LEDs
wim 2:1dab1089c332 178 LF28A_status.lamptest(LED_OFF); // All LEDs off
wim 2:1dab1089c332 179 LF28A_status.backlight(LED_ON);
wim 2:1dab1089c332 180 LF28A_status.set_brightness(brightness);
wim 2:1dab1089c332 181
wim 2:1dab1089c332 182 // Init Alphanumeric Display
wim 2:1dab1089c332 183 LF28A_display.cls();
wim 2:1dab1089c332 184
wim 2:1dab1089c332 185 //Done, Tell me about it
wim 2:1dab1089c332 186 DBG("Init Done, Originator = %d\r", hostResetCmd);
wim 2:1dab1089c332 187 }
wim 2:1dab1089c332 188
wim 2:1dab1089c332 189
wim 2:1dab1089c332 190 void grat_bright_selector() {
wim 2:1dab1089c332 191 int result;
wim 2:1dab1089c332 192
wim 2:1dab1089c332 193 switch (graticule) {
wim 2:1dab1089c332 194 case BRT_OFF : graticule = BRT_LOW;
wim 2:1dab1089c332 195 break;
wim 2:1dab1089c332 196 case BRT_LOW : graticule = BRT_MED;
wim 2:1dab1089c332 197 break;
wim 2:1dab1089c332 198 case BRT_MED : graticule = BRT_HIGH;
wim 2:1dab1089c332 199 break;
wim 2:1dab1089c332 200 case BRT_HIGH : graticule = BRT_OFF;
wim 2:1dab1089c332 201 break;
wim 2:1dab1089c332 202 default: // Oops, we should never end up here....
wim 2:1dab1089c332 203 graticule = BRT_LOW;
wim 2:1dab1089c332 204 result = -1;
wim 2:1dab1089c332 205 break;
wim 2:1dab1089c332 206 } //end switch
wim 2:1dab1089c332 207
wim 2:1dab1089c332 208 //Done, Tell me about it
wim 2:1dab1089c332 209 DBG("Graticule Brightness Change, current val = %d\r", graticule);
wim 2:1dab1089c332 210 }
wim 2:1dab1089c332 211
wim 2:1dab1089c332 212 void disp_bright_selector() {
wim 2:1dab1089c332 213 int result;
wim 2:1dab1089c332 214
wim 2:1dab1089c332 215 switch (brightness) {
wim 2:1dab1089c332 216 case BRT_OFF : brightness = BRT_LOW;
wim 2:1dab1089c332 217 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 218 break;
wim 2:1dab1089c332 219 case BRT_LOW : brightness = BRT_MED;
wim 2:1dab1089c332 220 LF28A_status.set_brightness(BRT_MED);
wim 2:1dab1089c332 221 break;
wim 2:1dab1089c332 222 case BRT_MED : brightness = BRT_HIGH;
wim 2:1dab1089c332 223 LF28A_status.set_brightness(BRT_HIGH);
wim 2:1dab1089c332 224 break;
wim 2:1dab1089c332 225 case BRT_HIGH : brightness = BRT_OFF;
wim 2:1dab1089c332 226 LF28A_status.set_brightness(BRT_OFF);
wim 2:1dab1089c332 227 break;
wim 2:1dab1089c332 228 default: // Oops, we should never end up here....
wim 2:1dab1089c332 229 brightness = BRT_LOW;
wim 2:1dab1089c332 230 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 231 result = -1;
wim 2:1dab1089c332 232 break;
wim 2:1dab1089c332 233 } //end switch
wim 2:1dab1089c332 234
wim 2:1dab1089c332 235 //Done, Tell me about it
wim 2:1dab1089c332 236 DBG("Display Brightness Change, current val = %d\r", brightness);
wim 2:1dab1089c332 237 }
wim 2:1dab1089c332 238
wim 2:1dab1089c332 239 void range_selector() {
wim 2:1dab1089c332 240 int result;
wim 2:1dab1089c332 241
wim 2:1dab1089c332 242 switch (range.select) {
wim 2:1dab1089c332 243 case RNG_F : range.select = RNG_L;
wim 2:1dab1089c332 244 break;
wim 2:1dab1089c332 245 case RNG_L : range.select = RNG_F;
wim 2:1dab1089c332 246 break;
wim 2:1dab1089c332 247 default: // Oops, we should never end up here....
wim 2:1dab1089c332 248 range.select = RNG_F;
wim 2:1dab1089c332 249 result = -1;
wim 2:1dab1089c332 250 break;
wim 2:1dab1089c332 251 } //end switch
wim 2:1dab1089c332 252
wim 2:1dab1089c332 253 //Done, Tell me about it
wim 2:1dab1089c332 254 DBG("Range Change, current val = %d\r", range.select);
wim 2:1dab1089c332 255 }
wim 2:1dab1089c332 256
wim 2:1dab1089c332 257 // Heartbeat monitor
wim 2:1dab1089c332 258 void pulse() {
wim 2:1dab1089c332 259 heartbeatLED = !heartbeatLED;
wim 2:1dab1089c332 260 }
wim 2:1dab1089c332 261
wim 2:1dab1089c332 262 void heartbeat_start() {
wim 2:1dab1089c332 263 heartbeat.attach(&pulse, 0.5);
wim 2:1dab1089c332 264 heartbeatflag = true;
wim 2:1dab1089c332 265 }
wim 2:1dab1089c332 266
wim 2:1dab1089c332 267 void heartbeat_stop() {
wim 2:1dab1089c332 268 heartbeat.detach();
wim 2:1dab1089c332 269 heartbeatflag = false;
wim 2:1dab1089c332 270 }
wim 2:1dab1089c332 271
wim 2:1dab1089c332 272 //------------------------------------------------------------//
wim 2:1dab1089c332 273 // Testing Stuff //
wim 2:1dab1089c332 274 //------------------------------------------------------------//
wim 2:1dab1089c332 275 #ifdef __TESTCODE
wim 2:1dab1089c332 276 #include "Testloop.h"
wim 2:1dab1089c332 277 #endif
wim 2:1dab1089c332 278 //------------------------------------------------------------//
wim 2:1dab1089c332 279 // End Testing Stuff //
wim 2:1dab1089c332 280 //------------------------------------------------------------//
wim 2:1dab1089c332 281
wim 2:1dab1089c332 282
wim 2:1dab1089c332 283 // Construct and Send messages to Host PC. Need to complete this !!
wim 2:1dab1089c332 284 void SendHostMessage(MessageToHost messageToHost) {
wim 2:1dab1089c332 285 int result;
wim 2:1dab1089c332 286
wim 2:1dab1089c332 287 switch (messageToHost) {
wim 2:1dab1089c332 288 case LFPON : pc.printf("$LFPON*00\r\n");
wim 2:1dab1089c332 289 break;
wim 2:1dab1089c332 290
wim 2:1dab1089c332 291 case LFRDY : if (!hostResetCmd) {
wim 2:1dab1089c332 292 pc.printf("$LFRDY,0*00\r\n");
wim 2:1dab1089c332 293 }
wim 2:1dab1089c332 294 else {
wim 2:1dab1089c332 295 pc.printf("$LFRDY,1*00\r\n");
wim 2:1dab1089c332 296 hostResetCmd = false;
wim 2:1dab1089c332 297 }
wim 2:1dab1089c332 298 break;
wim 2:1dab1089c332 299
wim 2:1dab1089c332 300 case LFSTA : pc.printf("$LFSTA,D,0,1234,1*00\r\n");
wim 2:1dab1089c332 301 break;
wim 2:1dab1089c332 302
wim 2:1dab1089c332 303 default: // Oops, we should never end up here....
wim 2:1dab1089c332 304
wim 2:1dab1089c332 305 result = -1;
wim 2:1dab1089c332 306 break;
wim 2:1dab1089c332 307 } //end switch
wim 2:1dab1089c332 308
wim 2:1dab1089c332 309 //Done, Tell me about it
wim 2:1dab1089c332 310 DBG("Message, current val = %d\r", messageToHost);
wim 2:1dab1089c332 311 }
wim 2:1dab1089c332 312
wim 2:1dab1089c332 313
wim 2:1dab1089c332 314 int main() {
wim 2:1dab1089c332 315 int address, result;
wim 2:1dab1089c332 316
wim 2:1dab1089c332 317 init_interfaces();
wim 2:1dab1089c332 318
wim 2:1dab1089c332 319 heartbeat_start();
wim 2:1dab1089c332 320
wim 2:1dab1089c332 321 clear_screen();
wim 2:1dab1089c332 322 version_string();
wim 2:1dab1089c332 323
wim 2:1dab1089c332 324 lamp_test();
wim 2:1dab1089c332 325
wim 2:1dab1089c332 326 BITE();
wim 2:1dab1089c332 327
wim 2:1dab1089c332 328 DBG("Start Main Loop, Step = %d\r", 50);
wim 2:1dab1089c332 329
wim 2:1dab1089c332 330 // Prepare main State Machine
wim 2:1dab1089c332 331 mode = INIT_ENTRY; // Start with Init
wim 2:1dab1089c332 332 hostResetCmd = false; // Start with regular PowerOn reset
wim 2:1dab1089c332 333
wim 2:1dab1089c332 334
wim 2:1dab1089c332 335 #ifndef __TESTCODE
wim 2:1dab1089c332 336 // Main Controlloop:
wim 2:1dab1089c332 337 // Check keyboard input and respond as required in the current device mode
wim 2:1dab1089c332 338 // Check Host commands and respond as required
wim 2:1dab1089c332 339 while(1) {
wim 2:1dab1089c332 340
wim 2:1dab1089c332 341 // Handle mode statemachine
wim 2:1dab1089c332 342 switch (mode) {
wim 2:1dab1089c332 343
wim 2:1dab1089c332 344 // INIT MODEs - Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 345 case INIT_ENTRY: // Transitional state
wim 2:1dab1089c332 346 mode = INIT;
wim 2:1dab1089c332 347 break;
wim 2:1dab1089c332 348
wim 2:1dab1089c332 349 case INIT: // Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 350 init_state();
wim 2:1dab1089c332 351
wim 2:1dab1089c332 352 // Inform Host that Init has completed
wim 2:1dab1089c332 353 SendHostMessage(LFRDY);
wim 2:1dab1089c332 354
wim 2:1dab1089c332 355 mode = INIT_EXIT;
wim 2:1dab1089c332 356 break;
wim 2:1dab1089c332 357
wim 2:1dab1089c332 358 case INIT_EXIT: // Transitional state
wim 2:1dab1089c332 359 mode = DESIG_ENTRY;
wim 2:1dab1089c332 360 break;
wim 2:1dab1089c332 361
wim 2:1dab1089c332 362 // DESIG MODEs - Laser Designator
wim 2:1dab1089c332 363 case DESIG_ENTRY: // Transitional state
wim 2:1dab1089c332 364
wim 2:1dab1089c332 365 //Display current STANAG Code
wim 2:1dab1089c332 366
wim 2:1dab1089c332 367 // Inform Host of change
wim 2:1dab1089c332 368 SendHostMessage(LFSTA);
wim 2:1dab1089c332 369
wim 2:1dab1089c332 370 mode = DESIG_DISP;
wim 2:1dab1089c332 371 break;
wim 2:1dab1089c332 372
wim 2:1dab1089c332 373 case DESIG_DISP:
wim 2:1dab1089c332 374 // Check and handle Keyboard
wim 2:1dab1089c332 375 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 376 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 377
wim 2:1dab1089c332 378 switch (keycode) {
wim 2:1dab1089c332 379 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 380 // Inform Host of change
wim 2:1dab1089c332 381 SendHostMessage(LFSTA);
wim 2:1dab1089c332 382 break;
wim 2:1dab1089c332 383
wim 2:1dab1089c332 384 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 385 break;
wim 2:1dab1089c332 386
wim 2:1dab1089c332 387 case KEY_MODE: mode = DESIG_EXIT;
wim 2:1dab1089c332 388 break;
wim 2:1dab1089c332 389
wim 2:1dab1089c332 390 default: // Ignore other keys
wim 2:1dab1089c332 391 break;
wim 2:1dab1089c332 392 }; //End Keyswitch
wim 2:1dab1089c332 393 }; // End Keyread
wim 2:1dab1089c332 394
wim 2:1dab1089c332 395 // Check and handle Fire key
wim 2:1dab1089c332 396
wim 2:1dab1089c332 397 break;
wim 2:1dab1089c332 398
wim 2:1dab1089c332 399 case DESIG_EXIT: // Transitional state
wim 2:1dab1089c332 400
wim 2:1dab1089c332 401 mode = RANGE_ENTRY;
wim 2:1dab1089c332 402 break;
wim 2:1dab1089c332 403
wim 2:1dab1089c332 404 // RANGE MODEs
wim 2:1dab1089c332 405 case RANGE_ENTRY: // Transitional state
wim 2:1dab1089c332 406
wim 2:1dab1089c332 407 //Display current STANAG Code
wim 2:1dab1089c332 408
wim 2:1dab1089c332 409 // Inform Host of change
wim 2:1dab1089c332 410 SendHostMessage(LFSTA);
wim 2:1dab1089c332 411
wim 2:1dab1089c332 412 mode = RANGE_DISP;
wim 2:1dab1089c332 413 break;
wim 2:1dab1089c332 414
wim 2:1dab1089c332 415 case RANGE_DISP:
wim 2:1dab1089c332 416 // Check and handle Keyboard
wim 2:1dab1089c332 417 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 418 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 419
wim 2:1dab1089c332 420 switch (keycode) {
wim 2:1dab1089c332 421 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 422
wim 2:1dab1089c332 423 // Inform Host of change
wim 2:1dab1089c332 424 SendHostMessage(LFSTA);
wim 2:1dab1089c332 425
wim 2:1dab1089c332 426 break;
wim 2:1dab1089c332 427
wim 2:1dab1089c332 428 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 429 break;
wim 2:1dab1089c332 430
wim 2:1dab1089c332 431 case KEY_MODE: mode = RANGE_EXIT;
wim 2:1dab1089c332 432 break;
wim 2:1dab1089c332 433
wim 2:1dab1089c332 434 default: // Ignore other keys
wim 2:1dab1089c332 435 break;
wim 2:1dab1089c332 436 }; //End Keyswitch
wim 2:1dab1089c332 437 }; // End Keyread
wim 2:1dab1089c332 438
wim 2:1dab1089c332 439 // Check and handle Fire key
wim 2:1dab1089c332 440 // Toggle Laser On/Off
wim 2:1dab1089c332 441 // Update and show Range, Toggle First/Last Range
wim 2:1dab1089c332 442
wim 2:1dab1089c332 443 break;
wim 2:1dab1089c332 444
wim 2:1dab1089c332 445 case RANGE_EXIT: // Transitional state
wim 2:1dab1089c332 446
wim 2:1dab1089c332 447 mode = CODE_ENTRY;
wim 2:1dab1089c332 448 break;
wim 2:1dab1089c332 449
wim 2:1dab1089c332 450
wim 2:1dab1089c332 451 // CODE MODEs
wim 2:1dab1089c332 452 case CODE_ENTRY: // Transitional state
wim 2:1dab1089c332 453
wim 2:1dab1089c332 454 //Display current STANAG Code
wim 2:1dab1089c332 455
wim 2:1dab1089c332 456 // Inform Host of change
wim 2:1dab1089c332 457 SendHostMessage(LFSTA);
wim 2:1dab1089c332 458
wim 2:1dab1089c332 459 mode = CODE_DISP;
wim 2:1dab1089c332 460 break;
wim 2:1dab1089c332 461
wim 2:1dab1089c332 462 case CODE_DISP:
wim 2:1dab1089c332 463 // Check and handle Keyboard
wim 2:1dab1089c332 464 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 465 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 466
wim 2:1dab1089c332 467 switch (keycode) {
wim 2:1dab1089c332 468 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 469
wim 2:1dab1089c332 470 // Inform Host of change
wim 2:1dab1089c332 471 SendHostMessage(LFSTA);
wim 2:1dab1089c332 472
wim 2:1dab1089c332 473 break;
wim 2:1dab1089c332 474
wim 2:1dab1089c332 475 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 476 break;
wim 2:1dab1089c332 477
wim 2:1dab1089c332 478 case KEY_MODE: mode = CODE_EXIT;
wim 2:1dab1089c332 479 break;
wim 2:1dab1089c332 480
wim 2:1dab1089c332 481 case KEY_EDIT: mode = CODE_EDIT;
wim 2:1dab1089c332 482 break;
wim 2:1dab1089c332 483
wim 2:1dab1089c332 484 case KEY_F_L_UP : //Incr STANAG code idx
wim 2:1dab1089c332 485 STANAG_code.incIdx();
wim 2:1dab1089c332 486
wim 2:1dab1089c332 487 //Display current STANAG Code
wim 2:1dab1089c332 488
wim 2:1dab1089c332 489 // Inform Host of change ??
wim 2:1dab1089c332 490 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 491
wim 2:1dab1089c332 492 break;
wim 2:1dab1089c332 493
wim 2:1dab1089c332 494 default: // Ignore other keys
wim 2:1dab1089c332 495 break;
wim 2:1dab1089c332 496 }; //End Keyswitch
wim 2:1dab1089c332 497 }; //End Keyread
wim 2:1dab1089c332 498
wim 2:1dab1089c332 499 break;
wim 2:1dab1089c332 500
wim 2:1dab1089c332 501 case CODE_EDIT:
wim 2:1dab1089c332 502 // Check and handle Keyboard
wim 2:1dab1089c332 503 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 504 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 505
wim 2:1dab1089c332 506 switch (keycode) {
wim 2:1dab1089c332 507 case KEY_GRAT_RT: //Cursor Right;
wim 2:1dab1089c332 508 break;
wim 2:1dab1089c332 509
wim 2:1dab1089c332 510 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 511 break;
wim 2:1dab1089c332 512
wim 2:1dab1089c332 513 case KEY_MODE:
wim 2:1dab1089c332 514 // Inform Host of change
wim 2:1dab1089c332 515 SendHostMessage(LFSTA);
wim 2:1dab1089c332 516
wim 2:1dab1089c332 517 mode = CODE_EXIT;
wim 2:1dab1089c332 518
wim 2:1dab1089c332 519 break;
wim 2:1dab1089c332 520
wim 2:1dab1089c332 521 case KEY_EDIT:
wim 2:1dab1089c332 522 // Inform Host of change
wim 2:1dab1089c332 523 SendHostMessage(LFSTA);
wim 2:1dab1089c332 524
wim 2:1dab1089c332 525 mode = CODE_DISP;
wim 2:1dab1089c332 526
wim 2:1dab1089c332 527 break;
wim 2:1dab1089c332 528
wim 2:1dab1089c332 529 case KEY_F_L_UP : //Incr current digit
wim 2:1dab1089c332 530 STANAG_code.incDigitIdx();
wim 2:1dab1089c332 531
wim 2:1dab1089c332 532 // Inform Host of change ro wait untip done editing ??
wim 2:1dab1089c332 533 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 534
wim 2:1dab1089c332 535 break;
wim 2:1dab1089c332 536
wim 2:1dab1089c332 537 default: // Ignore other keys
wim 2:1dab1089c332 538 break;
wim 2:1dab1089c332 539 }; //End Keyswitch
wim 2:1dab1089c332 540 }; //End Keyread
wim 2:1dab1089c332 541
wim 2:1dab1089c332 542 break;
wim 2:1dab1089c332 543
wim 2:1dab1089c332 544 case CODE_EXIT: // Transitional state
wim 2:1dab1089c332 545
wim 2:1dab1089c332 546 mode = DESIG_ENTRY;
wim 2:1dab1089c332 547 break;
wim 2:1dab1089c332 548
wim 2:1dab1089c332 549 // ADDR MODEs
wim 2:1dab1089c332 550 case ADDR_ENTRY: // Transitional state
wim 2:1dab1089c332 551 case ADDR: // Transitional state
wim 2:1dab1089c332 552 case ADDR_EXIT: // Transitional state
wim 2:1dab1089c332 553 // FREQ MODEs
wim 2:1dab1089c332 554 case FREQ_ENTRY: // Transitional state
wim 2:1dab1089c332 555 case FREQ: // Transitional state
wim 2:1dab1089c332 556 case FREQ_EXIT: // Transitional state
wim 2:1dab1089c332 557 // PATH MODEs
wim 2:1dab1089c332 558 case PATH_ENTRY: // Transitional state
wim 2:1dab1089c332 559 case PATH: // Transitional state
wim 2:1dab1089c332 560 case PATH_EXIT: // Transitional state
wim 2:1dab1089c332 561
wim 2:1dab1089c332 562 default: // Oops, we should never end up here....try to recover
wim 2:1dab1089c332 563 mode = INIT_ENTRY;
wim 2:1dab1089c332 564 hostResetCmd = false;
wim 2:1dab1089c332 565
wim 2:1dab1089c332 566 result = -1;
wim 2:1dab1089c332 567 DBG("Error - Result = %d\r", result);
wim 2:1dab1089c332 568 break;
wim 2:1dab1089c332 569 }; //End mode statemachine switch
wim 2:1dab1089c332 570
wim 2:1dab1089c332 571
wim 2:1dab1089c332 572 // Handle Host commands
wim 2:1dab1089c332 573 // Reset command
wim 2:1dab1089c332 574 // Range data
wim 2:1dab1089c332 575
wim 2:1dab1089c332 576 // Just for Info, lets see how fast this cycle is...
wim 2:1dab1089c332 577 //
wim 2:1dab1089c332 578 } // end while(1)
wim 2:1dab1089c332 579
wim 2:1dab1089c332 580
wim 2:1dab1089c332 581 #else
wim 2:1dab1089c332 582 //testing stuff
wim 2:1dab1089c332 583 testloop();
wim 2:1dab1089c332 584
wim 2:1dab1089c332 585 #endif
wim 2:1dab1089c332 586
wim 2:1dab1089c332 587 DBG("I'll be back...\r\r");
wim 2:1dab1089c332 588 }