Skip to content
Snippets Groups Projects
Commit 175054ac authored by Aapo Torkkeli's avatar Aapo Torkkeli
Browse files

basic version of timer sending

parent c35d4c7f
No related branches found
No related tags found
No related merge requests found
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
#include "ble_hts.h" #include "ble_hts.h"
#include "ble_bas.h" #include "ble_bas.h"
#include "arm_math.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. */ #define DEVICE_NAME "nRF_Aapo" /**< Name of device. Will be included in the advertising data. */
...@@ -114,9 +116,14 @@ ...@@ -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 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) // Determines if temperature type is given as characteristic (1) or as a field of measurement (0)
#define TEMP_TYPE_AS_CHARACTERISTIC 0 #define TEMP_TYPE_AS_CHARACTERISTIC 0
APP_TIMER_DEF(send_orientation_timer_id);
extern uint8_t orientation; extern uint8_t orientation;
uint8_t previous_orientation; uint8_t previous_orientation;
...@@ -129,7 +136,6 @@ uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Ha ...@@ -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_HTS_DEF(m_hts); // Macro for defining a ble_hts instance
BLE_BAS_DEF(m_bas); // Macro for defining a ble_bas instance BLE_BAS_DEF(m_bas); // Macro for defining a ble_bas instance
// Flag to keep track of when an indication confirmation is pending // Flag to keep track of when an indication confirmation is pending
bool m_hts_meas_ind_conf_pending = false; bool m_hts_meas_ind_conf_pending = false;
...@@ -146,22 +152,22 @@ ble_uuid_t m_adv_uuids[] = /**< Un ...@@ -146,22 +152,22 @@ ble_uuid_t m_adv_uuids[] = /**< Un
void advertising_start(bool erase_bonds); 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) { void fetch_orientation(ble_hts_meas_t * p_meas) {
ble_date_time_t time_stamp = { 2018, 16, 10, 16, 15, 0 }; ble_date_time_t time_stamp = { 2018, 16, 10, 16, 15, 0 };
uint32_t celciusX100; uint32_t orientation_to_send;
celciusX100 = orientation; // one unit is 0.01 Celcius orientation_to_send = orientation; // one unit is 0.01 Celcius
p_meas->temp_in_fahr_units = false; p_meas->temp_in_fahr_units = false;
p_meas->time_stamp_present = true; p_meas->time_stamp_present = true;
p_meas->temp_type_present = (TEMP_TYPE_AS_CHARACTERISTIC ? false : true); p_meas->temp_type_present = (TEMP_TYPE_AS_CHARACTERISTIC ? false : true);
p_meas->temp_in_celcius.exponent = -2; 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.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->time_stamp = time_stamp;
p_meas->temp_type = BLE_HTS_TEMP_TYPE_FINGER; p_meas->temp_type = BLE_HTS_TEMP_TYPE_FINGER;
...@@ -252,6 +258,12 @@ void pm_evt_handler(pm_evt_t const * p_evt) { ...@@ -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. /**@brief Function for the Timer initialization.
* *
...@@ -263,14 +275,8 @@ void timers_init(void) { ...@@ -263,14 +275,8 @@ void timers_init(void) {
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
// Create timers. // Create timers.
err_code = app_timer_create(&send_orientation_timer_id, APP_TIMER_MODE_REPEATED, send_orientation_timer);
/* YOUR_JOB: Create any timers to be used by the application. APP_ERROR_CHECK(err_code);
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); */
} }
...@@ -448,15 +454,12 @@ void conn_params_init(void) { ...@@ -448,15 +454,12 @@ void conn_params_init(void) {
APP_ERROR_CHECK(err_code); APP_ERROR_CHECK(err_code);
} }
/**@brief Function for starting timers. /**@brief Function for starting timers.
*/ */
void application_timers_start(void) { 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; ret_code_t err_code;
err_code = app_timer_start(m_app_timer_id, TIMER_INTERVAL, NULL); err_code = app_timer_start(send_orientation_timer_id, TIMER_INTERVAL, NULL);
APP_ERROR_CHECK(err_code); */ APP_ERROR_CHECK(err_code);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment