@@ -21,8 +21,6 @@ LOG_MODULE_REGISTER(as6212_sample, LOG_LEVEL_INF);
21
21
#define INTERRUPT_MODE 0x0200
22
22
23
23
#define SLEEP_DURATION 2U
24
- #define TEMPERATURE_THRESHOLD_LOW 38
25
- #define TEMPERATURE_THRESHOLD_HIGH 44
26
24
27
25
/* Thread properties */
28
26
#undef TASK_STACK_SIZE
@@ -42,8 +40,11 @@ static struct k_thread as6212_b_id;
42
40
int as6212_int1_int_isr_count = 0 ;
43
41
const struct device * as6212 ;
44
42
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 )
46
44
{
45
+ ARG_UNUSED (device );
46
+ ARG_UNUSED (trigger );
47
+
47
48
as6212_int1_int_isr_count ++ ;
48
49
printk ("\n%s(): Received AS6212 Temperature Sensor ALERT Interrupt (%d)\n" , __func__ ,
49
50
as6212_int1_int_isr_count );
@@ -90,9 +91,11 @@ static void enable_temp_alerts(const struct device *as6212)
90
91
struct sensor_trigger sensor_trigger_type_temp_alert = {.chan = SENSOR_CHAN_AMBIENT_TEMP ,
91
92
.type = SENSOR_TRIG_THRESHOLD };
92
93
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 );
94
96
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 );
96
99
97
100
struct sensor_value thermostat_mode = {0 , 0 };
98
101
@@ -101,21 +104,18 @@ static void enable_temp_alerts(const struct device *as6212)
101
104
sensor_attr_set (as6212 , SENSOR_CHAN_AMBIENT_TEMP , SENSOR_ATTR_UPPER_THRESH ,
102
105
& alert_upper_thresh );
103
106
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 ) );
105
108
106
109
sensor_attr_set (as6212 , SENSOR_CHAN_AMBIENT_TEMP , SENSOR_ATTR_LOWER_THRESH ,
107
110
& alert_lower_thresh );
108
111
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 ) );
110
113
111
114
sensor_trigger_set (as6212 , & sensor_trigger_type_temp_alert , temperature_alert );
112
115
113
116
puts ("\n\tSet temperature_alert" );
114
117
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 );
119
119
}
120
120
#endif
121
121
@@ -211,8 +211,11 @@ static void setup(void)
211
211
return ;
212
212
}
213
213
214
- sensor_attr_set (as6212 , SENSOR_CHAN_AMBIENT_TEMP ,
214
+ result = sensor_attr_set (as6212 , SENSOR_CHAN_AMBIENT_TEMP ,
215
215
SENSOR_ATTR_TMP108_CONTINUOUS_CONVERSION_MODE , NULL );
216
+ if (result ) {
217
+ printf ("error: sensor_attr_set(): %d\n" , result );
218
+ }
216
219
217
220
#if CONFIG_APP_ENABLE_ONE_SHOT
218
221
enable_one_shot (as6212 );
0 commit comments