void event_handler( event_type_t event_type, unidata_t unidata ) { uint16_t input_attr = 0; result_t res = EINVAL; if( EV_TYPE_OPEN == event_type ) { /* Геркон разомкнут */ state = GERCON_OPEN; input_attr &= ~GERCON_PIN; attr_write( INPUT, &input_attr ); res = stimer_set( TIMER_NUM, RED_PERIOD ); } else if( EV_TYPE_CLOSE == event_type ) { /* Геркон замкнут */ state = GERCON_CLOSE; input_attr |= GERCON_PIN; attr_write( INPUT, &input_attr ); res = stimer_set( TIMER_NUM, GREEN_PERIOD ); green_count = 0; } else return; port_write( RED_PORT, RED_PIN, PIN_LO ); port_write( GREEN_PORT, GREEN_PIN, PIN_LO ); //if( IS_ERROR(res) ) // port_write( RED_PORT, RED_PIN, PIN_HI ); return; }
void event_handler( event_type_t event_type, unidata_t unidata ) { result_t err; uint64_t cur_time; static uint64_t last_detect_time = 0; DBG("call event_handler"); switch(event_type) { case TIMER_EVENT: if((stage == STAGE_IDLE) ) { stage = STAGE_PYRO; init_adc(); } err = stimer_set(TIMER_0, SHOT_PERIOD ); if( ENOERR != err ) DBG("FAIL: start timer"); break; case ADC12_EVENT: switch(stage) { case STAGE_PYRO: cur_time = sys_time(); unidata <<= 4; if((unidata < MOTION_LO_TH) || (unidata > MOTION_HI_TH)) { // Motion is detected if(cur_MotionState == MOTION_STATE_QUIET) { uint16_t attr = 0; attr_write(0xE2, &attr); } cur_MotionState = MOTION_STATE_ALARM; last_detect_time = cur_time; } else if(cur_MotionState == MOTION_STATE_ALARM) { if((cur_time - last_detect_time) > QUIET_MSG_TIMEOUT) { uint16_t attr = 1; attr_write(0xE2, &attr); cur_MotionState = MOTION_STATE_QUIET; } } middle_point += (unidata - middle_point) >> 8; //unidata = ((uint32_t)3000 * (uint32_t)unidata) / 4095; // Calculation of voltage break; default: stage = STAGE_PYRO; } break; default: DBG("UNKNOW EVENT"); } DBG("return event_handler"); return; }
void event_handler( event_type_t event_type, unidata_t unidata ) { if( event_type == GIOP_INTERRUPT ) { /* Изменилось состояние входов */ #if defined(BLINK_ON) port_t ledpin; port_read( LED_PORT, LED1, &ledpin ); ledpin ^= LED1; port_write( LED_PORT, LED1, ledpin ); #endif #if defined(INVERT_ATTR) unidata = ~unidata; #endif attr_write( INPUT, &unidata ); } else if( event_type == EV_AWRITTEN ){ if( unidata == OUTPUT ) { /* Изменён атрибут цифровых выходов */ port_t out; result_t res = attr_read( OUTPUT, &out ); if( IS_OK(res) ) { /* Записываем в порт новое значение атрибута */ port_write( OPORT, OPINS, out ); } #if defined(BLINK_ON) port_t ledpin; port_read( LED_PORT, LED2, &ledpin ); ledpin ^= LED2; port_write( LED_PORT, LED2, ledpin ); #endif } } return; }
void write_vga_register(register_set_t target, uint8_t index, uint8_t value) { switch(target) { case GRAPHIC_CTRL: gctrl_write(index, value); break; case SEQUENCER: seq_write(index, value); break; case ATTRIBUTE_CTRL: attr_write(index, value); break; case CRT_CTRL: crtc_write(index, value); break; case EXTERNAL_REGISTERS: switch(index) { case MISC_OUTPUT_REGISTER: misc_output_write(value); break; case FEATURE_CONTROL_REGISTER: feature_control_write(value); break; } break; default: break; } }