Esempio n. 1
0
void LIGHT::light_init()
{
    //pwm initialized outside
    //PWM head(PWM::pwm1, 0);           //PWM for head lights
    //PWM tail(PWM::pwm2, 0);           //PWM for tail lights
    hl_mode=OFF;
    data_rcv.headlights=true;
    head.set(0);
    tail.set(0);
}
Esempio n. 2
0
void LIGHT::chk_light(void)
{
    if(hl_mode_change==true)
    {
        hl_mode_change=false;
        switch(hl_mode)
        {
            case AUTO:
                head.set(100-io_other_snr_data.light);    //Automatic head lights
                tail.set(10);
                break;
            case ON:
                head.set(100);  //Head light On
                tail.set(10);   //Tail light On - DIM
                break;
            case OFF:
                head.set(0);    //Head light Off
                tail.set(0);    //Tail light Off
                break;
            default:
                head.set(0);    //Head light Off
                tail.set(0);    //Tail light Off
                break;
        }
    }
    if(hl_mode==AUTO)
    {
        head.set(100-io_other_snr_data.light);
    }

    if(data_rcv.speed_dir_data==true)
    {
        data_rcv.speed_dir_data=false;
        if(io_speed.brake==SPEED_STOP || io_speed.brake==SPEED_EMERGENCY_STOP )
        {
            //printf("\nI am STOPPED !");
            tail.set(100);
            brake=true;
        }
        else
        {
            brake=false;
        }
        if(io_speed.dir==DIR_REV && brake==false)
        {
            if(flicker==true)   //Tail light blinking
            {
                tail.set(0);
                flicker=false;
            }
            else
            {
                tail.set(100);
                flicker=true;
            }
            //printf("\nI am taking REVERSE !");    //Debugging
        }
        if(io_speed.dir==DIR_FWD && brake==false)
        {
            hl_mode_change=true;                    //Go to default state
            //printf("\nI am going FORWARD !");     //Debugging
        }

    }
    if(data_rcv.chkpt_data==true)
    {
        flick_cnt++;        //Head light blink
        if(flick_cnt%2)
        head.set(100);
        else
        head.set(0);

        if(flick_cnt>=6)
        {
            flick_cnt=0;
            hl_mode_change=true;
            data_rcv.chkpt_data=false;
        }
    }
    if(dest_reached==true)
    {
        if(flicker==true)   //Head and Tail light blinking
        {
            head.set(0);
            tail.set(0);
            flicker=false;
        }
        else
        {
            head.set(100);
            tail.set(100);
            flicker=true;
        }
    }
}