-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
94 lines (78 loc) · 1.31 KB
/
main.ino
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
/*
Dependencies.
*/
#ifndef ARDUINO
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#endif
/*
Globals.
*/
volatile enum state { IDLE, SCANNING, RESETTING, FAIL_SD, FAIL_SENSOR } state;
/*
Functions.
*/
#include "interface.h"
#ifndef ARDUINO
void delay(int ms)
{
// #define USE_ARTIFICIAL_DELAY
#ifdef USE_ARTIFICIAL_DELAY
#ifdef WIN32
Sleep(ms);
#else
usleep(ms * 1000 /* microseconds */ );
#endif
#endif
}
#endif
void fail(enum state s)
{
state = s;
showState();
while (true);
}
#include "storage.h"
#include "scan.h"
#include "sensor.h"
#include "motors.h"
void setup()
{
setupInterface();
setupStorage();
setupSensor();
setupMotors();
// #define CALIBRATION_MODE
#ifdef CALIBRATION_MODE
/* Lower sensor. */ digitalWrite(PIN_DIR_TOWER, HIGH);
// /* Raise sensor. */ digitalWrite(PIN_DIR_TOWER, LOW);
for (int s = 0; s < 100 /* Number of steps to move per reset. */; ++s) {
digitalWrite(PIN_STEP_TOWER, HIGH);
delayMicroseconds(TOWER_STEP_HALF_DELAY_uS);
digitalWrite(PIN_STEP_TOWER, LOW);
delayMicroseconds(TOWER_STEP_HALF_DELAY_uS);
}
#endif
}
void loop()
{
#ifndef CALIBRATION_MODE
if (state == SCANNING) {
showState();
scan();
}
state = IDLE;
showState();
#endif
}
#ifndef ARDUINO
int main()
{
setup();
toggleState();
loop();
}
#endif