void handle_tempo_tap( ClickRecognizerRef recognizer, Window* win ) { if( measuring_tempo ) { // This is in 1ms units. uint32_t tap_time = hw_timer_get_time(); uint32_t tap_interval = tap_time - last_tap_time; last_tap_time = tap_time; // Push num ticks, calc curr and avg tempo. if( num_tap_intervals < MAX_TAP_INTERVALS ) { tap_intervals[num_tap_intervals++] = tap_interval; } else { uint32_t sum = tap_intervals[0]; uint32_t avg; for( int t = 1; t < MAX_TAP_INTERVALS; t++ ) { sum += tap_intervals[t]; tap_intervals[t-1] = tap_intervals[t]; } tap_intervals[MAX_TAP_INTERVALS-1] = tap_interval; avg = sum / 4; avg_tempo = 60000 / avg; snprintf( avg_tempo_str, 4, "%d", avg_tempo ); text_layer_set_text( &avg_tempo_lay, avg_tempo_str ); } if( num_tap_intervals > 1 ) { curr_tempo = 60000 / tap_interval; snprintf( curr_tempo_str, 4, "%d", curr_tempo ); text_layer_set_text( &curr_tempo_lay, curr_tempo_str ); } } else { num_tap_intervals = 0; hw_timer_start(); last_tap_time = hw_timer_get_time(); text_layer_set_text( &measuring_lay, measuring_active_str ); layer_set_hidden( (Layer*) &measuring_inverter_lay, false ); memset( tap_intervals, 0, ARRAY_LENGTH(tap_intervals) * sizeof(*tap_intervals) ); measuring_tempo = true; } stop_measuring_timer = app_timer_send_event( my_ctx, STOP_MEASURING_TIMEOUT, 0 ); }
void ir_tx_handler()//u8 ir_tx_addr, u8 ir_tx_data,u16 ir_tx_rep) { u32 t_expire=0; static u32 rep_expire_us=110000;//for nec 32bit mode static u16 data_tmp=0; static u8 ir_tx_bit_num=0; static u8 ir_bit_state=TX_BIT_CARRIER; #if IR_TX_STATUS_MACHINE_HW_TIMER hw_timer_stop(); #else os_timer_disarm(&ir_tx_timer); #endif switch(ir_tx_state) { case IR_TX_IDLE: { gen_carrier_clk(); ir_tx_state = IR_TX_HEADER; #if IR_TX_STATUS_MACHINE_HW_TIMER hw_timer_arm(IR_NEC_HEADER_HIGH_US); hw_timer_start(); #else os_timer_arm_us(&ir_tx_timer, IR_NEC_HEADER_HIGH_US, 0);//143 9ms #endif break; } case IR_TX_HEADER: { ir_tx_carrier_clr(); #if IR_TX_STATUS_MACHINE_HW_TIMER hw_timer_arm(IR_NEC_HEADER_LOW_US); hw_timer_start(); #else os_timer_arm_us(&ir_tx_timer, IR_NEC_HEADER_LOW_US, 0);//71 ,4.5ms #endif ir_tx_state=IR_TX_DATA; ir_bit_state=TX_BIT_CARRIER; data_tmp=ir_tx_addr; rep_expire_us-=13500; break; } case IR_TX_DATA: { if(ir_bit_state==TX_BIT_CARRIER){ t_expire=IR_NEC_DATA_HIGH_US; ir_bit_state=TX_BIT_LOW; gen_carrier_clk(); }else if(ir_bit_state==TX_BIT_LOW){ ir_tx_carrier_clr(); if( (data_tmp>>(ir_tx_bit_num% IR_NEC_BIT_NUM ))&0x1){ t_expire=IR_NEC_DATA_LOW_1_US; } else{ t_expire=IR_NEC_DATA_LOW_0_US; } ir_tx_bit_num++; if(ir_tx_bit_num==IR_NEC_BIT_NUM ){ if(ir_tx_standard) data_tmp=(~ir_tx_addr); else data_tmp = ir_tx_addr2; }else if(ir_tx_bit_num==IR_NEC_BIT_NUM*2 ){ if(ir_tx_standard) data_tmp=ir_tx_cmd; else data_tmp=ir_tx_cmd; }else if(ir_tx_bit_num==IR_NEC_BIT_NUM*3){ if(ir_tx_standard) data_tmp=(~ir_tx_cmd); else data_tmp=ir_tx_cmd2; }else if((ir_tx_bit_num==(IR_NEC_BIT_NUM*4+1))){ //clean up state for next or for repeat ir_tx_state=IR_TX_IDLE; ir_tx_bit_num=0; ir_bit_state=TX_BIT_CARRIER; #if IR_TX_STATUS_MACHINE_HW_TIMER hw_timer_stop(); #else os_timer_disarm(&ir_tx_timer); #endif if(ir_tx_rep>0){ t_expire= (rep_expire_us -5); #if IR_TX_STATUS_MACHINE_HW_TIMER hw_timer_arm(t_expire); hw_timer_start(); #else os_timer_arm_us(&ir_tx_timer, t_expire, 0);//71 #endif rep_expire_us=IR_NEC_REP_CYCLE; ir_tx_state=IR_TX_REP; }else{ rep_expire_us=IR_NEC_REP_CYCLE; ir_tx_state=IR_TX_IDLE; } break; } ir_bit_state=TX_BIT_CARRIER; }else{ }