Libraries and Example of mbed parallel bus using I2C port expanders

Dependencies:   HDSP253X mbed PCF8574_Bus

Committer:
wim
Date:
Tue Aug 23 20:26:05 2011 +0000
Revision:
4:745fbbd5e4e5
Parent:
3:3fbfdec782f4
Child:
5:38b853bb1afa
Test version for breadboard, using STANAG Edits

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 4:745fbbd5e4e5 81 bool laser;
wim 2:1dab1089c332 82 bool hostResetCmd;
wim 2:1dab1089c332 83 MessageToHost messageToHost;
wim 2:1dab1089c332 84 STANAG_Codes STANAG_codes;
wim 2:1dab1089c332 85
wim 2:1dab1089c332 86 // Variables for Heartbeat and Status monitoring
wim 2:1dab1089c332 87 Ticker heartbeat;
wim 2:1dab1089c332 88 bool heartbeatflag=false;
wim 2:1dab1089c332 89
wim 2:1dab1089c332 90
wim 2:1dab1089c332 91 // Local functions
wim 2:1dab1089c332 92 void clear_screen() {
wim 2:1dab1089c332 93 //ANSI Terminal Commands
wim 2:1dab1089c332 94 pc.printf("\x1B[2J");
wim 2:1dab1089c332 95 pc.printf("\x1B[H");
wim 2:1dab1089c332 96 }
wim 2:1dab1089c332 97
wim 2:1dab1089c332 98 void version_string() {
wim 2:1dab1089c332 99 pc.printf("\r\r");
wim 2:1dab1089c332 100 pc.printf("%s\r", LF28A_SOFTWARE_DESCRIPTOR);
wim 2:1dab1089c332 101 pc.printf("Version v%1d.%1d\r", LF28A_SW_VERSION_MAJOR, LF28A_SW_VERSION_MINOR);
wim 2:1dab1089c332 102 pc.printf("Build on %s at %s\r", __DATE__, __TIME__);
wim 2:1dab1089c332 103 pc.printf("%s\r", LF28A_COPYRIGHT_DESCRIPTOR);
wim 2:1dab1089c332 104 pc.printf("\r\n");
wim 2:1dab1089c332 105 }
wim 2:1dab1089c332 106
wim 2:1dab1089c332 107 void init_interfaces() {
wim 2:1dab1089c332 108 // Init Host PC communication, default is 9600
wim 2:1dab1089c332 109 pc.baud(D_BAUDRATE);
wim 2:1dab1089c332 110
wim 2:1dab1089c332 111 // Init LF28A CDA I/F hardware
wim 2:1dab1089c332 112 i2c.frequency(100000);
wim 2:1dab1089c332 113 // pc.printf("SCL0 H, L = 0x%x, 0x%x\r", LPC_I2C0->I2SCLH, LPC_I2C0->I2SCLL);
wim 2:1dab1089c332 114 // pc.printf("SCL1 H, L = 0x%x, 0x%x\r", LPC_I2C1->I2SCLH, LPC_I2C1->I2SCLL);
wim 2:1dab1089c332 115 // pc.printf("SCL2 H, L = 0x%x, 0x%x\r", LPC_I2C2->I2SCLH, LPC_I2C2->I2SCLL);
wim 2:1dab1089c332 116
wim 2:1dab1089c332 117 // Reset LF28A CDA
wim 2:1dab1089c332 118 // NOTE: On LF28A CDA the Reset* pin is connected to the Display and to the Latches.
wim 2:1dab1089c332 119 // That implies they are all reset when the Reset* pin is used !
wim 2:1dab1089c332 120 enablebus.reset(LOW);
wim 2:1dab1089c332 121 wait_ms(50);
wim 2:1dab1089c332 122 enablebus.reset(HIGH);
wim 2:1dab1089c332 123
wim 2:1dab1089c332 124 //Done, Tell me about it
wim 2:1dab1089c332 125 myled1 = 1;
wim 2:1dab1089c332 126 DBG("Init Interfaces Done, Main, Step = %d\r", 10);
wim 2:1dab1089c332 127 }
wim 2:1dab1089c332 128
wim 2:1dab1089c332 129
wim 2:1dab1089c332 130 void lamp_test() {
wim 2:1dab1089c332 131 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 132 LF28A_status.lamptest(LED_ON); // All LEDs On, including Backlight and NoGo
wim 2:1dab1089c332 133
wim 2:1dab1089c332 134 LF28A_display.locate(0);
wim 2:1dab1089c332 135 LF28A_display.printf("XXXXXXXX");
wim 2:1dab1089c332 136
wim 2:1dab1089c332 137 wait(2.0);
wim 2:1dab1089c332 138
wim 2:1dab1089c332 139 LF28A_status.lamptest(LED_OFF); // All LEDs Off, including Backlight and NoGo
wim 2:1dab1089c332 140
wim 2:1dab1089c332 141 LF28A_display.cls();
wim 2:1dab1089c332 142 // LF28A_status.set_brightness(D_STATUS_LED_BRIGHT_OFF);
wim 2:1dab1089c332 143
wim 2:1dab1089c332 144 //Done, Tell me about it
wim 2:1dab1089c332 145 DBG("Lamp Test Done, Main, Step = %d\r", 20);
wim 2:1dab1089c332 146 }
wim 2:1dab1089c332 147
wim 2:1dab1089c332 148 void BITE() {
wim 2:1dab1089c332 149 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 150 LF28A_status.NoGo(LED_OFF);
wim 2:1dab1089c332 151
wim 2:1dab1089c332 152 LF28A_display.locate(0);
wim 2:1dab1089c332 153 LF28A_display.printf("--------");
wim 2:1dab1089c332 154
wim 2:1dab1089c332 155 wait(0.5);
wim 2:1dab1089c332 156
wim 2:1dab1089c332 157 LF28A_display.cls();
wim 2:1dab1089c332 158 // LF28A_status.set_brightness(D_STATUS_LED_BRIGHT_OFF);
wim 2:1dab1089c332 159
wim 2:1dab1089c332 160 //Done, Tell me about it
wim 2:1dab1089c332 161 DBG("BITE Done, Main, Step = %d\r", 30);
wim 2:1dab1089c332 162 }
wim 2:1dab1089c332 163
wim 2:1dab1089c332 164 void init_state() {
wim 2:1dab1089c332 165 // Default modes and settings after Power On or Host Reset
wim 2:1dab1089c332 166 brightness = BRT_LOW; // Should be BRT_OFF, but then you dont see anything..
wim 2:1dab1089c332 167 graticule = BRT_LOW; // Should be BRT_OFF, but then you dont see anything..
wim 2:1dab1089c332 168
wim 2:1dab1089c332 169 range.last = 0;
wim 2:1dab1089c332 170 range.first = 0;
wim 2:1dab1089c332 171 range.select = RNG_F;
wim 2:1dab1089c332 172
wim 4:745fbbd5e4e5 173 laser = false;
wim 4:745fbbd5e4e5 174
wim 2:1dab1089c332 175 // Read Config File if needed..
wim 2:1dab1089c332 176 // Reload STANAG Codes ?
wim 2:1dab1089c332 177 STANAG_codes.setCodeIdx(0);
wim 2:1dab1089c332 178 STANAG_codes.setDigitIdx(0);
wim 2:1dab1089c332 179
wim 2:1dab1089c332 180 // Init Status LEDs
wim 2:1dab1089c332 181 LF28A_status.lamptest(LED_OFF); // All LEDs off
wim 2:1dab1089c332 182 LF28A_status.backlight(LED_ON);
wim 2:1dab1089c332 183 LF28A_status.set_brightness(brightness);
wim 2:1dab1089c332 184
wim 2:1dab1089c332 185 // Init Alphanumeric Display
wim 3:3fbfdec782f4 186 LF28A_display.cls(); // Clear display and Cursor home
wim 3:3fbfdec782f4 187 LF28A_display.set_flash_mode(true); // Enable flashing digits
wim 2:1dab1089c332 188
wim 2:1dab1089c332 189 //Done, Tell me about it
wim 2:1dab1089c332 190 DBG("Init Done, Originator = %d\r", hostResetCmd);
wim 2:1dab1089c332 191 }
wim 2:1dab1089c332 192
wim 2:1dab1089c332 193
wim 2:1dab1089c332 194 void grat_bright_selector() {
wim 2:1dab1089c332 195 int result;
wim 2:1dab1089c332 196
wim 2:1dab1089c332 197 switch (graticule) {
wim 2:1dab1089c332 198 case BRT_OFF : graticule = BRT_LOW;
wim 2:1dab1089c332 199 break;
wim 2:1dab1089c332 200 case BRT_LOW : graticule = BRT_MED;
wim 2:1dab1089c332 201 break;
wim 2:1dab1089c332 202 case BRT_MED : graticule = BRT_HIGH;
wim 2:1dab1089c332 203 break;
wim 2:1dab1089c332 204 case BRT_HIGH : graticule = BRT_OFF;
wim 2:1dab1089c332 205 break;
wim 2:1dab1089c332 206 default: // Oops, we should never end up here....
wim 2:1dab1089c332 207 graticule = BRT_LOW;
wim 2:1dab1089c332 208 result = -1;
wim 2:1dab1089c332 209 break;
wim 2:1dab1089c332 210 } //end switch
wim 2:1dab1089c332 211
wim 2:1dab1089c332 212 //Done, Tell me about it
wim 2:1dab1089c332 213 DBG("Graticule Brightness Change, current val = %d\r", graticule);
wim 2:1dab1089c332 214 }
wim 2:1dab1089c332 215
wim 2:1dab1089c332 216 void disp_bright_selector() {
wim 2:1dab1089c332 217 int result;
wim 2:1dab1089c332 218
wim 2:1dab1089c332 219 switch (brightness) {
wim 2:1dab1089c332 220 case BRT_OFF : brightness = BRT_LOW;
wim 2:1dab1089c332 221 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 222 break;
wim 2:1dab1089c332 223 case BRT_LOW : brightness = BRT_MED;
wim 2:1dab1089c332 224 LF28A_status.set_brightness(BRT_MED);
wim 2:1dab1089c332 225 break;
wim 2:1dab1089c332 226 case BRT_MED : brightness = BRT_HIGH;
wim 2:1dab1089c332 227 LF28A_status.set_brightness(BRT_HIGH);
wim 2:1dab1089c332 228 break;
wim 2:1dab1089c332 229 case BRT_HIGH : brightness = BRT_OFF;
wim 2:1dab1089c332 230 LF28A_status.set_brightness(BRT_OFF);
wim 2:1dab1089c332 231 break;
wim 2:1dab1089c332 232 default: // Oops, we should never end up here....
wim 2:1dab1089c332 233 brightness = BRT_LOW;
wim 2:1dab1089c332 234 LF28A_status.set_brightness(BRT_LOW);
wim 2:1dab1089c332 235 result = -1;
wim 2:1dab1089c332 236 break;
wim 2:1dab1089c332 237 } //end switch
wim 2:1dab1089c332 238
wim 2:1dab1089c332 239 //Done, Tell me about it
wim 2:1dab1089c332 240 DBG("Display Brightness Change, current val = %d\r", brightness);
wim 2:1dab1089c332 241 }
wim 2:1dab1089c332 242
wim 2:1dab1089c332 243 void range_selector() {
wim 2:1dab1089c332 244 int result;
wim 2:1dab1089c332 245
wim 2:1dab1089c332 246 switch (range.select) {
wim 2:1dab1089c332 247 case RNG_F : range.select = RNG_L;
wim 2:1dab1089c332 248 break;
wim 2:1dab1089c332 249 case RNG_L : range.select = RNG_F;
wim 2:1dab1089c332 250 break;
wim 2:1dab1089c332 251 default: // Oops, we should never end up here....
wim 2:1dab1089c332 252 range.select = RNG_F;
wim 2:1dab1089c332 253 result = -1;
wim 2:1dab1089c332 254 break;
wim 2:1dab1089c332 255 } //end switch
wim 2:1dab1089c332 256
wim 2:1dab1089c332 257 //Done, Tell me about it
wim 2:1dab1089c332 258 DBG("Range Change, current val = %d\r", range.select);
wim 2:1dab1089c332 259 }
wim 2:1dab1089c332 260
wim 2:1dab1089c332 261 // Heartbeat monitor
wim 2:1dab1089c332 262 void pulse() {
wim 2:1dab1089c332 263 heartbeatLED = !heartbeatLED;
wim 2:1dab1089c332 264 }
wim 2:1dab1089c332 265
wim 2:1dab1089c332 266 void heartbeat_start() {
wim 2:1dab1089c332 267 heartbeat.attach(&pulse, 0.5);
wim 2:1dab1089c332 268 heartbeatflag = true;
wim 2:1dab1089c332 269 }
wim 2:1dab1089c332 270
wim 2:1dab1089c332 271 void heartbeat_stop() {
wim 2:1dab1089c332 272 heartbeat.detach();
wim 2:1dab1089c332 273 heartbeatflag = false;
wim 2:1dab1089c332 274 }
wim 2:1dab1089c332 275
wim 2:1dab1089c332 276 //------------------------------------------------------------//
wim 2:1dab1089c332 277 // Testing Stuff //
wim 2:1dab1089c332 278 //------------------------------------------------------------//
wim 2:1dab1089c332 279 #ifdef __TESTCODE
wim 2:1dab1089c332 280 #include "Testloop.h"
wim 2:1dab1089c332 281 #endif
wim 2:1dab1089c332 282 //------------------------------------------------------------//
wim 2:1dab1089c332 283 // End Testing Stuff //
wim 2:1dab1089c332 284 //------------------------------------------------------------//
wim 2:1dab1089c332 285
wim 2:1dab1089c332 286
wim 2:1dab1089c332 287 // Construct and Send messages to Host PC. Need to complete this !!
wim 2:1dab1089c332 288 void SendHostMessage(MessageToHost messageToHost) {
wim 2:1dab1089c332 289 int result;
wim 2:1dab1089c332 290
wim 2:1dab1089c332 291 switch (messageToHost) {
wim 2:1dab1089c332 292 case LFPON : pc.printf("$LFPON*00\r\n");
wim 2:1dab1089c332 293 break;
wim 2:1dab1089c332 294
wim 3:3fbfdec782f4 295 case LFRDY_0 : // No hostResetCmd
wim 3:3fbfdec782f4 296 pc.printf("$LFRDY,0*00\r\n");
wim 3:3fbfdec782f4 297 break;
wim 3:3fbfdec782f4 298
wim 3:3fbfdec782f4 299 case LFRDY_1 : // hostResetCmd
wim 3:3fbfdec782f4 300 pc.printf("$LFRDY,1*00\r\n");
wim 2:1dab1089c332 301 break;
wim 2:1dab1089c332 302
wim 2:1dab1089c332 303 case LFSTA : pc.printf("$LFSTA,D,0,1234,1*00\r\n");
wim 2:1dab1089c332 304 break;
wim 2:1dab1089c332 305
wim 3:3fbfdec782f4 306 case LFIDL : // No Message
wim 3:3fbfdec782f4 307 break;
wim 3:3fbfdec782f4 308
wim 2:1dab1089c332 309 default: // Oops, we should never end up here....
wim 2:1dab1089c332 310
wim 2:1dab1089c332 311 result = -1;
wim 2:1dab1089c332 312 break;
wim 2:1dab1089c332 313 } //end switch
wim 2:1dab1089c332 314
wim 2:1dab1089c332 315 //Done, Tell me about it
wim 2:1dab1089c332 316 DBG("Message, current val = %d\r", messageToHost);
wim 2:1dab1089c332 317 }
wim 2:1dab1089c332 318
wim 2:1dab1089c332 319
wim 2:1dab1089c332 320 int main() {
wim 2:1dab1089c332 321 int address, result;
wim 2:1dab1089c332 322
wim 2:1dab1089c332 323 init_interfaces();
wim 2:1dab1089c332 324
wim 2:1dab1089c332 325 heartbeat_start();
wim 2:1dab1089c332 326
wim 2:1dab1089c332 327 clear_screen();
wim 2:1dab1089c332 328 version_string();
wim 2:1dab1089c332 329
wim 3:3fbfdec782f4 330 #ifndef __TESTCODE
wim 2:1dab1089c332 331 lamp_test();
wim 2:1dab1089c332 332
wim 2:1dab1089c332 333 BITE();
wim 2:1dab1089c332 334
wim 2:1dab1089c332 335 DBG("Start Main Loop, Step = %d\r", 50);
wim 2:1dab1089c332 336
wim 2:1dab1089c332 337 // Prepare main State Machine
wim 2:1dab1089c332 338 mode = INIT_ENTRY; // Start with Init
wim 2:1dab1089c332 339 hostResetCmd = false; // Start with regular PowerOn reset
wim 3:3fbfdec782f4 340
wim 2:1dab1089c332 341 // Main Controlloop:
wim 2:1dab1089c332 342 // Check keyboard input and respond as required in the current device mode
wim 2:1dab1089c332 343 // Check Host commands and respond as required
wim 2:1dab1089c332 344 while(1) {
wim 2:1dab1089c332 345
wim 2:1dab1089c332 346 // Handle mode statemachine
wim 2:1dab1089c332 347 switch (mode) {
wim 2:1dab1089c332 348
wim 2:1dab1089c332 349 // INIT MODEs - Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 350 case INIT_ENTRY: // Transitional state
wim 2:1dab1089c332 351 mode = INIT;
wim 2:1dab1089c332 352 break;
wim 2:1dab1089c332 353
wim 2:1dab1089c332 354 case INIT: // Init LF28A after Power On or Host Reset
wim 2:1dab1089c332 355 init_state();
wim 2:1dab1089c332 356
wim 2:1dab1089c332 357 // Inform Host that Init has completed
wim 3:3fbfdec782f4 358 if (!hostResetCmd) {
wim 3:3fbfdec782f4 359 // Regular PowerOn Reset
wim 4:745fbbd5e4e5 360 SendHostMessage(LFRDY_0);
wim 3:3fbfdec782f4 361 }
wim 3:3fbfdec782f4 362 else {
wim 3:3fbfdec782f4 363 // Host initiated a Reset
wim 3:3fbfdec782f4 364 SendHostMessage(LFRDY_1);
wim 3:3fbfdec782f4 365 hostResetCmd = false;
wim 3:3fbfdec782f4 366 }
wim 3:3fbfdec782f4 367
wim 2:1dab1089c332 368 mode = INIT_EXIT;
wim 2:1dab1089c332 369 break;
wim 2:1dab1089c332 370
wim 2:1dab1089c332 371 case INIT_EXIT: // Transitional state
wim 2:1dab1089c332 372 mode = DESIG_ENTRY;
wim 2:1dab1089c332 373 break;
wim 2:1dab1089c332 374
wim 2:1dab1089c332 375 // DESIG MODEs - Laser Designator
wim 2:1dab1089c332 376 case DESIG_ENTRY: // Transitional state
wim 2:1dab1089c332 377
wim 3:3fbfdec782f4 378 // Status LEDs
wim 3:3fbfdec782f4 379 LF28A_status.LED(LED_DESIG, LED_ON);
wim 3:3fbfdec782f4 380
wim 2:1dab1089c332 381 //Display current STANAG Code
wim 4:745fbbd5e4e5 382 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 383 LF28A_display.printf (" %04d",STANAG_codes.getCode() );
wim 2:1dab1089c332 384
wim 2:1dab1089c332 385 // Inform Host of change
wim 2:1dab1089c332 386 SendHostMessage(LFSTA);
wim 2:1dab1089c332 387
wim 2:1dab1089c332 388 mode = DESIG_DISP;
wim 2:1dab1089c332 389 break;
wim 2:1dab1089c332 390
wim 2:1dab1089c332 391 case DESIG_DISP:
wim 2:1dab1089c332 392 // Check and handle Keyboard
wim 2:1dab1089c332 393 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 394 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 395
wim 2:1dab1089c332 396 switch (keycode) {
wim 2:1dab1089c332 397 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 398 // Inform Host of change
wim 2:1dab1089c332 399 SendHostMessage(LFSTA);
wim 2:1dab1089c332 400 break;
wim 2:1dab1089c332 401
wim 2:1dab1089c332 402 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 403 break;
wim 2:1dab1089c332 404
wim 2:1dab1089c332 405 case KEY_MODE: mode = DESIG_EXIT;
wim 2:1dab1089c332 406 break;
wim 2:1dab1089c332 407
wim 2:1dab1089c332 408 default: // Ignore other keys
wim 2:1dab1089c332 409 break;
wim 2:1dab1089c332 410 }; //End Keyswitch
wim 2:1dab1089c332 411 }; // End Keyread
wim 2:1dab1089c332 412
wim 2:1dab1089c332 413 // Check and handle Fire key
wim 2:1dab1089c332 414
wim 2:1dab1089c332 415 break;
wim 2:1dab1089c332 416
wim 2:1dab1089c332 417 case DESIG_EXIT: // Transitional state
wim 2:1dab1089c332 418
wim 3:3fbfdec782f4 419 // Status LEDs
wim 3:3fbfdec782f4 420 LF28A_status.LED(LED_DESIG, LED_OFF);
wim 3:3fbfdec782f4 421
wim 2:1dab1089c332 422 mode = RANGE_ENTRY;
wim 2:1dab1089c332 423 break;
wim 2:1dab1089c332 424
wim 2:1dab1089c332 425 // RANGE MODEs
wim 2:1dab1089c332 426 case RANGE_ENTRY: // Transitional state
wim 2:1dab1089c332 427
wim 3:3fbfdec782f4 428 // Status LEDs
wim 3:3fbfdec782f4 429 LF28A_status.LED(LED_RANGE, LED_ON);
wim 3:3fbfdec782f4 430
wim 4:745fbbd5e4e5 431 //Display current STANAG Code ...Is this correct on entry ??
wim 4:745fbbd5e4e5 432 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 433 LF28A_display.printf (" %04d",STANAG_codes.getCode() );
wim 2:1dab1089c332 434
wim 2:1dab1089c332 435 // Inform Host of change
wim 2:1dab1089c332 436 SendHostMessage(LFSTA);
wim 2:1dab1089c332 437
wim 2:1dab1089c332 438 mode = RANGE_DISP;
wim 2:1dab1089c332 439 break;
wim 2:1dab1089c332 440
wim 2:1dab1089c332 441 case RANGE_DISP:
wim 2:1dab1089c332 442 // Check and handle Keyboard
wim 2:1dab1089c332 443 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 444 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 445
wim 2:1dab1089c332 446 switch (keycode) {
wim 2:1dab1089c332 447 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 448
wim 2:1dab1089c332 449 // Inform Host of change
wim 2:1dab1089c332 450 SendHostMessage(LFSTA);
wim 2:1dab1089c332 451
wim 2:1dab1089c332 452 break;
wim 2:1dab1089c332 453
wim 2:1dab1089c332 454 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 455 break;
wim 2:1dab1089c332 456
wim 2:1dab1089c332 457 case KEY_MODE: mode = RANGE_EXIT;
wim 2:1dab1089c332 458 break;
wim 4:745fbbd5e4e5 459
wim 4:745fbbd5e4e5 460 case KEY_F_L_UP : //Toggle First/Last
wim 4:745fbbd5e4e5 461 range_selector();
wim 4:745fbbd5e4e5 462
wim 4:745fbbd5e4e5 463 //Display current Range
wim 4:745fbbd5e4e5 464 if (range.select == RNG_F) {
wim 4:745fbbd5e4e5 465 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 466 LF28A_display.printf ("F %04d", range.first );
wim 4:745fbbd5e4e5 467 }
wim 4:745fbbd5e4e5 468 else {
wim 4:745fbbd5e4e5 469 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 470 LF28A_display.printf ("F %04d", range.last);
wim 4:745fbbd5e4e5 471 };
wim 4:745fbbd5e4e5 472
wim 4:745fbbd5e4e5 473 // Inform Host of change ??
wim 4:745fbbd5e4e5 474 //SendHostMessage(LFSTA);
wim 4:745fbbd5e4e5 475
wim 4:745fbbd5e4e5 476 break;
wim 4:745fbbd5e4e5 477
wim 4:745fbbd5e4e5 478
wim 4:745fbbd5e4e5 479 case KEY_FIRE: // Check and handle Fire key
wim 4:745fbbd5e4e5 480
wim 4:745fbbd5e4e5 481 // Toggle Laser On/Off
wim 4:745fbbd5e4e5 482 if (laser) {
wim 4:745fbbd5e4e5 483 // Laser is On, Switch Off
wim 4:745fbbd5e4e5 484
wim 4:745fbbd5e4e5 485 // Status LEDs
wim 4:745fbbd5e4e5 486 LF28A_status.LED(LED_LASER, LED_ON);
wim 4:745fbbd5e4e5 487
wim 4:745fbbd5e4e5 488 }
wim 4:745fbbd5e4e5 489 else {
wim 4:745fbbd5e4e5 490 // Laser is Off, Switch On
wim 4:745fbbd5e4e5 491
wim 4:745fbbd5e4e5 492 // Status LEDs
wim 4:745fbbd5e4e5 493 LF28A_status.LED(LED_LASER, LED_ON);
wim 4:745fbbd5e4e5 494
wim 4:745fbbd5e4e5 495 // Automatic Time-out needed
wim 4:745fbbd5e4e5 496
wim 4:745fbbd5e4e5 497 };
wim 4:745fbbd5e4e5 498
wim 4:745fbbd5e4e5 499 // Inform Host of change (laser on/off)
wim 4:745fbbd5e4e5 500 SendHostMessage(LFSTA);
wim 4:745fbbd5e4e5 501
wim 4:745fbbd5e4e5 502 break;
wim 2:1dab1089c332 503
wim 2:1dab1089c332 504 default: // Ignore other keys
wim 2:1dab1089c332 505 break;
wim 2:1dab1089c332 506 }; //End Keyswitch
wim 2:1dab1089c332 507 }; // End Keyread
wim 2:1dab1089c332 508
wim 4:745fbbd5e4e5 509 #if (0)
wim 4:745fbbd5e4e5 510 // tbd Check Automatic Time-out for Laser
wim 4:745fbbd5e4e5 511 Timer.stop()
wim 4:745fbbd5e4e5 512 laser = false;
wim 4:745fbbd5e4e5 513 // Status LEDs
wim 4:745fbbd5e4e5 514 LF28A_status.LED(LED_LASER, LED_ON);
wim 4:745fbbd5e4e5 515 #endif
wim 2:1dab1089c332 516
wim 2:1dab1089c332 517 break;
wim 2:1dab1089c332 518
wim 2:1dab1089c332 519 case RANGE_EXIT: // Transitional state
wim 4:745fbbd5e4e5 520
wim 4:745fbbd5e4e5 521 #if (0)
wim 4:745fbbd5e4e5 522 // tbd Check Automatic Time-out for Laser
wim 4:745fbbd5e4e5 523 Timer.stop()
wim 4:745fbbd5e4e5 524 laser = false;
wim 4:745fbbd5e4e5 525 // Status LEDs
wim 4:745fbbd5e4e5 526 LF28A_status.LED(LED_LASER, LED_ON);
wim 4:745fbbd5e4e5 527 #endif
wim 3:3fbfdec782f4 528
wim 3:3fbfdec782f4 529 // Status LEDs
wim 3:3fbfdec782f4 530 LF28A_status.LED(LED_RANGE, LED_OFF);
wim 2:1dab1089c332 531
wim 2:1dab1089c332 532 mode = CODE_ENTRY;
wim 2:1dab1089c332 533 break;
wim 2:1dab1089c332 534
wim 2:1dab1089c332 535
wim 2:1dab1089c332 536 // CODE MODEs
wim 2:1dab1089c332 537 case CODE_ENTRY: // Transitional state
wim 3:3fbfdec782f4 538
wim 3:3fbfdec782f4 539 // Status LEDs
wim 3:3fbfdec782f4 540 LF28A_status.LED(LED_CODE, LED_ON);
wim 4:745fbbd5e4e5 541
wim 4:745fbbd5e4e5 542 //Enable flashing Code
wim 4:745fbbd5e4e5 543 LF28A_display.set_flash_mode(true);
wim 4:745fbbd5e4e5 544
wim 2:1dab1089c332 545 //Display current STANAG Code
wim 4:745fbbd5e4e5 546 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 547 LF28A_display.printf (" %04d",STANAG_codes.getCode() );
wim 4:745fbbd5e4e5 548
wim 2:1dab1089c332 549 // Inform Host of change
wim 2:1dab1089c332 550 SendHostMessage(LFSTA);
wim 2:1dab1089c332 551
wim 2:1dab1089c332 552 mode = CODE_DISP;
wim 2:1dab1089c332 553 break;
wim 2:1dab1089c332 554
wim 2:1dab1089c332 555 case CODE_DISP:
wim 2:1dab1089c332 556 // Check and handle Keyboard
wim 2:1dab1089c332 557 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 558 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 559
wim 2:1dab1089c332 560 switch (keycode) {
wim 2:1dab1089c332 561 case KEY_GRAT_RT: grat_bright_selector();
wim 2:1dab1089c332 562
wim 2:1dab1089c332 563 // Inform Host of change
wim 2:1dab1089c332 564 SendHostMessage(LFSTA);
wim 2:1dab1089c332 565
wim 2:1dab1089c332 566 break;
wim 2:1dab1089c332 567
wim 2:1dab1089c332 568 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 569 break;
wim 2:1dab1089c332 570
wim 2:1dab1089c332 571 case KEY_MODE: mode = CODE_EXIT;
wim 2:1dab1089c332 572 break;
wim 2:1dab1089c332 573
wim 4:745fbbd5e4e5 574 case KEY_EDIT_PATH:
wim 4:745fbbd5e4e5 575 mode = CODE_EDIT;
wim 4:745fbbd5e4e5 576
wim 4:745fbbd5e4e5 577 // Enable current flashing digit
wim 4:745fbbd5e4e5 578 LF28A_display.set_char_flash_state(true, 4 + STANAG_codes.getDigitIdx());
wim 4:745fbbd5e4e5 579
wim 2:1dab1089c332 580 break;
wim 2:1dab1089c332 581
wim 2:1dab1089c332 582 case KEY_F_L_UP : //Incr STANAG code idx
wim 4:745fbbd5e4e5 583 STANAG_codes.incCodeIdx();
wim 2:1dab1089c332 584
wim 4:745fbbd5e4e5 585 //Display current STANAG Code
wim 4:745fbbd5e4e5 586 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 587 LF28A_display.printf (" %04d",STANAG_codes.getCode() );
wim 4:745fbbd5e4e5 588
wim 2:1dab1089c332 589
wim 2:1dab1089c332 590 // Inform Host of change ??
wim 2:1dab1089c332 591 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 592
wim 2:1dab1089c332 593 break;
wim 2:1dab1089c332 594
wim 2:1dab1089c332 595 default: // Ignore other keys
wim 2:1dab1089c332 596 break;
wim 2:1dab1089c332 597 }; //End Keyswitch
wim 2:1dab1089c332 598 }; //End Keyread
wim 2:1dab1089c332 599
wim 2:1dab1089c332 600 break;
wim 2:1dab1089c332 601
wim 2:1dab1089c332 602 case CODE_EDIT:
wim 2:1dab1089c332 603 // Check and handle Keyboard
wim 2:1dab1089c332 604 if (LF28A_keyboard.readable()) {
wim 2:1dab1089c332 605 keycode = LF28A_keyboard.getkey();
wim 2:1dab1089c332 606
wim 2:1dab1089c332 607 switch (keycode) {
wim 2:1dab1089c332 608 case KEY_GRAT_RT: //Cursor Right;
wim 4:745fbbd5e4e5 609 // Disable current flashing digit
wim 4:745fbbd5e4e5 610 LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());
wim 4:745fbbd5e4e5 611
wim 4:745fbbd5e4e5 612 // Incr selected digit
wim 4:745fbbd5e4e5 613 STANAG_codes.incDigitIdx();
wim 4:745fbbd5e4e5 614
wim 4:745fbbd5e4e5 615 // Enable current flashing digit
wim 4:745fbbd5e4e5 616 LF28A_display.set_char_flash_state(true, 4 + STANAG_codes.getDigitIdx());
wim 4:745fbbd5e4e5 617
wim 2:1dab1089c332 618 break;
wim 2:1dab1089c332 619
wim 2:1dab1089c332 620 case KEY_BRIGHT: disp_bright_selector();
wim 2:1dab1089c332 621 break;
wim 2:1dab1089c332 622
wim 4:745fbbd5e4e5 623 case KEY_MODE: // Done, exit Code mode
wim 4:745fbbd5e4e5 624
wim 4:745fbbd5e4e5 625 // Disable current flashing digit
wim 4:745fbbd5e4e5 626 LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());
wim 4:745fbbd5e4e5 627
wim 2:1dab1089c332 628 // Inform Host of change
wim 2:1dab1089c332 629 SendHostMessage(LFSTA);
wim 2:1dab1089c332 630
wim 2:1dab1089c332 631 mode = CODE_EXIT;
wim 2:1dab1089c332 632
wim 2:1dab1089c332 633 break;
wim 2:1dab1089c332 634
wim 4:745fbbd5e4e5 635 case KEY_EDIT_PATH: // Done, return to Code display mode
wim 4:745fbbd5e4e5 636
wim 4:745fbbd5e4e5 637 // Disable current flashing digit
wim 4:745fbbd5e4e5 638 LF28A_display.set_char_flash_state(false, 4 + STANAG_codes.getDigitIdx());
wim 4:745fbbd5e4e5 639
wim 2:1dab1089c332 640 // Inform Host of change
wim 2:1dab1089c332 641 SendHostMessage(LFSTA);
wim 2:1dab1089c332 642
wim 2:1dab1089c332 643 mode = CODE_DISP;
wim 2:1dab1089c332 644
wim 2:1dab1089c332 645 break;
wim 2:1dab1089c332 646
wim 2:1dab1089c332 647 case KEY_F_L_UP : //Incr current digit
wim 4:745fbbd5e4e5 648 STANAG_codes.incDigitIdx();
wim 4:745fbbd5e4e5 649
wim 4:745fbbd5e4e5 650 // Display Current STANAG Code
wim 4:745fbbd5e4e5 651 LF28A_display.locate (0);
wim 4:745fbbd5e4e5 652 LF28A_display.printf (" %04d",STANAG_codes.getCode() );
wim 2:1dab1089c332 653
wim 3:3fbfdec782f4 654 // Inform Host of change or wait until done editing ??
wim 2:1dab1089c332 655 //SendHostMessage(LFSTA);
wim 2:1dab1089c332 656
wim 2:1dab1089c332 657 break;
wim 2:1dab1089c332 658
wim 2:1dab1089c332 659 default: // Ignore other keys
wim 2:1dab1089c332 660 break;
wim 2:1dab1089c332 661 }; //End Keyswitch
wim 2:1dab1089c332 662 }; //End Keyread
wim 2:1dab1089c332 663
wim 2:1dab1089c332 664 break;
wim 2:1dab1089c332 665
wim 2:1dab1089c332 666 case CODE_EXIT: // Transitional state
wim 3:3fbfdec782f4 667
wim 3:3fbfdec782f4 668 // Status LEDs
wim 4:745fbbd5e4e5 669 LF28A_status.LED(LED_CODE, LED_OFF);
wim 4:745fbbd5e4e5 670
wim 4:745fbbd5e4e5 671 //Disable flashing Code
wim 4:745fbbd5e4e5 672 LF28A_display.set_flash_mode(false);
wim 4:745fbbd5e4e5 673
wim 2:1dab1089c332 674 mode = DESIG_ENTRY;
wim 2:1dab1089c332 675 break;
wim 2:1dab1089c332 676
wim 2:1dab1089c332 677 // ADDR MODEs
wim 2:1dab1089c332 678 case ADDR_ENTRY: // Transitional state
wim 2:1dab1089c332 679 case ADDR: // Transitional state
wim 2:1dab1089c332 680 case ADDR_EXIT: // Transitional state
wim 2:1dab1089c332 681 // FREQ MODEs
wim 2:1dab1089c332 682 case FREQ_ENTRY: // Transitional state
wim 2:1dab1089c332 683 case FREQ: // Transitional state
wim 2:1dab1089c332 684 case FREQ_EXIT: // Transitional state
wim 2:1dab1089c332 685 // PATH MODEs
wim 2:1dab1089c332 686 case PATH_ENTRY: // Transitional state
wim 2:1dab1089c332 687 case PATH: // Transitional state
wim 2:1dab1089c332 688 case PATH_EXIT: // Transitional state
wim 2:1dab1089c332 689
wim 2:1dab1089c332 690 default: // Oops, we should never end up here....try to recover
wim 2:1dab1089c332 691 mode = INIT_ENTRY;
wim 2:1dab1089c332 692 hostResetCmd = false;
wim 2:1dab1089c332 693
wim 2:1dab1089c332 694 result = -1;
wim 2:1dab1089c332 695 DBG("Error - Result = %d\r", result);
wim 2:1dab1089c332 696 break;
wim 2:1dab1089c332 697 }; //End mode statemachine switch
wim 2:1dab1089c332 698
wim 2:1dab1089c332 699
wim 2:1dab1089c332 700 // Handle Host commands
wim 2:1dab1089c332 701 // Reset command
wim 2:1dab1089c332 702 // Range data
wim 2:1dab1089c332 703
wim 2:1dab1089c332 704 // Just for Info, lets see how fast this cycle is...
wim 2:1dab1089c332 705 //
wim 2:1dab1089c332 706 } // end while(1)
wim 2:1dab1089c332 707
wim 2:1dab1089c332 708
wim 2:1dab1089c332 709 #else
wim 2:1dab1089c332 710 //testing stuff
wim 2:1dab1089c332 711 testloop();
wim 2:1dab1089c332 712
wim 2:1dab1089c332 713 #endif
wim 2:1dab1089c332 714
wim 2:1dab1089c332 715 DBG("I'll be back...\r\r");
wim 2:1dab1089c332 716 }