Skip to content

Commit f66dd94

Browse files
asmellbycfriedt
authored andcommitted
samples: bluetooth: peripheral_ht: Use dht0 temperature sensor
Use the temperature sensor with a dht0 alias if available in the Bluetooth Health Thermometer sample. This alias is already used by the sensor/dht_polling sample app for temperature measurement, and is supported by several boards in the tree. Signed-off-by: Aksel Skauge Mellbye <[email protected]>
1 parent d49e6c1 commit f66dd94

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

samples/bluetooth/peripheral_ht/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
mainmenu "Bluetooth: Peripheral HT"
55

6-
if HAS_HW_NRF_TEMP
7-
86
config SENSOR
9-
default y
7+
default y if HAS_HW_NRF_TEMP || $(dt_alias_enabled,dht0)
8+
9+
if HAS_HW_NRF_TEMP
1010

1111
config TEMP_NRF5
1212
default y

samples/bluetooth/peripheral_ht/README.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ Overview
1010
Similar to the :zephyr:code-sample:`ble_peripheral` sample, except that this
1111
application specifically exposes the HT (Health Thermometer) GATT Service.
1212

13-
On Nordic nRF devices, this sample uses the built-in TEMP peripheral to return
14-
die temperature values. On other boards, it will generate dummy temperature
15-
values.
13+
On boards with a ``dht0`` Devicetree alias node, this sample uses this sensor to
14+
return ambient temperature values. On Nordic nRF devices, it uses the built-in
15+
TEMP peripheral to return die temperature values. On other boards, it will
16+
generate dummy temperature values.
1617

1718

1819
Requirements

samples/bluetooth/peripheral_ht/src/hts.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@
2727

2828
#ifdef CONFIG_TEMP_NRF5
2929
static const struct device *temp_dev = DEVICE_DT_GET_ANY(nordic_nrf_temp);
30+
#define TEMP_SENSOR_CHAN SENSOR_CHAN_DIE_TEMP
31+
#elif DT_HAS_ALIAS(dht0)
32+
static const struct device *temp_dev = DEVICE_DT_GET(DT_ALIAS(dht0));
33+
#define TEMP_SENSOR_CHAN SENSOR_CHAN_AMBIENT_TEMP
3034
#else
3135
static const struct device *temp_dev;
36+
#define TEMP_SENSOR_CHAN SENSOR_CHAN_AMBIENT_TEMP
3237
#endif
3338

3439
static uint8_t simulate_htm;
@@ -104,8 +109,7 @@ void hts_indicate(void)
104109
printk("sensor_sample_fetch failed return: %d\n", r);
105110
}
106111

107-
r = sensor_channel_get(temp_dev, SENSOR_CHAN_DIE_TEMP,
108-
&temp_value);
112+
r = sensor_channel_get(temp_dev, TEMP_SENSOR_CHAN, &temp_value);
109113
if (r) {
110114
printk("sensor_channel_get failed return: %d\n", r);
111115
}

0 commit comments

Comments
 (0)