Ejemplo n.º 1
0
void door_init(void)
{
    door_doorstate = 0;

    PIN_CLEAR(DOOR_HBRIDGE_ENABLE);
    PIN_CLEAR(DOOR_HBRIDGE_IN1);
    PIN_CLEAR(DOOR_HBRIDGE_IN2);
   
    DDR_CONFIG_OUT(DOOR_HBRIDGE_ENABLE);
    DDR_CONFIG_OUT(DOOR_HBRIDGE_IN1);
    DDR_CONFIG_OUT(DOOR_HBRIDGE_IN2);

    locking = false;
    unlocking = false;
#if 0    
    int i;
    while(1){
        door_turnLeft();
        for(i=0; i<25; i++) _delay_ms(1);
        while(1){
            for(i=0; i<5; i++) _delay_ms(1);
            if(adc_getChannel(7) > 1000) {
                break;
            }
        }
        door_stop();
        for(i=0; i<1000; i++) _delay_ms(1);
        door_turnRight();
        for(i=0; i<25; i++) _delay_ms(1);
        while(1){
            for(i=0; i<5; i++) _delay_ms(1);
            if(adc_getChannel(7) > 1000) {
                break;
            }
        }
        door_stop();
        for(i=0; i<1000; i++) _delay_ms(1);
    }
#endif
}
Ejemplo n.º 2
0
static void door_startUnlock(void)
{
    int i;
    door_turnLeft();
    for(i=0; i<30; i++) _delay_ms(1);
    if(adc_getChannel(7) > 1000) {
        door_stop();
        return;
    }
    unlocking = true;
    locking = false;
    locked = false;
    unlocked = false;
}
Ejemplo n.º 3
0
void door_tick(void)
{
    door_update_inputs();
    if( door_desiredState == DOOR_LOCK_LOCKED && !locking && !locked ){
        door_startLock();
    }else if( door_desiredState == DOOR_LOCK_UNLOCKED && !unlocking && !unlocked){
        door_startUnlock();
    }

    if(adc_getChannel(7) > 1000) {
        door_stop();
        if(locking) {
            locking = false;
            locked = true;
            unlocked = false;
        }
        if(unlocking) {
            unlocking = false;
            unlocked = true;
            locked = false;
        }
    }
}
Ejemplo n.º 4
0
static void power_update(void)
{
    power_inputVoltage = adc_getChannel(POWER_INPUT_VOLTAGE_CHANNEL); 
    power_inputVoltage *= 11;
}
Ejemplo n.º 5
0
/** main function
 */
int main(void) {
//    SPCR &= ~(1<<SPE);
//    TIMSK0 &= ~(1<<TOIE1);
    wdt_disable();
    /* Clear WDRF in MCUSR */
    MCUSR &= ~(1<<WDRF);
    /* Write logical one to WDCE and WDE */
    /* Keep old prescaler setting to prevent unintentional time-out */
    WDTCSR |= (1<<WDCE) | (1<<WDE);
    /* Turn off WDT */
    WDTCSR = 0x00;
    //volatile long l;
//    for(l=0;l<1000000;l++);
    DDR_CONFIG_IN(CONFIG1);
    PIN_SET(CONFIG1);
    wdt_enable(WDTO_2S);
    wdt_reset();
    volatile unsigned long l;     
    for(l=0;l<10;l++);

    if( !PIN_HIGH(CONFIG1) ){
        global.config = 30;
    }else{
        global.config = 21;
    }
    
    leds_init();

    wdt_reset();
    if( global.config == 21 ){
        DDR_CONFIG_IN(JUMPER1C1);
        PIN_SET(JUMPER1C1);
    }else if( global.config == 30 ){
        DDR_CONFIG_IN(JUMPER1C2);
        PIN_SET(JUMPER1C2);
        adc_init();
        uint16_t bat = adc_getChannel(6);
        if( bat < ADC_MINBATIDLE ){
            //global.flags.lowbat = 1;
        }
    }
    
    wdt_reset();
    init_pwm();
#if SERIAL_UART
    uart1_init( UART_BAUD_SELECT(UART_BAUDRATE,F_CPU));
    stdout = &mystdout;
#endif

#if RC5_DECODER
    rc5_init();
#endif

    wdt_reset();
#if STATIC_SCRIPTS
    init_script_threads();
#endif
    settings_read();
    //if((global.config == 21 && !PIN_HIGH(JUMPER1C1)) || (global.config== 30 && !PIN_HIGH(JUMPER1C2)))
    //    interfaces_setEnabled(IFACE_RF,0);

    control_init();

    wdt_reset();
#if RS485_CTRL
    rs485_init();
    zbus_core_init();
#endif
    //rf_init();
    packet_init(idbuf[0],0);

    wdt_reset();
    srandom(random_seed);
    random_seed = random();

    /* enable interrupts globally */
    sei();
//    global.state = STATE_RUNNING;
//    global.state = STATE_PAUSE;
//    global.flags.running = 0;
    while (1) {
        wdt_reset();
        //leds_main();

        #if 1
        packet_tick();
        #else
        if(packetbase ){//> 32){
            packetbase = 0;

            packet_tick();
            //if(main_reset++ > 16000)
            //    jump_to_bootloader(); 
            //uint16_t bat = adc_getChannel(6);
            /*if( bat < ADC_MINBATIDLE ){
                global.flags.lowbat = 1;
            }*/
        }
        #endif
        //if( global.flags.lowbat ){
        //    control_lowbat();
        //}

        if( global.flags.timebase ){
            //control_tick();
            global.flags.timebase=0;
        }
        /* after the last pwm timeslot, rebuild the timeslot table */
        
        //if (global.flags.last_pulse) {
        //    global.flags.last_pulse = 0;
            //if(global.flags.running)
            //update_pwm_timeslots();
        //}
        /* at the beginning of each pwm cycle, call the fading engine and
         * execute all script threads */
        if (global.flags.new_cycle) {
            global.flags.new_cycle = 0;
            if(control_faderunning)
                update_brightness();

            if(global.flags.running){
#if STATIC_SCRIPTS
//                execute_script_threads();
#endif
            }
            //continue;
        }
#if RC5_DECODER
#endif
#if RS485_CTRL
        rs485_process();
#endif
#if SERIAL_UART
//serial_process();
#endif
    }
}
Ejemplo n.º 6
0
uint8_t cmd_handler(uint8_t cmd, uint8_t * param, uint8_t * result)
{
   if(cmd == CMD_BRIGHTNESS_DOWN){
        if(global_pwm.dim > 0){
            global_pwm.dim--;
        }
    }else if(cmd == CMD_BRIGHTNESS_UP){
        if(global_pwm.dim < 255){
            global_pwm.dim++;
        }
    }else if(cmd == CMD_FULL_BRIGHTNESS){
        global_pwm.dim=255;
    }else if(cmd == CMD_ZERO_BRIGHTNESS){
        global_pwm.dim=0;
    }else if(cmd == CMD_POWER){
        if(global.state != STATE_STANDBY){
            global.nextstate = global.state;
            if(global.nextstate == STATE_SLEEP)
                global.nextstate = STATE_RUNNING;
            //global.state = STATE_ENTERSTANDBY;
            control_standby(0);
        }else{
            global.state = STATE_LEAVESTANDBY;
        }
    }else if(cmd == CMD_SET_SCRIPT){
        if(sizeof(global_playlist)/(sizeof(struct playlist_t)) > param[0])
                cmd_setscript(
                    global_playlist[param[0]].execute, global_playlist[param[0]].position);
    }else if(cmd == CMD_FASTER){
        if(script_threads[0].speed_adjustment < 8){
            script_threads[0].speed_adjustment++;
            respeed(&script_threads[0]);
            //update_brightness();
            //execute_script_threads();
        }

    }else if(cmd == CMD_SLOWER){
        if(script_threads[0].speed_adjustment > -8){
            script_threads[0].speed_adjustment--;
            respeed(&script_threads[0]);
            //update_brightness();
            //execute_script_threads();
        }
    }else if(cmd == CMD_PAUSE){
        if(global.state != STATE_PAUSE)
            global.state = STATE_PAUSE;
        else
            global.state = STATE_RUNNING;
    }else if(cmd == CMD_SAVE){
        settings_save();
    }else if(cmd == CMD_SLEEP){
        global.state = STATE_ENTERSLEEP;
    }else if(cmd == CMD_RED){
        global_pwm.channel_modifier = 0;
    }else if(cmd == CMD_GREEN){
        global_pwm.channel_modifier = 1;
    }else if(cmd == CMD_BLUE){
        global_pwm.channel_modifier = 2;
    }else if(cmd == CMD_COLOR_UP){
        global_pwm.channels[global_pwm.channel_modifier].brightness++;
    }else if(cmd == CMD_COLOR_DOWN){
        global_pwm.channels[global_pwm.channel_modifier].brightness--;
    }else if(cmd == CMD_COLOR_FULL){
        global_pwm.channels[global_pwm.channel_modifier].brightness=255;
    }else if(cmd == CMD_COLOR_ZERO){
        global_pwm.channels[global_pwm.channel_modifier].brightness=0;
    }else if(cmd == CMD_GET_VERSION){
        //strcpy((char *) result,"D=");
        //strcat((char *) result,__DATE__);
        //strcat((char *) result,"H=");

        //strcpy((char *) result, "D="__DATE__"H=");
        //strcat((char *) result,__DATE__);
        if( result == NULL ) return 0;
        sprintf((char *)result,"D="__DATE__" H=%d",global.config);
        return strlen((char *)result);
    }else if(cmd == CMD_GET_STATE){
        if( result == NULL ) return 0;
        result[0] = global.state;
        result[1] = script_threads[0].speed_adjustment;
        result[2] = global_pwm.dim;
        return 3;
    }else if(cmd == CMD_SET_SPEED){
        script_threads[0].speed_adjustment = param[0]; 
    }else if(cmd == CMD_SET_STATE){
        global.state = param[0];
    }else if(cmd == CMD_SET_BRIGHTNESS){
        global_pwm.dim = param[0];
    }else if(cmd == CMD_SET_COLOR){
        control_setColor(param[0],param[1],param[2]);
    }else if(cmd == CMD_RESET){
        jump_to_bootloader();
    }else if(cmd == CMD_FADE){
        uint16_t speed = (param[3]<<8)+param[4];
        control_fade(param[0],param[1],param[2],speed);
    }else if(cmd == CMD_FADEMS){
        uint16_t time = (param[3]<<8)+param[4];
        control_fadems(param[0],param[1],param[2],time);
    }else if(cmd == CMD_FADEMSALT){
        uint16_t time = (param[3]<<8)+param[4];
        control_fademsalt(param[0],param[1],param[2],time);
    }else if(cmd == CMD_GET_VOLTAGE){
        if( result == NULL ) return 0;
        uint16_t adc = adc_getChannel(6);
        sprintf((char *)result,"V=%u",adc);
        return strlen((char *)result);
    }else if(cmd == CMD_GET_COLOR){
        if( result == NULL ) return 0;
        result[0] = global_pwm.channels[0].brightness;
        result[1] = global_pwm.channels[1].brightness;
        result[2] = global_pwm.channels[2].brightness;
        return 3;
    }else if(cmd == CMD_FLASH){
        uint16_t time = (param[3]<<8)+param[4];
        control_flash(param[0],param[1],param[2],time);
    }
    return 0;
}