Grenade Drone Controller
Dependencies: mbed
SwitchFn/SwitchFn.cpp@2:915533cf5d94, 2018-08-20 (annotated)
- Committer:
- halusis
- Date:
- Mon Aug 20 03:08:50 2018 +0000
- Revision:
- 2:915533cf5d94
- Parent:
- 1:d2b6491e52fd
Grenade Drone Switch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
halusis | 0:02ed82ccad9f | 1 | #include "SwitchFn.h" |
halusis | 0:02ed82ccad9f | 2 | #include "PinAssign.h" |
halusis | 0:02ed82ccad9f | 3 | #include "GlobalVars.h" |
halusis | 0:02ed82ccad9f | 4 | |
halusis | 0:02ed82ccad9f | 5 | Timeout Sw1timer,Sw2timer,Sw3timer,Sw4timer,Sw5timer,Sw6timer,Sw7timer,Sw8timer,Sw14timer,Sw58timer,SwAlltimer; |
halusis | 0:02ed82ccad9f | 6 | void Sw1_isr(void){fSw1++;} |
halusis | 0:02ed82ccad9f | 7 | void Sw2_isr(void){fSw2++;} |
halusis | 0:02ed82ccad9f | 8 | void Sw3_isr(void){fSw3++;} |
halusis | 0:02ed82ccad9f | 9 | void Sw4_isr(void){fSw4++;} |
halusis | 0:02ed82ccad9f | 10 | void Sw5_isr(void){fSw5++;} |
halusis | 0:02ed82ccad9f | 11 | void Sw6_isr(void){fSw6++;} |
halusis | 0:02ed82ccad9f | 12 | void Sw7_isr(void){fSw7++;} |
halusis | 0:02ed82ccad9f | 13 | void Sw8_isr(void){fSw8++;} |
halusis | 0:02ed82ccad9f | 14 | void Sw14_isr(void){fSw14++;} |
halusis | 0:02ed82ccad9f | 15 | void Sw58_isr(void){fSw58++;} |
halusis | 0:02ed82ccad9f | 16 | void SwAll_isr(void){fSwAll++;} |
halusis | 0:02ed82ccad9f | 17 | |
halusis | 0:02ed82ccad9f | 18 | void Send2Crr(void) |
halusis | 0:02ed82ccad9f | 19 | { |
halusis | 0:02ed82ccad9f | 20 | Snd2Crr.putc(0xfe); |
halusis | 0:02ed82ccad9f | 21 | Snd2Crr.putc(0xfe); |
halusis | 0:02ed82ccad9f | 22 | Snd2Crr.putc(SigBit); |
halusis | 0:02ed82ccad9f | 23 | Snd2Crr.putc(SigBit); |
halusis | 0:02ed82ccad9f | 24 | Snd2Crr.putc(0xff); |
halusis | 1:d2b6491e52fd | 25 | Snd2Crr.putc(0xff); |
halusis | 1:d2b6491e52fd | 26 | |
halusis | 2:915533cf5d94 | 27 | /* |
halusis | 1:d2b6491e52fd | 28 | //test////////////////// |
halusis | 1:d2b6491e52fd | 29 | if(SigBit&0x80) Led1=1; |
halusis | 1:d2b6491e52fd | 30 | if(SigBit&0x40) Led2=1; |
halusis | 1:d2b6491e52fd | 31 | if(SigBit&0x20) Led3=1; |
halusis | 1:d2b6491e52fd | 32 | if(SigBit&0x10) Led4=1; |
halusis | 1:d2b6491e52fd | 33 | if(SigBit&0x08) Led5=1; |
halusis | 1:d2b6491e52fd | 34 | if(SigBit&0x04) Led6=1; |
halusis | 1:d2b6491e52fd | 35 | if(SigBit&0x02) Led7=1; |
halusis | 1:d2b6491e52fd | 36 | if(SigBit&0x01) Led8=1; |
halusis | 1:d2b6491e52fd | 37 | /////////////////////////// |
halusis | 2:915533cf5d94 | 38 | */ |
halusis | 0:02ed82ccad9f | 39 | } |
halusis | 0:02ed82ccad9f | 40 | |
halusis | 0:02ed82ccad9f | 41 | void ProcCrr(void) {RcvBit=Snd2Crr.getc();} |
halusis | 0:02ed82ccad9f | 42 | |
halusis | 0:02ed82ccad9f | 43 | void Sw1Fn(void) |
halusis | 0:02ed82ccad9f | 44 | { |
halusis | 0:02ed82ccad9f | 45 | if(fSw1==0){fSw1=1;Sw1timer.attach(&Sw1_isr,0.1);} |
halusis | 0:02ed82ccad9f | 46 | else if(fSw1==1){} |
halusis | 0:02ed82ccad9f | 47 | else if(fSw1==2&&Sw1==0) |
halusis | 0:02ed82ccad9f | 48 | { |
halusis | 0:02ed82ccad9f | 49 | fSw1=3; |
halusis | 0:02ed82ccad9f | 50 | if((SigBit&0x80)==0x00){SigBit|=0x80;} |
halusis | 0:02ed82ccad9f | 51 | } |
halusis | 0:02ed82ccad9f | 52 | else fSw1=0; |
halusis | 0:02ed82ccad9f | 53 | } |
halusis | 0:02ed82ccad9f | 54 | void Sw2Fn(void) |
halusis | 0:02ed82ccad9f | 55 | { |
halusis | 0:02ed82ccad9f | 56 | if(fSw2==0){fSw2=1;Sw2timer.attach(&Sw2_isr,0.1);} |
halusis | 0:02ed82ccad9f | 57 | else if(fSw2==1){} |
halusis | 0:02ed82ccad9f | 58 | else if(fSw2==2&&Sw2==0) |
halusis | 0:02ed82ccad9f | 59 | { |
halusis | 0:02ed82ccad9f | 60 | fSw2=3; |
halusis | 0:02ed82ccad9f | 61 | if((SigBit&0x40)==0x00){SigBit|=0x40;} |
halusis | 0:02ed82ccad9f | 62 | } |
halusis | 0:02ed82ccad9f | 63 | else fSw2=0; |
halusis | 0:02ed82ccad9f | 64 | } |
halusis | 0:02ed82ccad9f | 65 | void Sw3Fn(void) |
halusis | 0:02ed82ccad9f | 66 | { |
halusis | 0:02ed82ccad9f | 67 | if(fSw3==0){fSw3=1;Sw3timer.attach(&Sw3_isr,0.1);} |
halusis | 0:02ed82ccad9f | 68 | else if(fSw3==1){} |
halusis | 0:02ed82ccad9f | 69 | else if(fSw3==2&&Sw3==0) |
halusis | 0:02ed82ccad9f | 70 | { |
halusis | 0:02ed82ccad9f | 71 | fSw3=3; |
halusis | 0:02ed82ccad9f | 72 | if((SigBit&0x20)==0x00){SigBit|=0x20; myled1=1;} |
halusis | 0:02ed82ccad9f | 73 | } |
halusis | 0:02ed82ccad9f | 74 | else fSw3=0; |
halusis | 0:02ed82ccad9f | 75 | } |
halusis | 0:02ed82ccad9f | 76 | void Sw4Fn(void) |
halusis | 0:02ed82ccad9f | 77 | { |
halusis | 0:02ed82ccad9f | 78 | if(fSw4==0){fSw4=1;Sw4timer.attach(&Sw4_isr,0.1);} |
halusis | 0:02ed82ccad9f | 79 | else if(fSw4==1){} |
halusis | 0:02ed82ccad9f | 80 | else if(fSw4==2&&Sw4==0) |
halusis | 0:02ed82ccad9f | 81 | { |
halusis | 0:02ed82ccad9f | 82 | fSw4=3; |
halusis | 0:02ed82ccad9f | 83 | if((SigBit&0x10)==0x00){SigBit|=0x10; myled3=1;} |
halusis | 0:02ed82ccad9f | 84 | } |
halusis | 0:02ed82ccad9f | 85 | else fSw4=0; |
halusis | 0:02ed82ccad9f | 86 | } |
halusis | 0:02ed82ccad9f | 87 | void Sw5Fn(void) |
halusis | 0:02ed82ccad9f | 88 | { |
halusis | 0:02ed82ccad9f | 89 | if(fSw5==0){fSw5=1;Sw5timer.attach(&Sw5_isr,0.1);} |
halusis | 0:02ed82ccad9f | 90 | else if(fSw5==1){} |
halusis | 0:02ed82ccad9f | 91 | else if(fSw5==2&&Sw5==0) |
halusis | 0:02ed82ccad9f | 92 | { |
halusis | 0:02ed82ccad9f | 93 | fSw5=3; |
halusis | 0:02ed82ccad9f | 94 | if((SigBit&0x08)==0x00){SigBit|=0x08;} |
halusis | 0:02ed82ccad9f | 95 | } |
halusis | 0:02ed82ccad9f | 96 | else fSw5=0; |
halusis | 0:02ed82ccad9f | 97 | } |
halusis | 0:02ed82ccad9f | 98 | void Sw6Fn(void) |
halusis | 0:02ed82ccad9f | 99 | { |
halusis | 0:02ed82ccad9f | 100 | if(fSw6==0){fSw6=1;Sw6timer.attach(&Sw6_isr,0.1);} |
halusis | 0:02ed82ccad9f | 101 | else if(fSw6==1){} |
halusis | 0:02ed82ccad9f | 102 | else if(fSw6==2&&Sw6==0) |
halusis | 0:02ed82ccad9f | 103 | { |
halusis | 0:02ed82ccad9f | 104 | fSw6=3; |
halusis | 0:02ed82ccad9f | 105 | if((SigBit&0x04)==0x00){SigBit|=0x04;} |
halusis | 0:02ed82ccad9f | 106 | } |
halusis | 0:02ed82ccad9f | 107 | else fSw6=0; |
halusis | 0:02ed82ccad9f | 108 | } |
halusis | 0:02ed82ccad9f | 109 | void Sw7Fn(void) |
halusis | 0:02ed82ccad9f | 110 | { |
halusis | 0:02ed82ccad9f | 111 | if(fSw7==0){fSw7=1;Sw7timer.attach(&Sw7_isr,0.1);} |
halusis | 0:02ed82ccad9f | 112 | else if(fSw7==1){} |
halusis | 0:02ed82ccad9f | 113 | else if(fSw7==2&&Sw7==0) |
halusis | 0:02ed82ccad9f | 114 | { |
halusis | 0:02ed82ccad9f | 115 | fSw7=3; |
halusis | 0:02ed82ccad9f | 116 | if((SigBit&0x02)==0x00){SigBit|=0x02;} |
halusis | 0:02ed82ccad9f | 117 | } |
halusis | 0:02ed82ccad9f | 118 | else fSw7=0; |
halusis | 0:02ed82ccad9f | 119 | } |
halusis | 0:02ed82ccad9f | 120 | void Sw8Fn(void) |
halusis | 0:02ed82ccad9f | 121 | { |
halusis | 0:02ed82ccad9f | 122 | if(fSw8==0){fSw8=1;Sw8timer.attach(&Sw8_isr,0.1);} |
halusis | 0:02ed82ccad9f | 123 | else if(fSw8==1){} |
halusis | 0:02ed82ccad9f | 124 | else if(fSw8==2&&Sw8==0) |
halusis | 0:02ed82ccad9f | 125 | { |
halusis | 0:02ed82ccad9f | 126 | fSw8=3; |
halusis | 0:02ed82ccad9f | 127 | if((SigBit&0x01)==0x00){SigBit|=0x01;} |
halusis | 0:02ed82ccad9f | 128 | } |
halusis | 0:02ed82ccad9f | 129 | else fSw8=0; |
halusis | 0:02ed82ccad9f | 130 | } |
halusis | 0:02ed82ccad9f | 131 | void Sw14Fn(void) |
halusis | 0:02ed82ccad9f | 132 | { |
halusis | 0:02ed82ccad9f | 133 | if(fSw14==0){fSw14=1;Sw14timer.attach(&Sw14_isr,0.1);} |
halusis | 0:02ed82ccad9f | 134 | else if(fSw14==1){} |
halusis | 0:02ed82ccad9f | 135 | else if(fSw14==2&&Sw14==0) |
halusis | 0:02ed82ccad9f | 136 | { |
halusis | 0:02ed82ccad9f | 137 | fSw14=3; |
halusis | 1:d2b6491e52fd | 138 | if((SigBit&0xf0)!=0xf0){SigBit|=0xf0; myled1=1;} |
halusis | 0:02ed82ccad9f | 139 | } |
halusis | 0:02ed82ccad9f | 140 | else fSw14=0; |
halusis | 0:02ed82ccad9f | 141 | } |
halusis | 0:02ed82ccad9f | 142 | void Sw58Fn(void) |
halusis | 0:02ed82ccad9f | 143 | { |
halusis | 0:02ed82ccad9f | 144 | if(fSw58==0){fSw58=1;Sw58timer.attach(&Sw58_isr,0.1);} |
halusis | 0:02ed82ccad9f | 145 | else if(fSw58==1){} |
halusis | 0:02ed82ccad9f | 146 | else if(fSw58==2&&Sw58==0) |
halusis | 0:02ed82ccad9f | 147 | { |
halusis | 0:02ed82ccad9f | 148 | fSw58=3; |
halusis | 1:d2b6491e52fd | 149 | if((SigBit&0x0f)!=0x0f){SigBit|=0x0f; myled2=1;} |
halusis | 0:02ed82ccad9f | 150 | } |
halusis | 0:02ed82ccad9f | 151 | else fSw58=0; |
halusis | 0:02ed82ccad9f | 152 | } |
halusis | 0:02ed82ccad9f | 153 | void SwAllFn(void) |
halusis | 0:02ed82ccad9f | 154 | { |
halusis | 0:02ed82ccad9f | 155 | if(fSwAll==0){fSwAll=1;SwAlltimer.attach(&SwAll_isr,0.1);} |
halusis | 0:02ed82ccad9f | 156 | else if(fSwAll==1){} |
halusis | 0:02ed82ccad9f | 157 | else if(fSwAll==2&&SwAll==0) |
halusis | 0:02ed82ccad9f | 158 | { |
halusis | 0:02ed82ccad9f | 159 | fSwAll=3; |
halusis | 1:d2b6491e52fd | 160 | if((SigBit&0xff)!=0xff){SigBit|=0xff; myled4=1;} |
halusis | 0:02ed82ccad9f | 161 | } |
halusis | 0:02ed82ccad9f | 162 | else fSwAll=0; |
halusis | 0:02ed82ccad9f | 163 | } |
halusis | 0:02ed82ccad9f | 164 | |
halusis | 0:02ed82ccad9f | 165 | void RcvStat(void) |
halusis | 0:02ed82ccad9f | 166 | { |
halusis | 0:02ed82ccad9f | 167 | if(RcvBit&0x80) Led1=1; |
halusis | 0:02ed82ccad9f | 168 | if(RcvBit&0x40) Led2=1; |
halusis | 0:02ed82ccad9f | 169 | if(RcvBit&0x20) Led3=1; |
halusis | 0:02ed82ccad9f | 170 | if(RcvBit&0x10) Led4=1; |
halusis | 0:02ed82ccad9f | 171 | if(RcvBit&0x08) Led5=1; |
halusis | 0:02ed82ccad9f | 172 | if(RcvBit&0x04) Led6=1; |
halusis | 0:02ed82ccad9f | 173 | if(RcvBit&0x02) Led7=1; |
halusis | 0:02ed82ccad9f | 174 | if(RcvBit&0x01) Led8=1; |
halusis | 0:02ed82ccad9f | 175 | } |