From 36522ee71b98e09af1ea42d81a82e69bb4e2a49d Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 10 Feb 2016 12:53:38 +0200 Subject: Bluetooth: peripheral: Make heart rate simulation more predictable sys_rand32_get appears to get stuck with same number for a while so instead just increment the heart rate by 1 until 160 and then return it back to 90. Change-Id: I2aea870c68539271a1bb6190a958a7e2d1914dc3 Signed-off-by: Luiz Augusto von Dentz --- samples/bluetooth/peripheral/prj.conf | 1 - samples/bluetooth/peripheral/prj_nble.conf | 1 - samples/bluetooth/peripheral/src/main.c | 8 +++++++- samples/bluetooth/peripheral_hr/prj.conf | 1 - samples/bluetooth/peripheral_hr/prj_nble.conf | 1 - samples/bluetooth/peripheral_hr/src/main.c | 8 +++++++- 6 files changed, 14 insertions(+), 6 deletions(-) (limited to 'samples') diff --git a/samples/bluetooth/peripheral/prj.conf b/samples/bluetooth/peripheral/prj.conf index 0cc037fbd..98d6d2ff0 100644 --- a/samples/bluetooth/peripheral/prj.conf +++ b/samples/bluetooth/peripheral/prj.conf @@ -1,4 +1,3 @@ -CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH_LE=y CONFIG_BLUETOOTH_DEBUG=y diff --git a/samples/bluetooth/peripheral/prj_nble.conf b/samples/bluetooth/peripheral/prj_nble.conf index ef0af4e30..ba9f2e8b1 100644 --- a/samples/bluetooth/peripheral/prj_nble.conf +++ b/samples/bluetooth/peripheral/prj_nble.conf @@ -1,4 +1,3 @@ -CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_NBLE=y CONFIG_ARC_INIT=n CONFIG_BLUETOOTH_DEBUG=y diff --git a/samples/bluetooth/peripheral/src/main.c b/samples/bluetooth/peripheral/src/main.c index 21c5e5630..b13b7ad15 100644 --- a/samples/bluetooth/peripheral/src/main.c +++ b/samples/bluetooth/peripheral/src/main.c @@ -73,6 +73,7 @@ static int read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr, static struct bt_gatt_ccc_cfg blvl_ccc_cfg[CONFIG_BLUETOOTH_MAX_PAIRED] = {}; static uint8_t simulate_blvl = 0; static uint8_t battery = 100; +static uint8_t heartrate = 90; static void blvl_ccc_cfg_changed(uint16_t value) { @@ -504,8 +505,13 @@ void main(void) /* Heartrate measurements simulation */ if (simulate_hrm) { + heartrate++; + if (heartrate == 160) { + heartrate = 90; + } + hrm[0] = 0x06; /* uint8, sensor contact */ - hrm[1] = 90 + (sys_rand32_get() % 20); + hrm[1] = heartrate; bt_gatt_notify(NULL, &hrs_attrs[2], &hrm, sizeof(hrm)); } diff --git a/samples/bluetooth/peripheral_hr/prj.conf b/samples/bluetooth/peripheral_hr/prj.conf index 8fef00b1d..9d1fa5d42 100644 --- a/samples/bluetooth/peripheral_hr/prj.conf +++ b/samples/bluetooth/peripheral_hr/prj.conf @@ -1,4 +1,3 @@ -CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_BLUETOOTH=y CONFIG_BLUETOOTH_LE=y CONFIG_BLUETOOTH_DEBUG=y diff --git a/samples/bluetooth/peripheral_hr/prj_nble.conf b/samples/bluetooth/peripheral_hr/prj_nble.conf index ef0af4e30..ba9f2e8b1 100644 --- a/samples/bluetooth/peripheral_hr/prj_nble.conf +++ b/samples/bluetooth/peripheral_hr/prj_nble.conf @@ -1,4 +1,3 @@ -CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_NBLE=y CONFIG_ARC_INIT=n CONFIG_BLUETOOTH_DEBUG=y diff --git a/samples/bluetooth/peripheral_hr/src/main.c b/samples/bluetooth/peripheral_hr/src/main.c index f310ffdd9..040408e50 100644 --- a/samples/bluetooth/peripheral_hr/src/main.c +++ b/samples/bluetooth/peripheral_hr/src/main.c @@ -75,6 +75,7 @@ static int read_blsc(struct bt_conn *conn, const struct bt_gatt_attr *attr, static struct bt_gatt_ccc_cfg blvl_ccc_cfg[CONFIG_BLUETOOTH_MAX_PAIRED] = {}; static uint8_t simulate_blvl; static uint8_t battery = 100; +static uint8_t heartrate = 90; static void blvl_ccc_cfg_changed(uint16_t value) { @@ -262,8 +263,13 @@ void main(void) /* Heartrate measurements simulation */ if (simulate_hrm) { + heartrate++; + if (heartrate == 160) { + heartrate = 90; + } + hrm[0] = 0x06; /* uint8, sensor contact */ - hrm[1] = 90 + (sys_rand32_get() % 20); + hrm[1] = heartrate; bt_gatt_notify(default_conn, &hrs_attrs[2], &hrm, sizeof(hrm)); -- cgit v1.2.3