Ejemplo n.º 1
0
void irkit_http_loop() {
#ifdef USE_INTERNET
    // long poll
    if (TIMER_FIRED(polling_timer)) {
        TIMER_STOP(polling_timer);

        if (TIMER_RUNNING(suspend_polling_timer)) {
            // suspend GET /m for a while if we have received a POST /messages request from client
            // client is in wifi, we can ignore our server for a while
            TIMER_START(polling_timer, SUSPEND_GET_MESSAGES_INTERVAL);
        }
        else {
            int8_t result = irkit_httpclient_get_messages();
            if ( result < 0 ) {
                HTTPLOG_PRINTLN("!E3");
                // maybe time cures GS? (no it doesn't, let's hardware reset, software reset doesn't work here)
                // don't software reset AVR, because that cuts off serial logging (for debug purpose only)
                wifi_hardware_reset();
            }
            else {
                polling_cid = result;
            }
        }
    }

    if (TIMER_FIRED(suspend_polling_timer)) {
        TIMER_STOP(suspend_polling_timer);
    }
#endif
}
Ejemplo n.º 2
0
uint8_t GSwifi::checkActivity() {
    static uint8_t continuous_timeouts_ = 0;

    while ( serial_->available() &&
            ! TIMER_FIRED(timeout_timer_) ) {

        parseByte( serial_->read() );

        if ( gs_failure_ ||
             (gs_ok_ &&
              (gs_response_lines_ == RESPONSE_LINES_ENDED ||
               gs_commandmode_    == GSCOMMANDMODE_NONE)) ) {
            gs_commandmode_      = GSCOMMANDMODE_NONE;
            continuous_timeouts_ = 0;
            setBusy(false);
            break;
        }
    }

    if ( busy_ &&
         TIMER_FIRED(timeout_timer_) ) {
        TIMER_STOP(timeout_timer_);
        GSLOG_PRINTLN("!E24");
        did_timeout_          = true;
        continuous_timeouts_ ++;
        setBusy(false);
    }

    // need a GS hardware reset, which we issue in setup()
    ASSERT( continuous_timeouts_ <= 5 );

    return busy_;
}
Ejemplo n.º 3
0
void long_press_button_ontimer( struct long_press_button_state_t* state ) {
    static uint8_t button_state = BUTTON_OFF;

    uint8_t next_button_state = digitalRead( state->pin );

    if ((BUTTON_OFF == button_state) &&
            (BUTTON_ON  == next_button_state)) {
        // OFF -> ON
        TIMER_START( state->timer, state->threshold_time );
    }
    else if ((BUTTON_ON == button_state) &&
             (BUTTON_ON == next_button_state)) {
        // still pressing

        TIMER_TICK( state->timer );

        if (TIMER_FIRED( state->timer )) {
            state->callback();

            // fires again after state->threshold_time
            button_state = BUTTON_OFF;
            return;
        }
    }

    button_state = next_button_state;
}
Ejemplo n.º 4
0
void IR_timer (void)
{
    if (IrCtrl.state == IR_RECVING) {
        TIMER_TICK( IrCtrl.recv_timer );

        if ( TIMER_FIRED( IrCtrl.recv_timer ) ) {
            TIMER_STOP( IrCtrl.recv_timer );
            IR_state( IR_RECVED );
        }
    }

    if (IrCtrl.state == IR_XMITTING) {
        TIMER_TICK( IrCtrl.xmit_timer );

        if ( TIMER_FIRED( IrCtrl.xmit_timer ) ) {
            TIMER_STOP( IrCtrl.xmit_timer );
            IR_state( IR_IDLE );
        }
    }
}
Ejemplo n.º 5
0
void GSwifi::loop() {
    TIMER_STOP( timeout_timer_ );

    checkActivity();

    for (uint8_t i=0; i<16; i++) {
        if (! cidIsRequest(i) &&
            TIMER_FIRED(timers_[i])) {
            TIMER_STOP(timers_[i]);

            GSLOG_PRINT("!E4 "); GSLOG_PRINTLN(i);

            // request (from us) timeout means GS is in trouble,
            // and it's easy to just rescue ourselves to reset
            wifi_hardware_reset();
            return;
        }
    }
}