Heart Rate Sensor Application.
Copyright (c) 2017-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include "platform.h"
#include "at_ble_api.h"
#include "console_serial.h"
#include "timer_hw.h"
#include "conf_extint.h"
#include "ble_manager.h"
#include "ble_utils.h"
#include "hr_sensor_app.h"
#include "hr_sensor.h"
Macros | |
#define | APP_BUTTON_EVENT_ID (2) |
#define | APP_INVALID_EVENT_ID (0) |
#define | APP_TIMER_EVENT_ID (1) |
Functions | |
static at_ble_status_t | app_connected_event_handler (void *params) |
connected state handler More... | |
static at_ble_status_t | app_disconnected_event_handler (void *params) |
at_ble_status_t | app_notification_cfm_handler (void *params) |
hr_notification_confirmation_handler called by ble manager to give the status of notification sent More... | |
static void | app_notification_handler (uint8_t notification_enable) |
notification handler function called by the profile More... | |
static void | app_reset_handler (void) |
energy expended handler called by profile to reset the energy values More... | |
void | button_cb (void) |
Button Press Callback. More... | |
static void | heart_rate_value_init (void) |
heart_rate_value_init will initializes the heart rate values for simulation. More... | |
static void | hr_measurment_send (void) |
hr_measurment_send sends the notifications after adding the hr values heart rate values starts @60bpm increments by 1 goes upto 255 bpm and restarts @60 Energy Expended will be sent on every 10th notification,it starts @ 0 and increments by 20 rr interval values, two rr interval values will be sent in every notification More... | |
static at_ble_status_t | hr_sensor_app_custom_event (void *param) |
int | main (void) |
Heart Rate Sensor Application main function. More... | |
static void | timer_callback_handler (void) |
Timer callback handler called on timer expiry. More... | |
Variables | |
uint8_t | activity = 0 |
volatile bool | advertisement_flag = false |
user_custom_event_t | app_custom_event [2] |
bool | app_exec = true |
static const ble_gap_event_cb_t | app_gap_handle |
static const ble_gatt_server_event_cb_t | app_gatt_server_handle |
volatile bool | app_init_done = false |
volatile bool | app_state = 0 |
volatile bool | disconnect_flag = false |
uint16_t | energy_expended_val = ENERGY_EXP_NORMAL |
uint8_t | energy_inclusion = 0 |
uint16_t | energy_incrementor |
uint16_t | heart_rate_value = HEART_RATE_MIN_NORM |
volatile bool | hr_initializer_flag = 1 |
uint8_t | hr_max_value |
uint8_t | hr_min_value |
static const ble_custom_event_cb_t | hr_sensor_custom_event_cb |
int8_t | inc_changer = 1 |
volatile bool | notification_flag = false |
volatile bool | notification_sent = true |
uint8_t | prev_activity = DEFAULT_ACTIVITY |
uint16_t | rr_interval_value = RR_VALUE_MIN |
uint8_t | second_counter = 0 |
volatile bool | start_advertisement = 0 |
int8_t | time_operator |
#define APP_BUTTON_EVENT_ID (2) |
Referenced by hr_sensor_app_custom_event().
#define APP_INVALID_EVENT_ID (0) |
#define APP_TIMER_EVENT_ID (1) |
Referenced by hr_sensor_app_custom_event().
|
static |
connected state handler
[in] | status | of the application |
References advertisement_flag, ALL_UNUSED, app_state, AT_BLE_SUCCESS, DBG_LOG, and notification_sent.
|
static |
at_ble_status_t app_notification_cfm_handler | ( | void * | params | ) |
hr_notification_confirmation_handler called by ble manager to give the status of notification sent
app_notification_cfm_handler called by ble manager to give the status of notification sent
[in] | at_ble_cmd_complete_event_t | address of the cmd completion |
References AT_BLE_SUCCESS, DBG_LOG_DEV, notification_sent, and at_ble_cmd_complete_event_t::status.
|
static |
notification handler function called by the profile
[in] | notification_enable | which will tell the state of the application |
References DBG_LOG, hw_timer_start(), hw_timer_stop(), notification_flag, and NOTIFICATION_INTERVAL.
Referenced by main().
|
static |
energy expended handler called by profile to reset the energy values
References DBG_LOG, and energy_expended_val.
Referenced by main().
void button_cb | ( | void | ) |
Button Press Callback.
References advertisement_flag, app_init_done, app_state, at_ble_event_user_defined_post(), DBG_LOG_DEV, disconnect_flag, and start_advertisement.
|
static |
heart_rate_value_init will initializes the heart rate values for simulation.
Based on the time different heart rate values are chosen to indicate different activity.
References activity, ACTIVITY_BRISK_WALKING, ACTIVITY_FAST_RUNNING, ACTIVITY_NORMAL, ACTIVITY_RUNNING, ACTIVITY_WALKING, ENERGY_EXP_BRISK_WALKING, ENERGY_EXP_FAST_RUNNING, ENERGY_EXP_NORMAL, ENERGY_EXP_RUNNING, ENERGY_EXP_WALKING, energy_incrementor, HEART_RATE_MAX_BRISK_WALK, HEART_RATE_MAX_FAST_RUNNING, HEART_RATE_MAX_NORM, HEART_RATE_MAX_RUNNING, HEART_RATE_MAX_WALKING, HEART_RATE_MIN_BRISK_WALK, HEART_RATE_MIN_FAST_RUNNING, HEART_RATE_MIN_NORM, HEART_RATE_MIN_RUNNING, HEART_RATE_MIN_WALKING, heart_rate_value, hr_max_value, hr_min_value, inc_changer, prev_activity, and second_counter.
Referenced by app_disconnected_event_handler(), and timer_callback_handler().
|
static |
hr_measurment_send sends the notifications after adding the hr values heart rate values starts @60bpm increments by 1 goes upto 255 bpm and restarts @60 Energy Expended will be sent on every 10th notification,it starts @ 0 and increments by 20 rr interval values, two rr interval values will be sent in every notification
References activity, ACTIVITY_BRISK_WALKING, ACTIVITY_FAST_RUNNING, ACTIVITY_NORMAL, ACTIVITY_RUNNING, ACTIVITY_WALKING, DBG_LOG, DBG_LOG_CONT, ENERGY_EXPENDED_FIELD_PRESENT, energy_expended_val, energy_inclusion, energy_incrementor, ENERGY_RESET, heart_rate_value, HR_CHAR_VALUE_LEN, hr_sensor_send_notification(), inc_changer, rr_interval_value, RR_INTERVAL_VALUE_PRESENT, RR_VALUE_MAX, RR_VALUE_MIN, and second_counter.
Referenced by hr_sensor_app_custom_event().
|
static |
int main | ( | void | ) |
Heart Rate Sensor Application main function.
References app_exec, app_init_done, app_notification_handler(), app_reset_handler(), BLE_CUSTOM_EVENT_TYPE, ble_device_init(), ble_event_task(), BLE_GAP_EVENT_TYPE, BLE_GATT_SERVER_EVENT_TYPE, ble_mgr_events_callback_handler(), board_init(), DBG_LOG, hr_sensor_init(), hw_timer_init(), hw_timer_register_callback(), NULL, REGISTER_CALL_BACK, register_hr_notification_handler(), register_hr_reset_handler(), serial_console_init(), system_init(), and timer_callback_handler().
|
static |
Timer callback handler called on timer expiry.
References app_init_done, at_ble_event_user_defined_post(), END_OF_LAST_ACTIVITY, heart_rate_value_init(), notification_flag, second_counter, START_OF_FIRST_ACTIVITY, and time_operator.
uint8_t activity = 0 |
activiy which will determine the
Referenced by app_disconnected_event_handler(), heart_rate_value_init(), and hr_measurment_send().
to check if the device is in advertisement
Referenced by app_connected_event_handler(), and button_cb().
user_custom_event_t app_custom_event[2] |
|
static |
|
static |
volatile bool app_state = 0 |
flag to represent the application state
flag for disconnection
Referenced by button_cb(), and hr_sensor_app_custom_event().
uint16_t energy_expended_val = ENERGY_EXP_NORMAL |
to count the energy expended
Referenced by app_disconnected_event_handler(), app_reset_handler(), and hr_measurment_send().
uint8_t energy_inclusion = 0 |
To check for including the energy in hr measurement
Referenced by app_disconnected_event_handler(), and hr_measurment_send().
uint16_t energy_incrementor |
energy incrementor for various heart rate values
Referenced by heart_rate_value_init(), and hr_measurment_send().
uint16_t heart_rate_value = HEART_RATE_MIN_NORM |
to count the heart rate value
Referenced by heart_rate_value_init(), and hr_measurment_send().
volatile bool hr_initializer_flag = 1 |
flag for initialization of hr for each category
uint8_t hr_max_value |
the maximum heart rate value
Referenced by heart_rate_value_init().
uint8_t hr_min_value |
the minimum heart rate value
Referenced by heart_rate_value_init().
|
static |
int8_t inc_changer = 1 |
increment operator to change heart rate
Referenced by heart_rate_value_init(), and hr_measurment_send().
uint8_t prev_activity = DEFAULT_ACTIVITY |
previous activity
Referenced by app_disconnected_event_handler(), and heart_rate_value_init().
uint16_t rr_interval_value = RR_VALUE_MIN |
to count the rr interval value
Referenced by hr_measurment_send().
uint8_t second_counter = 0 |
second_counter to count the time
Referenced by app_disconnected_event_handler(), heart_rate_value_init(), hr_measurment_send(), and timer_callback_handler().
volatile bool start_advertisement = 0 |
flag to start advertisement
Referenced by button_cb(), and hr_sensor_app_custom_event().
int8_t time_operator |
operator to change the seconds
Referenced by timer_callback_handler().