Interface layer for the mbed boards ready for the JAVA library
Dependencies: C12832 LM75B MMA7660 mbed FXOS8700Q
Fork of frdm_serial by
main.cpp@7:238c6fd5c209, 2016-02-16 (annotated)
- Committer:
- Condo2k4
- Date:
- Tue Feb 16 23:07:10 2016 +0000
- Revision:
- 7:238c6fd5c209
- Parent:
- 6:adf2837c1e7f
- Child:
- 8:d70e3e3690fd
Fixed get_heading
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
azazeal88 | 1:38f32fc3db2c | 1 | #include "mbed.h" |
co657_mjrb6 | 0:6891aea05ef2 | 2 | #include "C12832.h" |
co657_mjrb6 | 0:6891aea05ef2 | 3 | #include "LM75B.h" |
azazeal88 | 1:38f32fc3db2c | 4 | #include "MMA7660.h" |
Condo2k4 | 4:39e949908fc5 | 5 | #include "FXOS8700Q.h" |
Condo2k4 | 4:39e949908fc5 | 6 | #include "comms.h" |
Condo2k4 | 5:d9f8c2f63323 | 7 | #include "main.h" |
azazeal88 | 1:38f32fc3db2c | 8 | |
azazeal88 | 1:38f32fc3db2c | 9 | //OUTPUTS |
azazeal88 | 1:38f32fc3db2c | 10 | |
Condo2k4 | 4:39e949908fc5 | 11 | DigitalOut lr(PTB22), lg(PTE26), lb(PTB21), xr(D5), xg(D9), xb(PTC12); |
azazeal88 | 1:38f32fc3db2c | 12 | C12832 lcd(D11, D13, D12, D7, D10); |
Condo2k4 | 5:d9f8c2f63323 | 13 | PwmOut spkr(D6); |
co657_mjrb6 | 0:6891aea05ef2 | 14 | |
azazeal88 | 1:38f32fc3db2c | 15 | //INPUTS |
azazeal88 | 1:38f32fc3db2c | 16 | |
azazeal88 | 1:38f32fc3db2c | 17 | LM75B temp(D14, D15); |
Condo2k4 | 4:39e949908fc5 | 18 | MMA7660 sAcc(D14, D15); |
Condo2k4 | 4:39e949908fc5 | 19 | |
Condo2k4 | 4:39e949908fc5 | 20 | FXOS8700Q_acc bAcc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board |
Condo2k4 | 4:39e949908fc5 | 21 | FXOS8700Q_mag bMag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board |
azazeal88 | 1:38f32fc3db2c | 22 | |
Condo2k4 | 3:990f8380da21 | 23 | InterruptIn sw2_int(SW2), sw3_int(SW3), up_int(A2), down_int(A3), left_int(A4), right_int(A5), fire_int(D4); |
Condo2k4 | 3:990f8380da21 | 24 | DigitalIn sw2(SW2), sw3(SW3), up(A2), down(A3), left(A4), right(A5), fire(D4); |
azazeal88 | 1:38f32fc3db2c | 25 | |
azazeal88 | 1:38f32fc3db2c | 26 | AnalogIn pot1(A0), pot2(A1); |
co657_mjrb6 | 0:6891aea05ef2 | 27 | |
Condo2k4 | 3:990f8380da21 | 28 | //INTERRUPT FLAGS |
co657_mjrb6 | 0:6891aea05ef2 | 29 | |
azazeal88 | 1:38f32fc3db2c | 30 | uint16_t flags; |
azazeal88 | 1:38f32fc3db2c | 31 | #define SW2_DOWN 0x0001 |
azazeal88 | 1:38f32fc3db2c | 32 | #define SW2_UP 0x0002 |
azazeal88 | 1:38f32fc3db2c | 33 | #define SW3_UP 0x0004 |
azazeal88 | 1:38f32fc3db2c | 34 | #define SW3_DOWN 0x0008 |
azazeal88 | 1:38f32fc3db2c | 35 | #define UP_UP 0x0010 |
azazeal88 | 1:38f32fc3db2c | 36 | #define UP_DOWN 0x0020 |
azazeal88 | 1:38f32fc3db2c | 37 | #define DOWN_UP 0x0040 |
azazeal88 | 1:38f32fc3db2c | 38 | #define DOWN_DOWN 0x0080 |
azazeal88 | 1:38f32fc3db2c | 39 | #define LEFT_UP 0x0100 |
azazeal88 | 1:38f32fc3db2c | 40 | #define LEFT_DOWN 0x0200 |
azazeal88 | 1:38f32fc3db2c | 41 | #define RIGHT_UP 0x0400 |
azazeal88 | 1:38f32fc3db2c | 42 | #define RIGHT_DOWN 0x0800 |
azazeal88 | 1:38f32fc3db2c | 43 | #define FIRE_UP 0x1000 |
azazeal88 | 1:38f32fc3db2c | 44 | #define FIRE_DOWN 0x2000 |
co657_mjrb6 | 0:6891aea05ef2 | 45 | |
azazeal88 | 1:38f32fc3db2c | 46 | //COMMS |
co657_mjrb6 | 0:6891aea05ef2 | 47 | |
Condo2k4 | 4:39e949908fc5 | 48 | DataSerial pc(USBTX, USBRX); |
co657_mjrb6 | 0:6891aea05ef2 | 49 | |
Condo2k4 | 2:2dcdbb85cae0 | 50 | //INTERRUPT HANDLERS |
Condo2k4 | 2:2dcdbb85cae0 | 51 | |
azazeal88 | 1:38f32fc3db2c | 52 | void sw2Down(){ flags |= SW2_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 53 | void sw2Up() { flags |= SW2_UP; } |
azazeal88 | 1:38f32fc3db2c | 54 | |
azazeal88 | 1:38f32fc3db2c | 55 | void sw3Down(){ flags |= SW3_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 56 | void sw3Up() { flags |= SW3_UP; } |
azazeal88 | 1:38f32fc3db2c | 57 | |
azazeal88 | 1:38f32fc3db2c | 58 | void upDown(){ flags |= UP_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 59 | void upUp() { flags |= UP_UP; } |
azazeal88 | 1:38f32fc3db2c | 60 | |
azazeal88 | 1:38f32fc3db2c | 61 | void downDown(){ flags |= DOWN_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 62 | void downUp() { flags |= DOWN_UP; } |
azazeal88 | 1:38f32fc3db2c | 63 | |
azazeal88 | 1:38f32fc3db2c | 64 | void leftDown(){ flags |= LEFT_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 65 | void leftUp() { flags |= LEFT_UP; } |
azazeal88 | 1:38f32fc3db2c | 66 | |
azazeal88 | 1:38f32fc3db2c | 67 | void rightDown(){ flags |= RIGHT_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 68 | void rightUp() { flags |= RIGHT_UP; } |
azazeal88 | 1:38f32fc3db2c | 69 | |
azazeal88 | 1:38f32fc3db2c | 70 | void fireDown(){ flags |= FIRE_DOWN; } |
azazeal88 | 1:38f32fc3db2c | 71 | void fireUp() { flags |= FIRE_UP; } |
azazeal88 | 1:38f32fc3db2c | 72 | |
Condo2k4 | 6:adf2837c1e7f | 73 | //PRETTY WAITING LEDS |
Condo2k4 | 4:39e949908fc5 | 74 | |
Condo2k4 | 4:39e949908fc5 | 75 | Ticker waitTicker; |
Condo2k4 | 4:39e949908fc5 | 76 | int ctr; |
Condo2k4 | 4:39e949908fc5 | 77 | |
Condo2k4 | 4:39e949908fc5 | 78 | void waitTick() { |
Condo2k4 | 4:39e949908fc5 | 79 | switch(ctr) { |
Condo2k4 | 4:39e949908fc5 | 80 | case 0: |
Condo2k4 | 4:39e949908fc5 | 81 | xr=xg=0; xb=1; break; |
Condo2k4 | 4:39e949908fc5 | 82 | case 1: |
Condo2k4 | 4:39e949908fc5 | 83 | xr=0; xg=xb=1; break; |
Condo2k4 | 4:39e949908fc5 | 84 | case 2: |
Condo2k4 | 4:39e949908fc5 | 85 | xr=xb=0; xg=1; break; |
Condo2k4 | 4:39e949908fc5 | 86 | case 3: |
Condo2k4 | 4:39e949908fc5 | 87 | xb=0; xr=xg=1; break; |
Condo2k4 | 4:39e949908fc5 | 88 | case 4: |
Condo2k4 | 4:39e949908fc5 | 89 | xg=xb=0; xr=1; break; |
Condo2k4 | 4:39e949908fc5 | 90 | case 5: |
Condo2k4 | 5:d9f8c2f63323 | 91 | lr=xg=lb=0; xr=lg=xb=1; |
Condo2k4 | 5:d9f8c2f63323 | 92 | ctr=0; return; |
Condo2k4 | 4:39e949908fc5 | 93 | } |
Condo2k4 | 5:d9f8c2f63323 | 94 | lr=!xr; lg=!xg; lb=!xb; |
Condo2k4 | 4:39e949908fc5 | 95 | ctr++; |
Condo2k4 | 4:39e949908fc5 | 96 | } |
Condo2k4 | 4:39e949908fc5 | 97 | |
Condo2k4 | 2:2dcdbb85cae0 | 98 | /* |
Condo2k4 | 2:2dcdbb85cae0 | 99 | Return the state of a requested pin |
Condo2k4 | 2:2dcdbb85cae0 | 100 | */ |
Condo2k4 | 5:d9f8c2f63323 | 101 | void read_digital() { |
azazeal88 | 1:38f32fc3db2c | 102 | bool val; |
Condo2k4 | 5:d9f8c2f63323 | 103 | switch(pc.readChar()) { |
Condo2k4 | 6:adf2837c1e7f | 104 | case '2': val=!sw2; break; |
Condo2k4 | 6:adf2837c1e7f | 105 | case '3': val=!sw3; break; |
azazeal88 | 1:38f32fc3db2c | 106 | case 'u': val=up; break; |
azazeal88 | 1:38f32fc3db2c | 107 | case 'd': val=down; break; |
azazeal88 | 1:38f32fc3db2c | 108 | case 'l': val=left; break; |
azazeal88 | 1:38f32fc3db2c | 109 | case 'r': val=right; break; |
azazeal88 | 1:38f32fc3db2c | 110 | case 'f': val=fire; break; |
azazeal88 | 1:38f32fc3db2c | 111 | default: return; |
co657_mjrb6 | 0:6891aea05ef2 | 112 | } |
Condo2k4 | 6:adf2837c1e7f | 113 | pc.sendBool(val); |
co657_mjrb6 | 0:6891aea05ef2 | 114 | } |
co657_mjrb6 | 0:6891aea05ef2 | 115 | |
Condo2k4 | 2:2dcdbb85cae0 | 116 | /* |
Condo2k4 | 2:2dcdbb85cae0 | 117 | Return the state of a requested potentiometer |
Condo2k4 | 2:2dcdbb85cae0 | 118 | */ |
Condo2k4 | 5:d9f8c2f63323 | 119 | void read_pot() { |
azazeal88 | 1:38f32fc3db2c | 120 | float val; |
Condo2k4 | 5:d9f8c2f63323 | 121 | switch(pc.readChar()) { |
azazeal88 | 1:38f32fc3db2c | 122 | case '1': val=pot1; break; |
azazeal88 | 1:38f32fc3db2c | 123 | case '2': val=pot2; break; |
azazeal88 | 1:38f32fc3db2c | 124 | default: return; |
azazeal88 | 1:38f32fc3db2c | 125 | } |
Condo2k4 | 4:39e949908fc5 | 126 | pc.sendFloat(val); |
Condo2k4 | 3:990f8380da21 | 127 | } |
Condo2k4 | 5:d9f8c2f63323 | 128 | void read_temp() { //read temp |
Condo2k4 | 5:d9f8c2f63323 | 129 | float t = temp.read(); |
Condo2k4 | 5:d9f8c2f63323 | 130 | pc.sendFloat(t); |
Condo2k4 | 5:d9f8c2f63323 | 131 | } |
Condo2k4 | 3:990f8380da21 | 132 | |
Condo2k4 | 5:d9f8c2f63323 | 133 | void read_shield_accel() {//read shield accel |
Condo2k4 | 5:d9f8c2f63323 | 134 | float x, y, z; |
Condo2k4 | 5:d9f8c2f63323 | 135 | x = sAcc.x(); |
Condo2k4 | 5:d9f8c2f63323 | 136 | y = sAcc.y(); |
Condo2k4 | 5:d9f8c2f63323 | 137 | z = sAcc.z(); |
Condo2k4 | 5:d9f8c2f63323 | 138 | pc.sendFloat(x); |
Condo2k4 | 5:d9f8c2f63323 | 139 | pc.sendFloat(y); |
Condo2k4 | 5:d9f8c2f63323 | 140 | pc.sendFloat(z); |
Condo2k4 | 5:d9f8c2f63323 | 141 | } |
Condo2k4 | 5:d9f8c2f63323 | 142 | |
Condo2k4 | 5:d9f8c2f63323 | 143 | void set_shield_led() { //shield led |
Condo2k4 | 5:d9f8c2f63323 | 144 | char raw = pc.readChar(); |
Condo2k4 | 5:d9f8c2f63323 | 145 | char r = ((raw>>2)&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 146 | char g = ((raw>>1)&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 147 | char b = (raw&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 148 | xr = r; xg = g; xb = b; |
Condo2k4 | 5:d9f8c2f63323 | 149 | } |
Condo2k4 | 5:d9f8c2f63323 | 150 | |
Condo2k4 | 5:d9f8c2f63323 | 151 | void get_orientation() { //read shield accel orientation |
Condo2k4 | 5:d9f8c2f63323 | 152 | MMA7660::Orientation o = sAcc.getOrientation(); |
Condo2k4 | 5:d9f8c2f63323 | 153 | pc.sendChar((char)o); |
Condo2k4 | 5:d9f8c2f63323 | 154 | } |
Condo2k4 | 5:d9f8c2f63323 | 155 | |
Condo2k4 | 5:d9f8c2f63323 | 156 | void get_side() { //read shield accel orientation |
Condo2k4 | 5:d9f8c2f63323 | 157 | MMA7660::Orientation o = sAcc.getSide(); |
Condo2k4 | 5:d9f8c2f63323 | 158 | pc.sendChar((char)o); |
Condo2k4 | 5:d9f8c2f63323 | 159 | } |
Condo2k4 | 5:d9f8c2f63323 | 160 | |
Condo2k4 | 5:d9f8c2f63323 | 161 | void get_heading() { |
Condo2k4 | 4:39e949908fc5 | 162 | MotionSensorDataUnits mag; |
Condo2k4 | 4:39e949908fc5 | 163 | bMag.getAxis(mag); |
Condo2k4 | 7:238c6fd5c209 | 164 | float heading = atan2(-(mag.x-20.0f),mag.y-5.0f)*180.0f/M_PI; |
Condo2k4 | 7:238c6fd5c209 | 165 | if(heading<0) heading+=360.0f; |
Condo2k4 | 5:d9f8c2f63323 | 166 | pc.sendFloat(heading); |
Condo2k4 | 5:d9f8c2f63323 | 167 | } |
Condo2k4 | 5:d9f8c2f63323 | 168 | |
Condo2k4 | 5:d9f8c2f63323 | 169 | void set_board_led() { // board led |
Condo2k4 | 5:d9f8c2f63323 | 170 | char raw = pc.readChar(); |
Condo2k4 | 5:d9f8c2f63323 | 171 | char r = ((raw>>2)&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 172 | char g = ((raw>>1)&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 173 | char b = (raw&1)^1; |
Condo2k4 | 5:d9f8c2f63323 | 174 | lr = r; lg = g; lb = b; |
Condo2k4 | 5:d9f8c2f63323 | 175 | } |
Condo2k4 | 5:d9f8c2f63323 | 176 | |
Condo2k4 | 5:d9f8c2f63323 | 177 | void read_board_magno() { //read board magno |
Condo2k4 | 5:d9f8c2f63323 | 178 | MotionSensorDataUnits mag; |
Condo2k4 | 5:d9f8c2f63323 | 179 | bMag.getAxis(mag); |
Condo2k4 | 5:d9f8c2f63323 | 180 | pc.sendFloat(mag.x); |
Condo2k4 | 5:d9f8c2f63323 | 181 | pc.sendFloat(mag.y); |
Condo2k4 | 5:d9f8c2f63323 | 182 | pc.sendFloat(mag.z); |
Condo2k4 | 5:d9f8c2f63323 | 183 | } |
Condo2k4 | 5:d9f8c2f63323 | 184 | |
Condo2k4 | 5:d9f8c2f63323 | 185 | void read_board_accel() { //read board accel |
Condo2k4 | 5:d9f8c2f63323 | 186 | float f; |
Condo2k4 | 5:d9f8c2f63323 | 187 | bAcc.getX(&f); pc.sendFloat(f); |
Condo2k4 | 5:d9f8c2f63323 | 188 | bAcc.getY(&f); pc.sendFloat(f); |
Condo2k4 | 5:d9f8c2f63323 | 189 | bAcc.getZ(&f); pc.sendFloat(f); |
Condo2k4 | 5:d9f8c2f63323 | 190 | } |
Condo2k4 | 5:d9f8c2f63323 | 191 | |
Condo2k4 | 5:d9f8c2f63323 | 192 | void set_lcd_position() { //set lcd position |
Condo2k4 | 5:d9f8c2f63323 | 193 | unsigned char xy[2]; |
Condo2k4 | 5:d9f8c2f63323 | 194 | pc.readData(xy,2); |
Condo2k4 | 5:d9f8c2f63323 | 195 | lcd.locate(xy[0],xy[1]); |
Condo2k4 | 5:d9f8c2f63323 | 196 | } |
Condo2k4 | 5:d9f8c2f63323 | 197 | |
Condo2k4 | 5:d9f8c2f63323 | 198 | void print_text() { //print lcd text |
Condo2k4 | 5:d9f8c2f63323 | 199 | char buff[256]; |
Condo2k4 | 5:d9f8c2f63323 | 200 | char len = pc.readString(buff); |
Condo2k4 | 5:d9f8c2f63323 | 201 | buff[len]=0; |
Condo2k4 | 5:d9f8c2f63323 | 202 | lcd.printf(buff); |
Condo2k4 | 5:d9f8c2f63323 | 203 | lcd.copy_to_lcd(); |
Condo2k4 | 6:adf2837c1e7f | 204 | pc.sendBool(true); |
Condo2k4 | 5:d9f8c2f63323 | 205 | } |
Condo2k4 | 5:d9f8c2f63323 | 206 | |
Condo2k4 | 5:d9f8c2f63323 | 207 | void set_lcd_pixel() { //set lcd pixel |
Condo2k4 | 5:d9f8c2f63323 | 208 | char xyc[3]; |
Condo2k4 | 5:d9f8c2f63323 | 209 | pc.readData(xyc, 3); |
Condo2k4 | 5:d9f8c2f63323 | 210 | lcd.pixel(xyc[0],xyc[1],xyc[2]); |
Condo2k4 | 5:d9f8c2f63323 | 211 | lcd.copy_to_lcd(); |
Condo2k4 | 5:d9f8c2f63323 | 212 | } |
Condo2k4 | 5:d9f8c2f63323 | 213 | |
Condo2k4 | 5:d9f8c2f63323 | 214 | void set_piezo() { // set piezo buzzer |
Condo2k4 | 5:d9f8c2f63323 | 215 | float vol = pc.readFloat(); |
Condo2k4 | 5:d9f8c2f63323 | 216 | float period = 1.0f/pc.readFloat(); |
Condo2k4 | 5:d9f8c2f63323 | 217 | spkr=vol*0.5f; //convert volume to duty cycle |
Condo2k4 | 5:d9f8c2f63323 | 218 | spkr.period(period); |
Condo2k4 | 5:d9f8c2f63323 | 219 | } |
Condo2k4 | 5:d9f8c2f63323 | 220 | |
Condo2k4 | 5:d9f8c2f63323 | 221 | void clear_lcd() { //clear lcd |
Condo2k4 | 5:d9f8c2f63323 | 222 | lcd.cls(); |
Condo2k4 | 6:adf2837c1e7f | 223 | pc.sendBool(true); |
Condo2k4 | 5:d9f8c2f63323 | 224 | } |
Condo2k4 | 5:d9f8c2f63323 | 225 | |
Condo2k4 | 5:d9f8c2f63323 | 226 | void cleanup() { |
Condo2k4 | 5:d9f8c2f63323 | 227 | lr = lg = lb = 1; |
Condo2k4 | 5:d9f8c2f63323 | 228 | xr = xg = xb = 1; |
Condo2k4 | 5:d9f8c2f63323 | 229 | lcd.cls(); |
Condo2k4 | 5:d9f8c2f63323 | 230 | |
Condo2k4 | 5:d9f8c2f63323 | 231 | pc.sendChar(RECONNECT); |
Condo2k4 | 5:d9f8c2f63323 | 232 | } |
Condo2k4 | 5:d9f8c2f63323 | 233 | |
Condo2k4 | 5:d9f8c2f63323 | 234 | void reconnect() { //reconnection |
Condo2k4 | 5:d9f8c2f63323 | 235 | cleanup(); |
Condo2k4 | 3:990f8380da21 | 236 | } |
Condo2k4 | 3:990f8380da21 | 237 | |
Condo2k4 | 3:990f8380da21 | 238 | int main() { |
azazeal88 | 1:38f32fc3db2c | 239 | //SETUP |
Condo2k4 | 5:d9f8c2f63323 | 240 | pc.baud(115200); |
azazeal88 | 1:38f32fc3db2c | 241 | |
Condo2k4 | 3:990f8380da21 | 242 | lr = lg = lb = 1; |
Condo2k4 | 5:d9f8c2f63323 | 243 | xr = xg = xb = 1; |
Condo2k4 | 5:d9f8c2f63323 | 244 | |
Condo2k4 | 5:d9f8c2f63323 | 245 | bAcc.enable(); |
Condo2k4 | 5:d9f8c2f63323 | 246 | bMag.enable(); |
co657_mjrb6 | 0:6891aea05ef2 | 247 | |
co657_mjrb6 | 0:6891aea05ef2 | 248 | sw2_int.mode (PullUp); |
co657_mjrb6 | 0:6891aea05ef2 | 249 | sw2_int.fall(&sw2Down); |
co657_mjrb6 | 0:6891aea05ef2 | 250 | sw2_int.rise(&sw2Up); |
co657_mjrb6 | 0:6891aea05ef2 | 251 | |
co657_mjrb6 | 0:6891aea05ef2 | 252 | sw3_int.mode (PullUp); |
co657_mjrb6 | 0:6891aea05ef2 | 253 | sw3_int.fall(&sw3Down); |
co657_mjrb6 | 0:6891aea05ef2 | 254 | sw3_int.rise(&sw3Up); |
co657_mjrb6 | 0:6891aea05ef2 | 255 | |
azazeal88 | 1:38f32fc3db2c | 256 | up_int.mode (PullUp); |
Condo2k4 | 4:39e949908fc5 | 257 | up_int.rise(&upDown); |
Condo2k4 | 4:39e949908fc5 | 258 | up_int.fall(&upUp); |
azazeal88 | 1:38f32fc3db2c | 259 | |
azazeal88 | 1:38f32fc3db2c | 260 | down_int.mode (PullUp); |
Condo2k4 | 4:39e949908fc5 | 261 | down_int.rise(&downDown); |
Condo2k4 | 4:39e949908fc5 | 262 | down_int.fall(&downUp); |
azazeal88 | 1:38f32fc3db2c | 263 | |
azazeal88 | 1:38f32fc3db2c | 264 | left_int.mode (PullUp); |
Condo2k4 | 4:39e949908fc5 | 265 | left_int.rise(&leftDown); |
Condo2k4 | 4:39e949908fc5 | 266 | left_int.fall(&leftUp); |
azazeal88 | 1:38f32fc3db2c | 267 | |
azazeal88 | 1:38f32fc3db2c | 268 | right_int.mode (PullUp); |
Condo2k4 | 4:39e949908fc5 | 269 | right_int.rise(&rightDown); |
Condo2k4 | 4:39e949908fc5 | 270 | right_int.fall(&rightUp); |
azazeal88 | 1:38f32fc3db2c | 271 | |
azazeal88 | 1:38f32fc3db2c | 272 | fire_int.mode (PullUp); |
Condo2k4 | 4:39e949908fc5 | 273 | fire_int.rise(&fireDown); |
Condo2k4 | 4:39e949908fc5 | 274 | fire_int.fall(&fireUp); |
co657_mjrb6 | 0:6891aea05ef2 | 275 | |
Condo2k4 | 3:990f8380da21 | 276 | //Pretty wait |
Condo2k4 | 3:990f8380da21 | 277 | ctr=0; |
Condo2k4 | 3:990f8380da21 | 278 | lcd.locate(0,0); |
Condo2k4 | 3:990f8380da21 | 279 | lcd.printf("Awaiting connection..."); |
Condo2k4 | 4:39e949908fc5 | 280 | waitTicker.attach(&waitTick,0.5); |
Condo2k4 | 5:d9f8c2f63323 | 281 | while((!pc.readable()) && (pc.readChar()!=RECONNECT)) sleep(); |
Condo2k4 | 3:990f8380da21 | 282 | waitTicker.detach(); |
Condo2k4 | 3:990f8380da21 | 283 | cleanup(); |
Condo2k4 | 3:990f8380da21 | 284 | |
azazeal88 | 1:38f32fc3db2c | 285 | for(;;) { |
Condo2k4 | 2:2dcdbb85cae0 | 286 | //Check if any interrupts fired |
azazeal88 | 1:38f32fc3db2c | 287 | if(flags&SW2_UP) { |
Condo2k4 | 3:990f8380da21 | 288 | flags&=!SW2_UP; |
Condo2k4 | 4:39e949908fc5 | 289 | pc.sendSpecialCommand('2','u'); |
azazeal88 | 1:38f32fc3db2c | 290 | } |
azazeal88 | 1:38f32fc3db2c | 291 | if(flags&SW2_DOWN) { |
Condo2k4 | 3:990f8380da21 | 292 | flags&=!SW2_DOWN; |
Condo2k4 | 4:39e949908fc5 | 293 | pc.sendSpecialCommand('2','d'); |
azazeal88 | 1:38f32fc3db2c | 294 | } |
azazeal88 | 1:38f32fc3db2c | 295 | if(flags&SW3_UP) { |
Condo2k4 | 3:990f8380da21 | 296 | flags&=!SW3_UP; |
Condo2k4 | 4:39e949908fc5 | 297 | pc.sendSpecialCommand('3','u'); |
azazeal88 | 1:38f32fc3db2c | 298 | } |
azazeal88 | 1:38f32fc3db2c | 299 | if(flags&SW3_DOWN) { |
Condo2k4 | 3:990f8380da21 | 300 | flags&=!SW3_DOWN; |
Condo2k4 | 4:39e949908fc5 | 301 | pc.sendSpecialCommand('3','d'); |
azazeal88 | 1:38f32fc3db2c | 302 | } |
azazeal88 | 1:38f32fc3db2c | 303 | if(flags&UP_UP) { |
Condo2k4 | 3:990f8380da21 | 304 | flags&=!UP_UP; |
Condo2k4 | 4:39e949908fc5 | 305 | pc.sendSpecialCommand('u','u'); |
azazeal88 | 1:38f32fc3db2c | 306 | } |
azazeal88 | 1:38f32fc3db2c | 307 | if(flags&UP_DOWN) { |
Condo2k4 | 3:990f8380da21 | 308 | flags&=!UP_DOWN; |
Condo2k4 | 4:39e949908fc5 | 309 | pc.sendSpecialCommand('u','d'); |
co657_mjrb6 | 0:6891aea05ef2 | 310 | } |
azazeal88 | 1:38f32fc3db2c | 311 | if(flags&DOWN_UP) { |
Condo2k4 | 3:990f8380da21 | 312 | flags&=!DOWN_UP; |
Condo2k4 | 4:39e949908fc5 | 313 | pc.sendSpecialCommand('d','u'); |
azazeal88 | 1:38f32fc3db2c | 314 | } |
azazeal88 | 1:38f32fc3db2c | 315 | if(flags&DOWN_DOWN) { |
Condo2k4 | 3:990f8380da21 | 316 | flags&=!DOWN_DOWN; |
Condo2k4 | 4:39e949908fc5 | 317 | pc.sendSpecialCommand('d','d'); |
azazeal88 | 1:38f32fc3db2c | 318 | } |
azazeal88 | 1:38f32fc3db2c | 319 | if(flags&LEFT_UP) { |
Condo2k4 | 3:990f8380da21 | 320 | flags&=!LEFT_UP; |
Condo2k4 | 4:39e949908fc5 | 321 | pc.sendSpecialCommand('l','u'); |
azazeal88 | 1:38f32fc3db2c | 322 | } |
azazeal88 | 1:38f32fc3db2c | 323 | if(flags&LEFT_DOWN) { |
Condo2k4 | 3:990f8380da21 | 324 | flags&=!LEFT_DOWN; |
Condo2k4 | 4:39e949908fc5 | 325 | pc.sendSpecialCommand('l','d'); |
co657_mjrb6 | 0:6891aea05ef2 | 326 | } |
azazeal88 | 1:38f32fc3db2c | 327 | if(flags&RIGHT_UP) { |
Condo2k4 | 3:990f8380da21 | 328 | flags&=!RIGHT_UP; |
Condo2k4 | 4:39e949908fc5 | 329 | pc.sendSpecialCommand('r','u'); |
azazeal88 | 1:38f32fc3db2c | 330 | } |
azazeal88 | 1:38f32fc3db2c | 331 | if(flags&RIGHT_DOWN) { |
Condo2k4 | 3:990f8380da21 | 332 | flags&=!RIGHT_DOWN; |
Condo2k4 | 4:39e949908fc5 | 333 | pc.sendSpecialCommand('r','d'); |
azazeal88 | 1:38f32fc3db2c | 334 | } |
azazeal88 | 1:38f32fc3db2c | 335 | if(flags&FIRE_UP) { |
Condo2k4 | 3:990f8380da21 | 336 | flags&=!FIRE_UP; |
Condo2k4 | 4:39e949908fc5 | 337 | pc.sendSpecialCommand('f','u'); |
azazeal88 | 1:38f32fc3db2c | 338 | } |
azazeal88 | 1:38f32fc3db2c | 339 | if(flags&FIRE_DOWN) { |
Condo2k4 | 3:990f8380da21 | 340 | flags&=!FIRE_DOWN; |
Condo2k4 | 4:39e949908fc5 | 341 | pc.sendSpecialCommand('f','d'); |
co657_mjrb6 | 0:6891aea05ef2 | 342 | } |
azazeal88 | 1:38f32fc3db2c | 343 | |
azazeal88 | 1:38f32fc3db2c | 344 | //Check for host requests |
co657_mjrb6 | 0:6891aea05ef2 | 345 | if(pc.readable()) { |
Condo2k4 | 5:d9f8c2f63323 | 346 | unsigned char cmd = pc.readChar(); |
Condo2k4 | 5:d9f8c2f63323 | 347 | if(cmd<COMMAND_LENGTH) { |
Condo2k4 | 5:d9f8c2f63323 | 348 | commandFunctions[cmd](); |
co657_mjrb6 | 0:6891aea05ef2 | 349 | } |
co657_mjrb6 | 0:6891aea05ef2 | 350 | } |
co657_mjrb6 | 0:6891aea05ef2 | 351 | } |
Condo2k4 | 4:39e949908fc5 | 352 | } |