/**@brief Function for handling button presses. */ static void button_event_handler(uint8_t pin_no) { static uint8_t send_push = 1; uint32_t err_code; uart_tx_status_code("event pin #", pin_no, 0); switch (pin_no) { case LEDBUTTON_BUTTON_PIN_NO: err_code = ble_lbs_on_button_change(&m_lbs, send_push); //err_code = NRF_SUCCESS; if (err_code != NRF_SUCCESS && err_code != BLE_ERROR_INVALID_CONN_HANDLE && err_code != NRF_ERROR_INVALID_STATE) { uart_tx_status_code("reset @ err. code #:", err_code, 0); err_code = sd_power_system_off(); APP_ERROR_CHECK(err_code); } send_push = !send_push; break; default: break; } }
static void button_event_handler(uint8_t pin_no, uint8_t button_action) { uint32_t err_code; switch (pin_no) { case LEDBUTTON_BUTTON_PIN_NO: err_code = ble_lbs_on_button_change(&m_lbs, button_action); if (err_code != NRF_SUCCESS && err_code != BLE_ERROR_INVALID_CONN_HANDLE && err_code != NRF_ERROR_INVALID_STATE) { APP_ERROR_CHECK(err_code); } break; default: APP_ERROR_HANDLER(pin_no); break; } }
// Function to decode IR signals and message to web if the car is hit void ir_in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { static uint8_t decoded = 0; static uint8_t offset = 0; static uint32_t prev = 0; if(offset >= 8) offset = 0; uint32_t usec = nrf_drv_timer_capture(&ir_timer, NRF_TIMER_CC_CHANNEL0); if(offset) SEGGER_RTT_printf(0, "%d\r\n", usec - prev); if((usec - prev) > 2000) { decoded += (1 << (offset - 1)); } if(offset == 7) { SEGGER_RTT_printf(0, "\r\n\n%d\n\r\n", decoded); new_hit_value(); if(decoded != unique_car_ID && decoded >= 1 && decoded <= 16) { ble_lbs_on_button_change(&m_lbs, hit_counter, 0); playNote(1516); nrf_delay_ms(50); playNote(1607); } decoded = 0; } prev = usec; offset++; }
static void pin_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action){ //if(pin == IR_RECEIVER_PIN_1 || pin == IR_RECEIVER_PIN_2 || pin == IR_RECEIVER_PIN_3){ /*hit_counter = new_hit_value(); playNote(1516); nrf_delay_ms(50); playNote(1607);*/ /* if(pin == IR_RECEIVER_PIN_1) { ir_in_pin_handler(pin, action); //ble_lbs_on_button_change(&m_lbs, hit_counter, 0); } else if(pin == IR_RECEIVER_PIN_2) ble_lbs_on_button_change(&m_lbs, hit_counter, 1); else if(pin == IR_RECEIVER_PIN_3) ble_lbs_on_button_change(&m_lbs, hit_counter, 2); }*/ if(pin == RFID_INTERRUPT_PIN) { ble_lbs_on_button_change(&m_lbs, rfid_counter, 4); if(rfid_counter % 20 == 0){ playNote(1072); set_rgb_color(2); nrf_delay_ms(10); playNote(1012); set_rgb_color(1); nrf_delay_ms(10); playNote(955); set_rgb_color(2); nrf_delay_ms(10); playNote(901); set_rgb_color(0); } rfid_counter = rfid_read_event_handler(); } }