diff --git a/project/ble.c b/project/ble.c index 008f4413608fb51e5982d8a7ee4f2b87797aad46..971429ce3fee3c851aef398f4b4b02d4c250fe40 100644 --- a/project/ble.c +++ b/project/ble.c @@ -84,6 +84,8 @@ #include "ble_hts.h" #include "ble_bas.h" #include "arm_math.h" +#include "nrf_drv_timer.h" +#include "bsp.h" #define DEVICE_NAME "nRF_Aapo" /**< Name of device. Will be included in the advertising data. */ @@ -114,9 +116,14 @@ #define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */ +#define APP_TIMER_MAX_TIMERS 1 /**< Maximum number of timers used by the application. */ +#define TIMER_INTERVAL APP_TIMER_TICKS(1000) + // Determines if temperature type is given as characteristic (1) or as a field of measurement (0) #define TEMP_TYPE_AS_CHARACTERISTIC 0 +APP_TIMER_DEF(send_orientation_timer_id); + extern uint8_t orientation; uint8_t previous_orientation; @@ -129,7 +136,6 @@ uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Ha BLE_HTS_DEF(m_hts); // Macro for defining a ble_hts instance BLE_BAS_DEF(m_bas); // Macro for defining a ble_bas instance - // Flag to keep track of when an indication confirmation is pending bool m_hts_meas_ind_conf_pending = false; @@ -146,22 +152,22 @@ ble_uuid_t m_adv_uuids[] = /**< Un void advertising_start(bool erase_bonds); /* -* Function for generating a dummy temperature information packet. +* Function for getting orientation value calculated from sensor values. */ void fetch_orientation(ble_hts_meas_t * p_meas) { ble_date_time_t time_stamp = { 2018, 16, 10, 16, 15, 0 }; - uint32_t celciusX100; - celciusX100 = orientation; // one unit is 0.01 Celcius + uint32_t orientation_to_send; + orientation_to_send = orientation; // one unit is 0.01 Celcius p_meas->temp_in_fahr_units = false; p_meas->time_stamp_present = true; p_meas->temp_type_present = (TEMP_TYPE_AS_CHARACTERISTIC ? false : true); p_meas->temp_in_celcius.exponent = -2; - p_meas->temp_in_celcius.mantissa = celciusX100; + p_meas->temp_in_celcius.mantissa = orientation_to_send; p_meas->temp_in_fahr.exponent = -2; - p_meas->temp_in_fahr.mantissa = (32 * 100) + ((celciusX100 * 9) / 5); + p_meas->temp_in_fahr.mantissa = (32 * 100) + ((orientation_to_send * 9) / 5); p_meas->time_stamp = time_stamp; p_meas->temp_type = BLE_HTS_TEMP_TYPE_FINGER; @@ -252,6 +258,12 @@ void pm_evt_handler(pm_evt_t const * p_evt) { } } +/** + * @brief Handler for timer events. + */ +void send_orientation_timer(void* p_context) { + temperature_measurement_send(); +} /**@brief Function for the Timer initialization. * @@ -263,14 +275,8 @@ void timers_init(void) { APP_ERROR_CHECK(err_code); // Create timers. - - /* YOUR_JOB: Create any timers to be used by the application. - Below is an example of how to create a timer. - For every new timer needed, increase the value of the macro APP_TIMER_MAX_TIMERS by - one. - ret_code_t err_code; - err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler); - APP_ERROR_CHECK(err_code); */ + err_code = app_timer_create(&send_orientation_timer_id, APP_TIMER_MODE_REPEATED, send_orientation_timer); + APP_ERROR_CHECK(err_code); } @@ -448,15 +454,12 @@ void conn_params_init(void) { APP_ERROR_CHECK(err_code); } - /**@brief Function for starting timers. */ void application_timers_start(void) { - /* YOUR_JOB: Start your timers. below is an example of how to start a timer. - ret_code_t err_code; - err_code = app_timer_start(m_app_timer_id, TIMER_INTERVAL, NULL); - APP_ERROR_CHECK(err_code); */ - + ret_code_t err_code; + err_code = app_timer_start(send_orientation_timer_id, TIMER_INTERVAL, NULL); + APP_ERROR_CHECK(err_code); }