/** * @brief Timer event handler for the capacitive sensor. * * @param[in] p_context General purpose pointer. Will be passed to the time-out handler * when the timer expires. * */ static void csense_timeout_handler(void * p_context) { ret_code_t err_code; err_code = nrf_drv_csense_sample(); if (err_code != NRF_SUCCESS) { NRF_LOG_INFO("Busy.\r\n"); return; } }
/** * @brief Function for handling conversion values. * * @param[in] val Value received from ADC or COMP. */ static void conversion_handler(uint16_t val) { nrf_drv_csense_evt_t event_struct; #if USE_COMP == 0 nrf_gpio_pin_set(m_csense.output_pin); #endif //USE_COMP m_csense.analog_values[m_csense.cur_chann_idx] = val; event_struct.read_value = val; event_struct.analog_channel = m_csense.cur_chann_idx; m_csense.channels_to_read &= ~(1UL<<m_csense.cur_chann_idx); // decide if there will be more conversions if(m_csense.channels_to_read == 0) { m_csense.busy = false; #if USE_COMP == 0 && defined(SAADC_PRESENT) nrf_saadc_disable(); #endif } m_csense.event_handler(&event_struct); if(m_csense.channels_to_read > 0) // Start new conversion. { ret_code_t err_code; calculate_next_channel(); err_code = nrf_drv_csense_sample(); if(err_code != NRF_SUCCESS) { return; } } }
/** * @brief Function for configuring pads threshold. */ void configure_thresholds(void) { ret_code_t err_code; uint32_t new_th_pad_1; uint32_t new_th_pad_2; for (int i = 0; i < 2; i++) { max_value[i] = 0; min_value[i] = UINT32_MAX; } NRF_LOG_INFO("Touch both pads.\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("3...\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("2...\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("1...\r\n"); NRF_LOG_FLUSH(); err_code = nrf_drv_csense_sample(); if (err_code != NRF_SUCCESS) { NRF_LOG_INFO("Busy.\n"); return; } while (nrf_drv_csense_is_busy()); NRF_LOG_INFO("Release both pads.\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("3...\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("2...\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(1000); NRF_LOG_INFO("1...\r\n"); NRF_LOG_FLUSH(); err_code = nrf_drv_csense_sample(); if (err_code != NRF_SUCCESS) { NRF_LOG_INFO("Busy.\n"); return; } while (nrf_drv_csense_is_busy()); nrf_delay_ms(100); new_th_pad_1 = max_value[PAD_ID_0]; new_th_pad_1 += min_value[PAD_ID_0]; new_th_pad_1 /= 2; new_th_pad_2 = max_value[PAD_ID_1]; new_th_pad_2 += min_value[PAD_ID_1]; new_th_pad_2 /= 2; threshold_value_pad1 = new_th_pad_1; threshold_value_pad2 = new_th_pad_2; NRF_LOG_INFO("New thresholds, AIN1: %d, AIN7: %d.\r\n", (unsigned int)new_th_pad_1, (unsigned int)new_th_pad_2); }