Skip to content

Commit 869a878

Browse files
committed
Align AS6212 sample to upstream
Signed-off-by: John Hutcherson <[email protected]>
1 parent 7279c52 commit 869a878

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

samples/as6212_sample/Kconfig

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#
2-
# Copyright (c) 2021 Jimmy Johnson <[email protected]>
1+
# Copyright (c) 2022 T-Mobile USA, Inc.
32
#
43
# SPDX-License-Identifier: Apache-2.0
54
#
@@ -21,7 +20,7 @@ config APP_ENABLE_ONE_SHOT
2120
config APP_TEMP_ALERT_HIGH_THRESH
2221
int "RH [%] high threshold for alert trigger in celsius"
2322
range 0 50
24-
default 26
23+
default 44
2524
help
2625
Set this to enable alerts for high temperatures
2726
although this will work with one shot enabled,
@@ -32,7 +31,7 @@ config APP_TEMP_ALERT_HIGH_THRESH
3231
config APP_TEMP_ALERT_LOW_THRESH
3332
int "RH [%] low threshold for alert trigger in celsius"
3433
range 0 50
35-
default 18
34+
default 38
3635
help
3736
Set this to enable alerts for low temperatures
3837
although this will work with one shot enabled,

samples/as6212_sample/README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ This application aims to demonstrate the Gecko's Energy Mode 2 (EM2) (Deep Sleep
6767
Mode) and Wake capabilities in conjunction with the temperature interrupt
6868
of DevEdge's (tmo_dev_edge) AMS OSRAM AS6212 Digital Temperature Sensor.
6969

70-
Set SENSOR_ATTR_UPPER_THRESH (44)
71-
Set SENSOR_ATTR_LOWER_THRESH (38)
70+
Set SENSOR_ATTR_UPPER_THRESH (44C)
71+
Set SENSOR_ATTR_LOWER_THRESH (38C)
7272

7373
Set temperature_alert
7474

samples/as6212_sample/prj.conf

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# Copyright (c) 2022 T-Mobile USA, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
15
CONFIG_SENSOR=y
26
CONFIG_STDOUT_CONSOLE=y
37
CONFIG_CBPRINTF_FP_SUPPORT=y
48
CONFIG_I2C=y
59
CONFIG_TMP108=y
6-
CONFIG_ASSERT=y
710
CONFIG_TMP108_ALERT_INTERRUPTS=y
811
#Power Managment
912
CONFIG_PM=y

samples/as6212_sample/src/main.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ LOG_MODULE_REGISTER(as6212_sample, LOG_LEVEL_INF);
2121
#define INTERRUPT_MODE 0x0200
2222

2323
#define SLEEP_DURATION 2U
24-
#define TEMPERATURE_THRESHOLD_LOW 38
25-
#define TEMPERATURE_THRESHOLD_HIGH 44
2624

2725
/* Thread properties */
2826
#undef TASK_STACK_SIZE
@@ -42,8 +40,11 @@ static struct k_thread as6212_b_id;
4240
int as6212_int1_int_isr_count = 0;
4341
const struct device *as6212;
4442

45-
void as6212_intr_callback(const struct device *port, struct gpio_callback *cb, uint32_t pins)
43+
static void as6212_intr_callback(const struct device *device, const struct sensor_trigger *trigger)
4644
{
45+
ARG_UNUSED(device);
46+
ARG_UNUSED(trigger);
47+
4748
as6212_int1_int_isr_count++;
4849
printk("\n%s(): Received AS6212 Temperature Sensor ALERT Interrupt (%d)\n", __func__,
4950
as6212_int1_int_isr_count);
@@ -90,9 +91,11 @@ static void enable_temp_alerts(const struct device *as6212)
9091
struct sensor_trigger sensor_trigger_type_temp_alert = {.chan = SENSOR_CHAN_AMBIENT_TEMP,
9192
.type = SENSOR_TRIG_THRESHOLD};
9293

93-
struct sensor_value alert_upper_thresh = {TEMPERATURE_THRESHOLD_HIGH, 0};
94+
struct sensor_value alert_upper_thresh;
95+
sensor_value_from_double(&alert_upper_thresh, CONFIG_APP_TEMP_ALERT_HIGH_THRESH);
9496

95-
struct sensor_value alert_lower_thresh = {TEMPERATURE_THRESHOLD_LOW, 0};
97+
struct sensor_value alert_lower_thresh;
98+
sensor_value_from_double(&alert_lower_thresh, CONFIG_APP_TEMP_ALERT_LOW_THRESH);
9699

97100
struct sensor_value thermostat_mode = {0, 0};
98101

@@ -101,21 +104,18 @@ static void enable_temp_alerts(const struct device *as6212)
101104
sensor_attr_set(as6212, SENSOR_CHAN_AMBIENT_TEMP, SENSOR_ATTR_UPPER_THRESH,
102105
&alert_upper_thresh);
103106

104-
printf("\tSet SENSOR_ATTR_UPPER_THRESH (%d)\n", alert_upper_thresh.val1);
107+
printf("\tSet SENSOR_ATTR_UPPER_THRESH (%gC)\n", sensor_value_to_double(&alert_upper_thresh));
105108

106109
sensor_attr_set(as6212, SENSOR_CHAN_AMBIENT_TEMP, SENSOR_ATTR_LOWER_THRESH,
107110
&alert_lower_thresh);
108111

109-
printf("\tSet SENSOR_ATTR_LOWER_THRESH (%d)\n", alert_lower_thresh.val1);
112+
printf("\tSet SENSOR_ATTR_LOWER_THRESH (%gC)\n", sensor_value_to_double(&alert_lower_thresh));
110113

111114
sensor_trigger_set(as6212, &sensor_trigger_type_temp_alert, temperature_alert);
112115

113116
puts("\n\tSet temperature_alert");
114117

115-
struct sensor_value app_callback = {0, 0};
116-
app_callback.val1 = 1;
117-
app_callback.val2 = (int32_t)as6212_intr_callback;
118-
sensor_attr_set(as6212, SENSOR_CHAN_AMBIENT_TEMP, SENSOR_ATTR_USER_CALLBACK, &app_callback);
118+
sensor_trigger_set(as6212, &sensor_trigger_type_temp_alert, as6212_intr_callback);
119119
}
120120
#endif
121121

@@ -211,8 +211,11 @@ static void setup(void)
211211
return;
212212
}
213213

214-
sensor_attr_set(as6212, SENSOR_CHAN_AMBIENT_TEMP,
214+
result = sensor_attr_set(as6212, SENSOR_CHAN_AMBIENT_TEMP,
215215
SENSOR_ATTR_TMP108_CONTINUOUS_CONVERSION_MODE, NULL);
216+
if (result) {
217+
printf("error: sensor_attr_set(): %d\n", result);
218+
}
216219

217220
#if CONFIG_APP_ENABLE_ONE_SHOT
218221
enable_one_shot(as6212);

0 commit comments

Comments
 (0)