forked from lebipbip/le-BipBip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensor.c
204 lines (181 loc) · 3.3 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* sensor.c
*
* Created on: 31 mars 2012
* Author: timothee
*/
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <msp430.h>
#include <legacymsp430.h>
#include "target.h"
#include "sensor.h"
#include "data.h"
#include "buzzer.h"
#include "oscillator.h"
#ifdef SENSOR_SIMULATED
void SensorSimuStart(void)
{
}
void SensorSimuStop(void)
{
}
void SensorStartTemperatureSampling(void)
{
}
uint32_t SensorReadTemperatureWhenAvailable(void)
{
delay_ms(8);
return 0;
}
void SensorSimuStartPressureSampling (void)
{
}
uint32_t SensorReadPressureWhenAvailable(void)
{
delay_ms(8);
return 0;
}
int32_t SensorSimuCompensateTemperature(uint32_t D2) // Compensate temperature
{
return 0;
}
uint32_t SensorSimuCompensatePressure(uint32_t D1) // Compensate pressure
{
#ifdef DEMO
static uint32_t pressure = 990000;
static uint8_t demoState = 10;
static uint16_t demoStateTime = 0;
static bool div2 = false;
static uint8_t div16 = 0;
static uint8_t div10 = 0;
switch (demoState)
{
case 10: // +0m/s
demoStateTime = (10000)/TASK_PERIOD_MS;
demoState = 20;
break;
case 20:
if (div2)
pressure++;
div2 = !div2;
demoStateTime--;
demoState = 31;
break;
case 31: // -0.15m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 41;
break;
case 41:
if (!div16)
{
pressure++;
div16 = 30;
}
else
div16--;
demoStateTime--;
if (!demoStateTime)
demoState = 30;
break;
case 30: // +0.15m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 40;
break;
case 40:
if (!div16)
{
pressure--;
div16 = 15;
}
else
div16--;
demoStateTime--;
if (!demoStateTime)
demoState = 50;
break;
case 50: // +0.35m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 60;
break;
case 60:
if (!div10)
{
pressure--;
div10 = 8;
}
else
div10--;
demoStateTime--;
if (!demoStateTime)
demoState = 70;
break;
case 70: // +1.5m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 80;
break;
case 80:
if (div2)
pressure--;
div2 = !div2;
demoStateTime--;
if (!demoStateTime)
demoState = 90;
break;
case 90: // -6m/s
demoStateTime = (2000)/TASK_PERIOD_MS;
demoState = 100;
break;
case 100:
pressure = pressure+2;
demoStateTime--;
if (!demoStateTime)
demoState = 110;
break;
case 110: // +3m/s
demoStateTime = (2000)/TASK_PERIOD_MS;
demoState = 120;
break;
case 120:
pressure = pressure-1;
demoStateTime--;
if (!demoStateTime)
demoState = 130;
break;
case 130: // +6m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 140;
break;
case 140:
pressure = pressure-2;
demoStateTime--;
if (!demoStateTime)
demoState = 150;
break;
case 150: // +9m/s
demoStateTime = (1500)/TASK_PERIOD_MS;
demoState = 160;
break;
case 160:
pressure = pressure-3;
demoStateTime--;
if (!demoStateTime)
demoState = 10;
break;
default:
demoState = 10;
break;
}
return pressure;
#else
static int index = 0;
if ((index++) == sizeof(DataSampleElevator)/sizeof(DataSampleElevator[0])-1)
{
index = 0;
BuzzerSetBlocking(2000,1000);
}
return DataSampleElevator[index];
#endif //DEMO
}
#endif // SENSOR_SIMULATED