Microchip® Advanced Software Framework

hr_sensor_app.c File Reference

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)
#define APP_INVALID_EVENT_ID   (0)
#define APP_TIMER_EVENT_ID   (1)

static at_ble_status_t app_connected_event_handler ( void *  params)
static

connected state handler

Parameters
[in]statusof the application

References advertisement_flag, ALL_UNUSED, app_state, AT_BLE_SUCCESS, DBG_LOG, and notification_sent.

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

Parameters
[in]at_ble_cmd_complete_event_taddress of the cmd completion

References AT_BLE_SUCCESS, DBG_LOG_DEV, notification_sent, and at_ble_cmd_complete_event_t::status.

static void app_notification_handler ( uint8_t  notification_enable)
static

notification handler function called by the profile

Parameters
[in]notification_enablewhich 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 void app_reset_handler ( void  )
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  )
static void hr_measurment_send ( void  )
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 void timer_callback_handler ( void  )
static

volatile bool advertisement_flag = false

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]
Initial value:
= {
{
.bptr = NULL,
},
{
.bptr = NULL
}
}
#define APP_TIMER_EVENT_ID
Definition: hr_sensor_app.c:173
#define NULL
Definition: def.h:47
#define APP_BUTTON_EVENT_ID
Definition: hr_sensor_app.c:174
bool app_exec = true
const ble_gap_event_cb_t app_gap_handle
static
Initial value:
= {
}
static at_ble_status_t app_connected_event_handler(void *params)
connected state handler
Definition: hr_sensor_app.c:329
static at_ble_status_t app_disconnected_event_handler(void *params)
Definition: hr_sensor_app.c:341
const ble_gatt_server_event_cb_t app_gatt_server_handle
static
Initial value:
= {
.notification_confirmed = app_notification_cfm_handler
}
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 ...
Definition: hr_sensor_app.c:246
volatile bool app_init_done = false
volatile bool app_state = 0

flag to represent the application state

volatile bool disconnect_flag = false

flag for disconnection

Referenced by button_cb(), and hr_sensor_app_custom_event().

uint8_t energy_inclusion = 0

To check for including the energy in hr measurement

Referenced by app_disconnected_event_handler(), ble_heart_rate_handle_disconnect_event(), ble_heart_rate_process(), and hr_measurment_send().

uint16_t energy_incrementor

energy incrementor for various heart rate values

Referenced by ble_heart_rate_process(), ble_heart_rate_value_init(), heart_rate_value_init(), and hr_measurment_send().

uint16_t heart_rate_value = HEART_RATE_MIN_NORM
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 ble_heart_rate_value_init(), and heart_rate_value_init().

uint8_t hr_min_value

the minimum heart rate value

Referenced by ble_heart_rate_value_init(), and heart_rate_value_init().

const ble_custom_event_cb_t hr_sensor_custom_event_cb
static
Initial value:
= {
}
static at_ble_status_t hr_sensor_app_custom_event(void *param)
Definition: hr_sensor_app.c:475
int8_t inc_changer = 1

increment operator to change heart rate

Referenced by ble_heart_rate_process(), ble_heart_rate_value_init(), heart_rate_value_init(), and hr_measurment_send().

volatile bool notification_flag = false

flag to start notification

uint16_t rr_interval_value = RR_VALUE_MIN

to count the rr interval value

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 ble_heart_rate_handle_timer_event(), and timer_callback_handler().