Created
June 17, 2020 16:03
-
-
Save mhx/694d73b8e6a144a0bbea25e7d15e56f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ruN samples/bluetooth/peripheral/src/main.c samples/bluetooth/peripheral-25964/src/main.c | |
--- samples/bluetooth/peripheral/src/main.c 2020-06-17 17:35:31.695578457 +0200 | |
+++ samples/bluetooth/peripheral-25964/src/main.c 2020-06-17 17:48:31.701315435 +0200 | |
@@ -316,6 +316,51 @@ | |
bt_gatt_hrs_notify(heartrate); | |
} | |
+static void interrupt_worker(struct k_work *work); | |
+static void interrupt_timer_handler(struct k_timer *timer); | |
+ | |
+K_WORK_DEFINE(interrupt_work, interrupt_worker); | |
+K_TIMER_DEFINE(interrupt_timer, interrupt_timer_handler, NULL); | |
+ | |
+static void interrupt_worker(struct k_work *work) { | |
+ printk("interrupt_worker\n"); | |
+ | |
+ /* Current Time Service updates only when time is changed */ | |
+ cts_notify(); | |
+ printk("cts done\n"); | |
+ | |
+ /* Heartrate measurements simulation */ | |
+ hrs_notify(); | |
+ printk("hrs done\n"); | |
+ | |
+ /* Battery level simulation */ | |
+ bas_notify(); | |
+ printk("bas done\n"); | |
+ | |
+ /* Vendor indication simulation */ | |
+ if (simulate_vnd) { | |
+ if (!indicating) { | |
+ ind_params.attr = &vnd_svc.attrs[2]; | |
+ ind_params.func = indicate_cb; | |
+ ind_params.data = &indicating; | |
+ ind_params.len = sizeof(indicating); | |
+ | |
+ if (bt_gatt_indicate(NULL, &ind_params) == 0) { | |
+ indicating = 1U; | |
+ } | |
+ } | |
+ } | |
+ | |
+ printk("resetting timer\n"); | |
+ | |
+ k_timer_start(&interrupt_timer, K_MSEC(100), K_NO_WAIT); | |
+} | |
+ | |
+static void interrupt_timer_handler(struct k_timer *timer) { | |
+ printk("interrupt_timer_handler\n"); | |
+ k_work_submit(&interrupt_work); | |
+} | |
+ | |
void main(void) | |
{ | |
int err; | |
@@ -331,35 +376,12 @@ | |
bt_conn_cb_register(&conn_callbacks); | |
bt_conn_auth_cb_register(&auth_cb_display); | |
+ k_timer_start(&interrupt_timer, K_MSEC(100), K_NO_WAIT); | |
+ | |
/* Implement notification. At the moment there is no suitable way | |
* of starting delayed work so we do it here | |
*/ | |
while (1) { | |
k_sleep(K_SECONDS(1)); | |
- | |
- /* Current Time Service updates only when time is changed */ | |
- cts_notify(); | |
- | |
- /* Heartrate measurements simulation */ | |
- hrs_notify(); | |
- | |
- /* Battery level simulation */ | |
- bas_notify(); | |
- | |
- /* Vendor indication simulation */ | |
- if (simulate_vnd) { | |
- if (indicating) { | |
- continue; | |
- } | |
- | |
- ind_params.attr = &vnd_svc.attrs[2]; | |
- ind_params.func = indicate_cb; | |
- ind_params.data = &indicating; | |
- ind_params.len = sizeof(indicating); | |
- | |
- if (bt_gatt_indicate(NULL, &ind_params) == 0) { | |
- indicating = 1U; | |
- } | |
- } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment