Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Sun Aug 21 19:42:48 2011 +0000
Revision:
3:3fbfdec782f4
Parent:
2:1dab1089c332
Child:
4:745fbbd5e4e5
Test version for breadboard

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 3:3fbfdec782f4 66 enum MessageToHost { LFPON, LFRDY_0, LFRDY_1, LFSTA, LFIDL };
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 3:3fbfdec782f4 183 LF28A_display.cls(); // Clear display and Cursor home
wim 3:3fbfdec782f4 184 LF28A_display.set_flash_mode(true); // Enable flashing digits
wim 2:1dab1089c332 185
wim 2:1dab1089c332 186 //Done, Tell me about it
wim 2:1dab1089c332 187 DBG("Init Done, Originator = %d\r", hostResetCmd);
wim 2:1dab1089c332 188 }
wim 2:1dab1089c332 189
wim 2:1dab1089c332 190
wim 2:1dab1089c332 191 void grat_bright_selector() {
wim 2:1dab1089c332 192 int result;
wim 2:1dab1089c332 193
wim 2:1dab1089c332 194 switch (graticule) {
wim 2:1dab1089c332 195 case BRT_OFF : graticule = BRT_LOW;
wim 2:1dab1089c332 196 break;
wim 2:1dab1089c332 197 case BRT_LOW : graticule = BRT_MED;
wim 2:1dab1089c332 198 break;
wim 2:1dab1089c332 199 case BRT_MED : graticule = BRT_HIGH;
wim 2:1dab1089c332 200 break;
wim 2:1dab1089c332 201 case BRT_HIGH : graticule = BRT_OFF;
wim 2:1dab1089c332 202 break;
wim 2:1dab1089c332 203 default: // Oops, we should never end up here....
wim 2:1dab1089c332 204 graticule = BRT_LOW;
wim 2:1dab1089c332 205 result = -1;
wim 2:1dab1089c332 206 break;
wim 2:1dab1089c332 207 } //end switch
wim 2:1dab1089c332 208
wim 2:1dab1089c332 209 //Done, Tell me about it
wim 2:1dab1089c332 210 DBG("Graticule Brightness Change, current val = %d\r", graticule);
wim 2:1dab1089c332 211 }
wim 2:1dab1089c332 212
wim 2:1dab1089c332 213 void disp_bright_selector() {
wim 2:1dab1089c332 214 int result;
wim 2:1dab1089c332 215
wim 2:1dab1089c332 216 switch (brightness) {
wim 2:1dab1089c332 217 case BRT_OFF : brightness = BRT_LOW;
wim 2:1dab1089c332 218 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 219 break;
wim 2:1dab1089c332 220 case BRT_LOW : brightness = BRT_MED;
wim 2:1dab1089c332 221 LF28A_status.set_brightness(BRT_MED);
wim 2:1dab1089c332 222 break;
wim 2:1dab1089c332 223 case BRT_MED : brightness = BRT_HIGH;
wim 2:1dab1089c332 224 LF28A_status.set_brightness(BRT_HIGH);
wim 2:1dab1089c332 225 break;
wim 2:1dab1089c332 226 case BRT_HIGH : brightness = BRT_OFF;
wim 2:1dab1089c332 227 LF28A_status.set_brightness(BRT_OFF);
wim 2:1dab1089c332 228 break;
wim 2:1dab1089c332 229 default: // Oops, we should never end up here....
wim 2:1dab1089c332 230 brightness = BRT_LOW;
wim 2:1dab1089c332 231 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 232 result = -1;
wim 2:1dab1089c332 233 break;
wim 2:1dab1089c332 234 } //end switch
wim 2:1dab1089c332 235
wim 2:1dab1089c332 236 //Done, Tell me about it
wim 2:1dab1089c332 237 DBG("Display Brightness Change, current val = %d\r", brightness);
wim 2:1dab1089c332 238 }
wim 2:1dab1089c332 239
wim 2:1dab1089c332 240 void range_selector() {
wim 2:1dab1089c332 241 int result;
wim 2:1dab1089c332 242
wim 2:1dab1089c332 243 switch (range.select) {
wim 2:1dab1089c332 244 case RNG_F : range.select = RNG_L;
wim 2:1dab1089c332 245 break;
wim 2:1dab1089c332 246 case RNG_L : range.select = RNG_F;
wim 2:1dab1089c332 247 break;
wim 2:1dab1089c332 248 default: // Oops, we should never end up here....
wim 2:1dab1089c332 249 range.select = RNG_F;
wim 2:1dab1089c332 250 result = -1;
wim 2:1dab1089c332 251 break;
wim 2:1dab1089c332 252 } //end switch
wim 2:1dab1089c332 253
wim 2:1dab1089c332 254 //Done, Tell me about it
wim 2:1dab1089c332 255 DBG("Range Change, current val = %d\r", range.select);
wim 2:1dab1089c332 256 }
wim 2:1dab1089c332 257
wim 2:1dab1089c332 258 // Heartbeat monitor
wim 2:1dab1089c332 259 void pulse() {
wim 2:1dab1089c332 260 heartbeatLED = !heartbeatLED;
wim 2:1dab1089c332 261 }
wim 2:1dab1089c332 262
wim 2:1dab1089c332 263 void heartbeat_start() {
wim 2:1dab1089c332 264 heartbeat.attach(&pulse, 0.5);
wim 2:1dab1089c332 265 heartbeatflag = true;
wim 2:1dab1089c332 266 }
wim 2:1dab1089c332 267
wim 2:1dab1089c332 268 void heartbeat_stop() {
wim 2:1dab1089c332 269 heartbeat.detach();
wim 2:1dab1089c332 270 heartbeatflag = false;
wim 2:1dab1089c332 271 }
wim 2:1dab1089c332 272
wim 2:1dab1089c332 273 //------------------------------------------------------------//
wim 2:1dab1089c332 274 // Testing Stuff //
wim 2:1dab1089c332 275 //------------------------------------------------------------//
wim 2:1dab1089c332 276 #ifdef __TESTCODE
wim 2:1dab1089c332 277 #include "Testloop.h"
wim 2:1dab1089c332 278 #endif
wim 2:1dab1089c332 279 //------------------------------------------------------------//
wim 2:1dab1089c332 280 // End Testing Stuff //
wim 2:1dab1089c332 281 //------------------------------------------------------------//
wim 2:1dab1089c332 282
wim 2:1dab1089c332 283
wim 2:1dab1089c332 284 // Construct and Send messages to Host PC. Need to complete this !!
wim 2:1dab1089c332 285 void SendHostMessage(MessageToHost messageToHost) {
wim 2:1dab1089c332 286 int result;
wim 2:1dab1089c332 287
wim 2:1dab1089c332 288 switch (messageToHost) {
wim 2:1dab1089c332 289 case LFPON : pc.printf("$LFPON*00\r\n");
wim 2:1dab1089c332 290 break;
wim 2:1dab1089c332 291
wim 3:3fbfdec782f4 292 case LFRDY_0 : // No hostResetCmd
wim 3:3fbfdec782f4 293 pc.printf("$LFRDY,0*00\r\n");
wim 3:3fbfdec782f4 294 break;
wim 3:3fbfdec782f4 295
wim 3:3fbfdec782f4 296 case LFRDY_1 : // hostResetCmd
wim 3:3fbfdec782f4 297 pc.printf("$LFRDY,1*00\r\n");
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 3:3fbfdec782f4 303 case LFIDL : // No Message
wim 3:3fbfdec782f4 304 break;
wim 3:3fbfdec782f4 305
wim 2:1dab1089c332 306 default: // Oops, we should never end up here....
wim 2:1dab1089c332 307
wim 2:1dab1089c332 308 result = -1;
wim 2:1dab1089c332 309 break;
wim 2:1dab1089c332 310 } //end switch
wim 2:1dab1089c332 311
wim 2:1dab1089c332 312 //Done, Tell me about it
wim 2:1dab1089c332 313 DBG("Message, current val = %d\r", messageToHost);
wim 2:1dab1089c332 314 }
wim 2:1dab1089c332 315
wim 2:1dab1089c332 316
wim 2:1dab1089c332 317 int main() {
wim 2:1dab1089c332 318 int address, result;
wim 2:1dab1089c332 319
wim 2:1dab1089c332 320 init_interfaces();
wim 2:1dab1089c332 321
wim 2:1dab1089c332 322 heartbeat_start();
wim 2:1dab1089c332 323
wim 2:1dab1089c332 324 clear_screen();
wim 2:1dab1089c332 325 version_string();
wim 2:1dab1089c332 326
wim 3:3fbfdec782f4 327 #ifndef __TESTCODE
wim 2:1dab1089c332 328 lamp_test();
wim 2:1dab1089c332 329
wim 2:1dab1089c332 330 BITE();
wim 2:1dab1089c332 331
wim 2:1dab1089c332 332 DBG("Start Main Loop, Step = %d\r", 50);
wim 2:1dab1089c332 333
wim 2:1dab1089c332 334 // Prepare main State Machine
wim 2:1dab1089c332 335 mode = INIT_ENTRY; // Start with Init
wim 2:1dab1089c332 336 hostResetCmd = false; // Start with regular PowerOn reset
wim 3:3fbfdec782f4 337
wim 2:1dab1089c332 338 // Main Controlloop:
wim 2:1dab1089c332 339 // Check keyboard input and respond as required in the current device mode
wim 2:1dab1089c332 340 // Check Host commands and respond as required
wim 2:1dab1089c332 341 while(1) {
wim 2:1dab1089c332 342
wim 2:1dab1089c332 343 // Handle mode statemachine
wim 2:1dab1089c332 344 switch (mode) {
wim 2:1dab1089c332 345
wim 2:1dab1089c332 346 // INIT MODEs - Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 347 case INIT_ENTRY: // Transitional state
wim 2:1dab1089c332 348 mode = INIT;
wim 2:1dab1089c332 349 break;
wim 2:1dab1089c332 350
wim 2:1dab1089c332 351 case INIT: // Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 352 init_state();
wim 2:1dab1089c332 353
wim 2:1dab1089c332 354 // Inform Host that Init has completed
wim 3:3fbfdec782f4 355 if (!hostResetCmd) {
wim 3:3fbfdec782f4 356 // Regular PowerOn Reset
wim 3:3fbfdec782f4 357 SendHostMessage(LFRDY_0)
wim 3:3fbfdec782f4 358 }
wim 3:3fbfdec782f4 359 else {
wim 3:3fbfdec782f4 360 // Host initiated a Reset
wim 3:3fbfdec782f4 361 SendHostMessage(LFRDY_1);
wim 3:3fbfdec782f4 362 hostResetCmd = false;
wim 3:3fbfdec782f4 363 }
wim 3:3fbfdec782f4 364
wim 2:1dab1089c332 365 mode = INIT_EXIT;
wim 2:1dab1089c332 366 break;
wim 2:1dab1089c332 367
wim 2:1dab1089c332 368 case INIT_EXIT: // Transitional state
wim 2:1dab1089c332 369 mode = DESIG_ENTRY;
wim 2:1dab1089c332 370 break;
wim 2:1dab1089c332 371
wim 2:1dab1089c332 372 // DESIG MODEs - Laser Designator
wim 2:1dab1089c332 373 case DESIG_ENTRY: // Transitional state
wim 2:1dab1089c332 374
wim 3:3fbfdec782f4 375 // Status LEDs
wim 3:3fbfdec782f4 376 LF28A_status.LED(LED_DESIG, LED_ON);
wim 3:3fbfdec782f4 377
wim 2:1dab1089c332 378 //Display current STANAG Code
wim 3:3fbfdec782f4 379 LF28A_display.printf("Designat");
wim 2:1dab1089c332 380
wim 2:1dab1089c332 381 // Inform Host of change
wim 2:1dab1089c332 382 SendHostMessage(LFSTA);
wim 2:1dab1089c332 383
wim 2:1dab1089c332 384 mode = DESIG_DISP;
wim 2:1dab1089c332 385 break;
wim 2:1dab1089c332 386
wim 2:1dab1089c332 387 case DESIG_DISP:
wim 2:1dab1089c332 388 // Check and handle Keyboard
wim 2:1dab1089c332 389 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 390 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 391
wim 2:1dab1089c332 392 switch (keycode) {
wim 2:1dab1089c332 393 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 394 // Inform Host of change
wim 2:1dab1089c332 395 SendHostMessage(LFSTA);
wim 2:1dab1089c332 396 break;
wim 2:1dab1089c332 397
wim 2:1dab1089c332 398 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 399 break;
wim 2:1dab1089c332 400
wim 2:1dab1089c332 401 case KEY_MODE: mode = DESIG_EXIT;
wim 2:1dab1089c332 402 break;
wim 2:1dab1089c332 403
wim 2:1dab1089c332 404 default: // Ignore other keys
wim 2:1dab1089c332 405 break;
wim 2:1dab1089c332 406 }; //End Keyswitch
wim 2:1dab1089c332 407 }; // End Keyread
wim 2:1dab1089c332 408
wim 2:1dab1089c332 409 // Check and handle Fire key
wim 2:1dab1089c332 410
wim 2:1dab1089c332 411 break;
wim 2:1dab1089c332 412
wim 2:1dab1089c332 413 case DESIG_EXIT: // Transitional state
wim 2:1dab1089c332 414
wim 3:3fbfdec782f4 415 // Status LEDs
wim 3:3fbfdec782f4 416 LF28A_status.LED(LED_DESIG, LED_OFF);
wim 3:3fbfdec782f4 417
wim 2:1dab1089c332 418 mode = RANGE_ENTRY;
wim 2:1dab1089c332 419 break;
wim 2:1dab1089c332 420
wim 2:1dab1089c332 421 // RANGE MODEs
wim 2:1dab1089c332 422 case RANGE_ENTRY: // Transitional state
wim 2:1dab1089c332 423
wim 3:3fbfdec782f4 424 // Status LEDs
wim 3:3fbfdec782f4 425 LF28A_status.LED(LED_RANGE, LED_ON);
wim 3:3fbfdec782f4 426
wim 2:1dab1089c332 427 //Display current STANAG Code
wim 3:3fbfdec782f4 428 LF28A_display.printf("Range ");
wim 2:1dab1089c332 429
wim 2:1dab1089c332 430 // Inform Host of change
wim 2:1dab1089c332 431 SendHostMessage(LFSTA);
wim 2:1dab1089c332 432
wim 2:1dab1089c332 433 mode = RANGE_DISP;
wim 2:1dab1089c332 434 break;
wim 2:1dab1089c332 435
wim 2:1dab1089c332 436 case RANGE_DISP:
wim 2:1dab1089c332 437 // Check and handle Keyboard
wim 2:1dab1089c332 438 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 439 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 440
wim 2:1dab1089c332 441 switch (keycode) {
wim 2:1dab1089c332 442 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 443
wim 2:1dab1089c332 444 // Inform Host of change
wim 2:1dab1089c332 445 SendHostMessage(LFSTA);
wim 2:1dab1089c332 446
wim 2:1dab1089c332 447 break;
wim 2:1dab1089c332 448
wim 2:1dab1089c332 449 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 450 break;
wim 2:1dab1089c332 451
wim 2:1dab1089c332 452 case KEY_MODE: mode = RANGE_EXIT;
wim 2:1dab1089c332 453 break;
wim 2:1dab1089c332 454
wim 2:1dab1089c332 455 default: // Ignore other keys
wim 2:1dab1089c332 456 break;
wim 2:1dab1089c332 457 }; //End Keyswitch
wim 2:1dab1089c332 458 }; // End Keyread
wim 2:1dab1089c332 459
wim 2:1dab1089c332 460 // Check and handle Fire key
wim 2:1dab1089c332 461 // Toggle Laser On/Off
wim 2:1dab1089c332 462 // Update and show Range, Toggle First/Last Range
wim 2:1dab1089c332 463
wim 2:1dab1089c332 464 break;
wim 2:1dab1089c332 465
wim 2:1dab1089c332 466 case RANGE_EXIT: // Transitional state
wim 3:3fbfdec782f4 467
wim 3:3fbfdec782f4 468 // Status LEDs
wim 3:3fbfdec782f4 469 LF28A_status.LED(LED_RANGE, LED_OFF);
wim 3:3fbfdec782f4 470
wim 2:1dab1089c332 471
wim 2:1dab1089c332 472 mode = CODE_ENTRY;
wim 2:1dab1089c332 473 break;
wim 2:1dab1089c332 474
wim 2:1dab1089c332 475
wim 2:1dab1089c332 476 // CODE MODEs
wim 2:1dab1089c332 477 case CODE_ENTRY: // Transitional state
wim 3:3fbfdec782f4 478
wim 3:3fbfdec782f4 479 // Status LEDs
wim 3:3fbfdec782f4 480 LF28A_status.LED(LED_CODE, LED_ON);
wim 3:3fbfdec782f4 481
wim 2:1dab1089c332 482 //Display current STANAG Code
wim 3:3fbfdec782f4 483 LF28A_display.printf("Code ");
wim 3:3fbfdec782f4 484
wim 2:1dab1089c332 485 // Inform Host of change
wim 2:1dab1089c332 486 SendHostMessage(LFSTA);
wim 2:1dab1089c332 487
wim 2:1dab1089c332 488 mode = CODE_DISP;
wim 2:1dab1089c332 489 break;
wim 2:1dab1089c332 490
wim 2:1dab1089c332 491 case CODE_DISP:
wim 2:1dab1089c332 492 // Check and handle Keyboard
wim 2:1dab1089c332 493 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 494 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 495
wim 2:1dab1089c332 496 switch (keycode) {
wim 2:1dab1089c332 497 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 498
wim 2:1dab1089c332 499 // Inform Host of change
wim 2:1dab1089c332 500 SendHostMessage(LFSTA);
wim 2:1dab1089c332 501
wim 2:1dab1089c332 502 break;
wim 2:1dab1089c332 503
wim 2:1dab1089c332 504 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 505 break;
wim 2:1dab1089c332 506
wim 2:1dab1089c332 507 case KEY_MODE: mode = CODE_EXIT;
wim 2:1dab1089c332 508 break;
wim 2:1dab1089c332 509
wim 2:1dab1089c332 510 case KEY_EDIT: mode = CODE_EDIT;
wim 2:1dab1089c332 511 break;
wim 2:1dab1089c332 512
wim 2:1dab1089c332 513 case KEY_F_L_UP : //Incr STANAG code idx
wim 2:1dab1089c332 514 STANAG_code.incIdx();
wim 2:1dab1089c332 515
wim 2:1dab1089c332 516 //Display current STANAG Code
wim 2:1dab1089c332 517
wim 2:1dab1089c332 518 // Inform Host of change ??
wim 2:1dab1089c332 519 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 520
wim 2:1dab1089c332 521 break;
wim 2:1dab1089c332 522
wim 2:1dab1089c332 523 default: // Ignore other keys
wim 2:1dab1089c332 524 break;
wim 2:1dab1089c332 525 }; //End Keyswitch
wim 2:1dab1089c332 526 }; //End Keyread
wim 2:1dab1089c332 527
wim 2:1dab1089c332 528 break;
wim 2:1dab1089c332 529
wim 2:1dab1089c332 530 case CODE_EDIT:
wim 2:1dab1089c332 531 // Check and handle Keyboard
wim 2:1dab1089c332 532 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 533 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 534
wim 2:1dab1089c332 535 switch (keycode) {
wim 2:1dab1089c332 536 case KEY_GRAT_RT: //Cursor Right;
wim 2:1dab1089c332 537 break;
wim 2:1dab1089c332 538
wim 2:1dab1089c332 539 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 540 break;
wim 2:1dab1089c332 541
wim 2:1dab1089c332 542 case KEY_MODE:
wim 2:1dab1089c332 543 // Inform Host of change
wim 2:1dab1089c332 544 SendHostMessage(LFSTA);
wim 2:1dab1089c332 545
wim 2:1dab1089c332 546 mode = CODE_EXIT;
wim 2:1dab1089c332 547
wim 2:1dab1089c332 548 break;
wim 2:1dab1089c332 549
wim 2:1dab1089c332 550 case KEY_EDIT:
wim 2:1dab1089c332 551 // Inform Host of change
wim 2:1dab1089c332 552 SendHostMessage(LFSTA);
wim 2:1dab1089c332 553
wim 2:1dab1089c332 554 mode = CODE_DISP;
wim 2:1dab1089c332 555
wim 2:1dab1089c332 556 break;
wim 2:1dab1089c332 557
wim 2:1dab1089c332 558 case KEY_F_L_UP : //Incr current digit
wim 2:1dab1089c332 559 STANAG_code.incDigitIdx();
wim 2:1dab1089c332 560
wim 3:3fbfdec782f4 561 // Inform Host of change or wait until done editing ??
wim 2:1dab1089c332 562 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 563
wim 2:1dab1089c332 564 break;
wim 2:1dab1089c332 565
wim 2:1dab1089c332 566 default: // Ignore other keys
wim 2:1dab1089c332 567 break;
wim 2:1dab1089c332 568 }; //End Keyswitch
wim 2:1dab1089c332 569 }; //End Keyread
wim 2:1dab1089c332 570
wim 2:1dab1089c332 571 break;
wim 2:1dab1089c332 572
wim 2:1dab1089c332 573 case CODE_EXIT: // Transitional state
wim 3:3fbfdec782f4 574
wim 3:3fbfdec782f4 575 // Status LEDs
wim 3:3fbfdec782f4 576 LF28A_status.LED(LED_CODE, LED_OFF);
wim 3:3fbfdec782f4 577
wim 2:1dab1089c332 578 mode = DESIG_ENTRY;
wim 2:1dab1089c332 579 break;
wim 2:1dab1089c332 580
wim 2:1dab1089c332 581 // ADDR MODEs
wim 2:1dab1089c332 582 case ADDR_ENTRY: // Transitional state
wim 2:1dab1089c332 583 case ADDR: // Transitional state
wim 2:1dab1089c332 584 case ADDR_EXIT: // Transitional state
wim 2:1dab1089c332 585 // FREQ MODEs
wim 2:1dab1089c332 586 case FREQ_ENTRY: // Transitional state
wim 2:1dab1089c332 587 case FREQ: // Transitional state
wim 2:1dab1089c332 588 case FREQ_EXIT: // Transitional state
wim 2:1dab1089c332 589 // PATH MODEs
wim 2:1dab1089c332 590 case PATH_ENTRY: // Transitional state
wim 2:1dab1089c332 591 case PATH: // Transitional state
wim 2:1dab1089c332 592 case PATH_EXIT: // Transitional state
wim 2:1dab1089c332 593
wim 2:1dab1089c332 594 default: // Oops, we should never end up here....try to recover
wim 2:1dab1089c332 595 mode = INIT_ENTRY;
wim 2:1dab1089c332 596 hostResetCmd = false;
wim 2:1dab1089c332 597
wim 2:1dab1089c332 598 result = -1;
wim 2:1dab1089c332 599 DBG("Error - Result = %d\r", result);
wim 2:1dab1089c332 600 break;
wim 2:1dab1089c332 601 }; //End mode statemachine switch
wim 2:1dab1089c332 602
wim 2:1dab1089c332 603
wim 2:1dab1089c332 604 // Handle Host commands
wim 2:1dab1089c332 605 // Reset command
wim 2:1dab1089c332 606 // Range data
wim 2:1dab1089c332 607
wim 2:1dab1089c332 608 // Just for Info, lets see how fast this cycle is...
wim 2:1dab1089c332 609 //
wim 2:1dab1089c332 610 } // end while(1)
wim 2:1dab1089c332 611
wim 2:1dab1089c332 612
wim 2:1dab1089c332 613 #else
wim 2:1dab1089c332 614 //testing stuff
wim 2:1dab1089c332 615 testloop();
wim 2:1dab1089c332 616
wim 2:1dab1089c332 617 #endif
wim 2:1dab1089c332 618
wim 2:1dab1089c332 619 DBG("I'll be back...\r\r");
wim 2:1dab1089c332 620 }