Grenade Drone Controller

Dependencies:   mbed

SwitchFn/SwitchFn.cpp

Committer:
halusis
Date:
2018-08-20
Revision:
2:915533cf5d94
Parent:
1:d2b6491e52fd

File content as of revision 2:915533cf5d94:

#include "SwitchFn.h"
#include "PinAssign.h"
#include "GlobalVars.h"

Timeout Sw1timer,Sw2timer,Sw3timer,Sw4timer,Sw5timer,Sw6timer,Sw7timer,Sw8timer,Sw14timer,Sw58timer,SwAlltimer;
void Sw1_isr(void){fSw1++;}
void Sw2_isr(void){fSw2++;}
void Sw3_isr(void){fSw3++;}
void Sw4_isr(void){fSw4++;}
void Sw5_isr(void){fSw5++;}
void Sw6_isr(void){fSw6++;}
void Sw7_isr(void){fSw7++;}
void Sw8_isr(void){fSw8++;}
void Sw14_isr(void){fSw14++;}
void Sw58_isr(void){fSw58++;}
void SwAll_isr(void){fSwAll++;}

void Send2Crr(void)
{
    Snd2Crr.putc(0xfe);
    Snd2Crr.putc(0xfe);
    Snd2Crr.putc(SigBit);
    Snd2Crr.putc(SigBit);
    Snd2Crr.putc(0xff);
    Snd2Crr.putc(0xff);
    
    /*
    //test//////////////////
    if(SigBit&0x80) Led1=1;
    if(SigBit&0x40) Led2=1;
    if(SigBit&0x20) Led3=1;
    if(SigBit&0x10) Led4=1;
    if(SigBit&0x08) Led5=1;
    if(SigBit&0x04) Led6=1;
    if(SigBit&0x02) Led7=1;
    if(SigBit&0x01) Led8=1;
    ///////////////////////////
    */
}

void ProcCrr(void) {RcvBit=Snd2Crr.getc();}

void Sw1Fn(void)
{
    if(fSw1==0){fSw1=1;Sw1timer.attach(&Sw1_isr,0.1);}
    else if(fSw1==1){}
    else if(fSw1==2&&Sw1==0)
    {
        fSw1=3;
        if((SigBit&0x80)==0x00){SigBit|=0x80;}
    }
    else fSw1=0;
}
void Sw2Fn(void)
{
    if(fSw2==0){fSw2=1;Sw2timer.attach(&Sw2_isr,0.1);}
    else if(fSw2==1){}
    else if(fSw2==2&&Sw2==0)
    {
        fSw2=3;
        if((SigBit&0x40)==0x00){SigBit|=0x40;}
    }
    else fSw2=0;
}
void Sw3Fn(void)
{
    if(fSw3==0){fSw3=1;Sw3timer.attach(&Sw3_isr,0.1);}
    else if(fSw3==1){}
    else if(fSw3==2&&Sw3==0)
    {
        fSw3=3;
        if((SigBit&0x20)==0x00){SigBit|=0x20; myled1=1;}
    }
    else fSw3=0;
}
void Sw4Fn(void)
{
    if(fSw4==0){fSw4=1;Sw4timer.attach(&Sw4_isr,0.1);}
    else if(fSw4==1){}
    else if(fSw4==2&&Sw4==0)
    {
        fSw4=3;
        if((SigBit&0x10)==0x00){SigBit|=0x10; myled3=1;}
    }
    else fSw4=0;
}
void Sw5Fn(void)
{
    if(fSw5==0){fSw5=1;Sw5timer.attach(&Sw5_isr,0.1);}
    else if(fSw5==1){}
    else if(fSw5==2&&Sw5==0)
    {
        fSw5=3;
        if((SigBit&0x08)==0x00){SigBit|=0x08;}
    }
    else fSw5=0;
}
void Sw6Fn(void)
{
    if(fSw6==0){fSw6=1;Sw6timer.attach(&Sw6_isr,0.1);}
    else if(fSw6==1){}
    else if(fSw6==2&&Sw6==0)
    {
        fSw6=3;
        if((SigBit&0x04)==0x00){SigBit|=0x04;}
    }
    else fSw6=0;
}
void Sw7Fn(void)
{
    if(fSw7==0){fSw7=1;Sw7timer.attach(&Sw7_isr,0.1);}
    else if(fSw7==1){}
    else if(fSw7==2&&Sw7==0)
    {
        fSw7=3;
        if((SigBit&0x02)==0x00){SigBit|=0x02;}
    }
    else fSw7=0;
}
void Sw8Fn(void)
{
    if(fSw8==0){fSw8=1;Sw8timer.attach(&Sw8_isr,0.1);}
    else if(fSw8==1){}
    else if(fSw8==2&&Sw8==0)
    {
        fSw8=3;
        if((SigBit&0x01)==0x00){SigBit|=0x01;}
    }
    else fSw8=0;
}
void Sw14Fn(void)
{
    if(fSw14==0){fSw14=1;Sw14timer.attach(&Sw14_isr,0.1);}
    else if(fSw14==1){}
    else if(fSw14==2&&Sw14==0)
    {
        fSw14=3;
        if((SigBit&0xf0)!=0xf0){SigBit|=0xf0; myled1=1;}
    }
    else fSw14=0;
}
void Sw58Fn(void)
{
    if(fSw58==0){fSw58=1;Sw58timer.attach(&Sw58_isr,0.1);}
    else if(fSw58==1){}
    else if(fSw58==2&&Sw58==0)
    {
        fSw58=3;
        if((SigBit&0x0f)!=0x0f){SigBit|=0x0f; myled2=1;}
    }
    else fSw58=0;   
}
void SwAllFn(void)
{
    if(fSwAll==0){fSwAll=1;SwAlltimer.attach(&SwAll_isr,0.1);}
    else if(fSwAll==1){}
    else if(fSwAll==2&&SwAll==0)
    {
        fSwAll=3;
        if((SigBit&0xff)!=0xff){SigBit|=0xff; myled4=1;}
    }
    else fSwAll=0; 
}

void RcvStat(void)
{
    if(RcvBit&0x80) Led1=1;
    if(RcvBit&0x40) Led2=1;
    if(RcvBit&0x20) Led3=1;
    if(RcvBit&0x10) Led4=1;
    if(RcvBit&0x08) Led5=1;
    if(RcvBit&0x04) Led6=1;
    if(RcvBit&0x02) Led7=1;
    if(RcvBit&0x01) Led8=1;
}