forked from spqr/umichmoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.c
87 lines (77 loc) · 1.87 KB
/
sensor.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "sensor.h"
#include "string.h"
#include "compiler.h"
static const struct sensor ** sg_sensor_space_end = 0;
void init_sensors() {
int ret;
const struct sensor ** s = __sensor_init_begin;
const struct sensor ** end = __sensor_init_end;
const struct sensor ** space_s = __sensor_space_begin;
const struct sensor ** space_end = __sensor_space_end;
const struct sensor ** space_ptr = space_s;
while (space_ptr != space_end) {
/* Make sure there are no valid sensors before calling init */
*space_ptr++ = 0;
}
space_ptr = space_s;
while (s != end) {
ret = (*s)->init();
if (ret == 0) {
*space_ptr++ = *s;
}
sg_sensor_space_end = space_ptr;
s++;
}
}
const struct sensor * getSensorByName(const char *name, int active) {
const struct sensor ** space_s;
const struct sensor ** space_end;
if (active) {
space_s = __sensor_space_begin;
space_end = sg_sensor_space_end;
}
else {
space_s = __sensor_init_end;
space_end = __sensor_init_end;
}
while (space_s != space_end) {
if (strcmp((*space_s)->name, name) == 0) {
return *space_s;
}
space_s++;
}
return 0;
}
const struct sensor * getSensorById(uint8_t id, int active) {
const struct sensor ** space_s;
const struct sensor ** space_end;
if (active) {
space_s = __sensor_space_begin;
space_end = sg_sensor_space_end;
}
else {
space_s = __sensor_init_end;
space_end = __sensor_init_end;
}
while (space_s != space_end) {
if ((*space_s)->sensor_id == id) {
return *space_s;
}
space_s++;
}
return 0;
}
const struct sensor ** getSensorIter() {
return __sensor_space_begin;
}
const struct sensor **getSensorNext(const struct sensor ** sensorIter) {
const struct sensor ** space_end = sg_sensor_space_end;
const struct sensor ** space_s = __sensor_space_begin;
sensorIter++;
if (sensorIter < space_s || sensorIter >= space_end) {
return 0;
}
else {
return sensorIter;
}
}