int app_batt_timer_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { #ifndef CUSTOM_BATTERY_LEVEL_MEASUREMENTS app_batt_lvl(); #else app_batt_lvl_custom(BATTERY_TYPE_USED, BATTERY_ALERT_AT_PERCENTAGE_LEFT); #endif app_timer_set(APP_BATT_TIMER, dest_id, bat_poll_timeout); return (KE_MSG_CONSUMED); }
void app_proxr_alert_start(uint8_t lvl) { alert_state.lvl = lvl; if (alert_state.lvl == PROXR_ALERT_MILD) alert_state.blink_timeout = 50; else alert_state.blink_timeout = 50; alert_state.blink_toggle = 1; GPIO_SetActive( alert_state.port, alert_state.pin); app_timer_set(APP_PXP_TIMER, TASK_APP, alert_state.blink_timeout); }
/** **************************************************************************************** * @brief Handles Battery Alert timer * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ int app_batt_alert_timer_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { //Read LED GPIO state if(bat_lvl_alert_used) { if (bat_led_state) { GPIO_SetInactive( bat_led_port, bat_led_pin); bat_led_state = 0; app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 20); } else { GPIO_SetActive( bat_led_port, bat_led_pin); bat_led_state = 1; app_timer_set(APP_BATT_ALERT_TIMER, dest_id, 5); } } return (KE_MSG_CONSUMED); }
/** **************************************************************************************** * @brief Handles APP_SAMPLING_TIMER's expiration message. Samples ADC and writes value to characteristic. * * @param[in] msgid Id of the message received. * @param[in] param Pointer to the parameters of the message. * @param[in] dest_id ID of the receiving task instance (TASK_GAP). * @param[in] src_id ID of the sending task instance. * * @return If the message was consumed or not. **************************************************************************************** */ int app_adc_sampling_timer_handler(ke_msg_id_t const msgid, void *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { adc_init(GP_ADC_SE, ADC_POLARITY_UNSIGNED); // Single ended mode adc_enable_channel(ADC_CHANNEL_P01); // app_adc_notify_upd_char(SWAP(adc_get_sample())); app_timer_set(APP_ADC_SAMPLING_TIMER, TASK_APP, APP_ADC_SAMPLING_TIMEOUT); //5 sec return (KE_MSG_CONSUMED); }
int app_adc_notify_cfg_ind_handler(ke_msg_id_t const msgid, struct adc_notify_cfg_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { if (param->val == PRF_CLI_START_NTF) { adc_init(GP_ADC_SE, 0); // Single ended mode adc_enable_channel(ADC_CHANNEL_P01); // app_adc_notify_upd_char(SWAP(adc_get_sample())); app_timer_set(APP_ADC_SAMPLING_TIMER, TASK_APP, APP_ADC_SAMPLING_TIMEOUT); //5 sec } else if (param->val == PRF_CLI_STOP_NTFIND) { ke_timer_clear(APP_ADC_SAMPLING_TIMER, TASK_APP); //5 sec } return (KE_MSG_CONSUMED); }
void app_batt_poll_start(uint16_t poll_timeout) { bat_poll_timeout = poll_timeout; app_timer_set(APP_BATT_TIMER, TASK_APP, 10); //first poll in 100 ms }
/** **************************************************************************************** * @brief Handler of the Red LED Timer * * @param[in] msgid * @param[in] param * @param[in] dest_id * @param[in] src_id * * @return KE_MSG_CONSUMED **************************************************************************************** */ int app_red_led_timer_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { if (!dbg_uses_led_pins() || !((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)) { // GPIOs are not being used by the debugger switch(red_led_st) { case LED_OFF: red_led_off(); break; case DOUBLE_BLINK_LED_IS_ON__TURN_OFF_A: red_led_off(); app_timer_set(APP_RED_LED_TIMER, TASK_APP, DOUBLE_BLINK_RED_OFF_A); red_led_st = DOUBLE_BLINK_LED_IS_OFF__TURN_ON_B; if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) && ((green_led_st == LED_OFF) || (green_led_st == BLINK_LED_IS_OFF__TURN_ON))) { app_restore_sleep_mode(); } break; case DOUBLE_BLINK_LED_IS_OFF__TURN_ON_B: red_led_blink(); app_timer_set(APP_RED_LED_TIMER, TASK_APP, DOUBLE_BLINK_RED_ON_B); red_led_st = DOUBLE_BLINK_LED_IS_ON__TURN_OFF_B; leds_block_sleep(); break; case DOUBLE_BLINK_LED_IS_ON__TURN_OFF_B: red_led_off(); app_timer_set(APP_RED_LED_TIMER, TASK_APP, DOUBLE_BLINK_RED_OFF_B); red_led_st = LED_OFF; if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) && ((green_led_st == LED_OFF) || (green_led_st == BLINK_LED_IS_OFF__TURN_ON))) { app_restore_sleep_mode(); } break; case BLINK_LED_IS_ON__TURN_OFF: red_led_off(); app_timer_set(APP_RED_LED_TIMER, TASK_APP, BLINK_RED_OFF); red_led_st = BLINK_LED_IS_OFF__TURN_ON; if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) && ((green_led_st == LED_OFF) || (green_led_st == BLINK_LED_IS_OFF__TURN_ON))){ app_restore_sleep_mode(); // restore sleep } break; case BLINK_LED_IS_OFF__TURN_ON: red_led_blink(); app_timer_set(APP_RED_LED_TIMER, TASK_APP, BLINK_RED_ON); leds_block_sleep(); break; case LED_ON: red_led_off(); if ((GetBits16(ANA_STATUS_REG, BOOST_SELECTED) == 0x1) && ((green_led_st == LED_OFF) || (green_led_st == BLINK_LED_IS_OFF__TURN_ON))) { app_restore_sleep_mode(); // restore sleep } high_priority_indications_active = false; break; default: break; } } return (KE_MSG_CONSUMED); }