Esempio n. 1
0
void state_diode_idle() {
    state_t next = ST_SLEEP;
    uint16_t time = 0;

    /*** Enter State ***/
    unbeep(); // Silence BEEP
    // Configure IO
    TRISA = 0b00001001; // Set up GP0 (probe) and GP3 (button) as inputs
    LATA = 0b00010000; // Activate bias current for diode test (4k7 series R)
    adc_init(); // Configure ADC

    /*** In State ***/
    while(time < IDLE_TIME) { // Go back to sleep if idling too long
        blink_mode(time&127, 3*16);
        if (check_button()) {
            next = ST_CONTINUITY_IDLE;  // Cycle to next mode
            break;
        } else if (adc_read() < DIODE_TRESHOLD_MAX) {
            next = ST_DIODE_BEEP;
            break;
        }
        time++;
    }

    /*** Exit State ***/
    State = next;
    return;
}
Esempio n. 2
0
void GPO::run()
{
    gpo_config_t prev_config;
    db_gpo->get((int32_t *)&prev_config.i);
  
    bool state = !prev_config.s.period ?
      switch_mode(&prev_config) : blink_mode(&prev_config);
  
    hal->gpio->set(this->GPIOx, this->pin, state);
}
Esempio n. 3
0
void state_continuity_idle() {
    state_t next = ST_SLEEP;
    uint16_t time = 0;

    /*** Enter State ***/
    unbeep(); // Silence BEEP
    // Configure IO
    TRISA = 0b00001001; // Set up GP0 (probe) and GP3 (button) as inputs
    LATA  = 0b00000010; // Activate bias current for cont. test (22k series R)
    adc_init(); // Configure ADC

    /*** In State ***/
    while(time < IDLE_TIME) {  // Go back to sleep if idling too long
        if (State == ST_CONTINUITY_IDLE) {
            blink_mode(time&127, 1*16);
            if (check_button()){
                next = ST_INVERSE_IDLE; // Cycle to next mode
                break;
            } else if (adc_read() < SHORT_TRESHOLD) {
                next = ST_CONTINUITY_BEEP; // Jump immediately (glitch capture)
                break;
            }
        } else { // ST_INVERSE_IDLE
            blink_mode(time&127, 2*16);
            if (check_button()){
                next = ST_DIODE_IDLE; // Cycle to next mode
                break;
            } else if (adc_read() > OPEN_TRESHOLD) {
                next = ST_INVERSE_BEEP; // Jump immediately (glitch capture)
                break;
            }
        }
        time++;
    }
    /*** Exit State ***/
    State = next;
    return;
}