-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhum_sensor.cpp
61 lines (42 loc) · 1.28 KB
/
hum_sensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "hum_sensor.h"
extern action_union actions[];
extern uint8_t act_size;
unsigned long last_hum_measure;
uint8_t hum_measure(uint8_t data[], size_t data_len) {
unsigned long current_time;
current_time = millis();
if((current_time-last_hum_measure) < HUM_MEASURE_INTERVAL) {
return 0;
}
last_hum_measure = current_time;
int _value;
_value = analogRead(HUM_SENSOR_PIN);
_value = _value / 4; // up to 256
uint8_t value = _value;
Serial.print("Humidity Sensor sending: ");
Serial.println(value);
/* Preparing controller call */
const proc_union hum_controller = {10, {value}, 1};
uint8_t msg[MAX_MSG_SIZE];
size_t msg_len;
/* Controller call */
if(is_installed(hum_controller.action_id)) {
add_dyn_proc(&hum_controller);
}
else {
addr_t emitter = NODE_ADDR;
msg_builder(emitter, hum_controller, msg, &msg_len);
send_msg(msg, msg_len);
}
return 0;
}
void setup_hum_sensor() {
pinMode(HUM_SENSOR_PIN, INPUT);
action_union act = {11, hum_measure};
actions[act_size] = act;
act_size++;
proc_union proc = {11, {}, 0};
add_reg_proc(&proc);
last_hum_measure = millis();
return;
}