36 #include "lib/sensors.h"
37 #include "ht-sensor.h"
39 #include <HtsDriver.h>
47 #define PRINTF(...) printf(__VA_ARGS__)
53 HT_SENSOR_STATUS_NOT_INIT = 0,
54 HT_SENSOR_STATUS_INIT,
55 HT_SENSOR_STATUS_NOT_ACTIVE = HT_SENSOR_STATUS_INIT,
56 HT_SENSOR_STATUS_ACTIVE
60 #define DELTA_TEMP_SENSOR_VALUE 1
61 #define DELTA_HUM_SENSOR_VALUE 1
66 const struct sensors_sensor ht_sensor;
67 volatile static ht_sensor_status_t ht_sensor_status = HT_SENSOR_STATUS_NOT_INIT;
68 static int prev_temp_event_val = 0;
69 static int prev_hum_event_val = 0;
70 static int temp_sensor_value = 0;
71 static int hum_sensor_value = 0;
76 PROCESS(HTSensorSampling,
"Humidity/Temperature sensor");
82 configure(
int type,
int value)
84 if(type == SENSORS_HW_INIT) {
85 PRINTF(
"SENSORS_HW_INIT\n");
86 ht_sensor_status = HT_SENSOR_STATUS_INIT;
89 }
else if(type == SENSORS_ACTIVE) {
90 if(ht_sensor_status != HT_SENSOR_STATUS_NOT_INIT) {
94 prev_temp_event_val = 0;
95 prev_hum_event_val = 0;
97 PRINTF(
"HT SENSOR ACTIVATED\n");
98 ht_sensor_status = HT_SENSOR_STATUS_ACTIVE;
99 process_post(&HTSensorSampling, PROCESS_EVENT_MSG, (
void *)&ht_sensor_status);
102 PRINTF(
"HT SENSOR DE-ACTIVATED\n");
103 ht_sensor_status = HT_SENSOR_STATUS_NOT_ACTIVE;
104 process_post(&HTSensorSampling, PROCESS_EVENT_MSG, (
void *)&ht_sensor_status);
109 PRINTF(
"ERROR: NO HW_INIT HT SENSOR\n");
121 if(type == SENSORS_ACTIVE) {
122 return ht_sensor_status == HT_SENSOR_STATUS_ACTIVE;
123 }
else if(type == SENSORS_READY) {
124 return ht_sensor_status != HT_SENSOR_STATUS_NOT_INIT;
134 if(type == HT_SENSOR_TEMP) {
135 return temp_sensor_value;
137 return hum_sensor_value;
155 if(ev == PROCESS_EVENT_TIMER) {
158 temp_sensor_value = u16HTSreadTempResult();
159 PRINTF(
"Temperature sample: %d\n", temp_sensor_value);
160 vHTSstartReadHumidity();
161 hum_sensor_value = u16HTSreadHumidityResult();
162 PRINTF(
"Humidity sample: %d\n", hum_sensor_value);
163 if((
abs(temp_sensor_value - prev_temp_event_val) > DELTA_TEMP_SENSOR_VALUE) ||
164 (
abs(hum_sensor_value - prev_hum_event_val) > DELTA_HUM_SENSOR_VALUE)) {
165 prev_temp_event_val = temp_sensor_value;
166 prev_hum_event_val = hum_sensor_value;
167 sensors_changed(&ht_sensor);
172 if(*(
int *)data == HT_SENSOR_STATUS_NOT_ACTIVE) {
175 }
else if((*(
int *)data == HT_SENSOR_STATUS_ACTIVE)) {
186 SENSORS_SENSOR(ht_sensor, HT_SENSOR, value, configure, status);
void etimer_restart(struct etimer *et)
Restart an event timer from the current point in time.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS_END()
Define the end of a process.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
static struct etimer et
NIC receiver thread.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
void etimer_stop(struct etimer *et)
Stop a pending event timer.
#define NULL
The null pointer.
#define CLOCK_SECOND
A second, measured in system clock time.
void process_start(struct process *p, process_data_t data)
Start a process.
int abs(int I)
Returns the absolute value of I (also called the magnitude of I).
void etimer_reset(struct etimer *et)
Reset an event timer with the same interval as was previously set.
#define PROCESS_BEGIN()
Define the beginning of a process.