-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.pde
129 lines (112 loc) · 3.85 KB
/
template.pde
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
// increase the heap size from 2k to 8k.
#define CHANGE_HEAP_SIZE(size) __asm__ volatile ("\t.globl _min_heap_size\n\t.equ _min_heap_size, " #size "\n")
CHANGE_HEAP_SIZE(0x2000);
//extern __attribute__((section("linker_defined"))) char _heap;
//extern __attribute__((section("linker_defined"))) char _min_heap_size;
#include <WProgram.h>
#include <HardwareSerial.h>
#include <Antikythera.h>
#include <ATKColor.h>
//#include <WS2801.h>
#include <WS2811.h>
#define NUM_DISPLAYS 1
//#define DISPLAY_WIDTH 8
//#define DISPLAY_HEIGHT 38
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 2
#define DISPLAY_LAYERS 1
// device management
#define SERIAL_READ_TIMEOUT 1000
#define ANTIKYTHERA_TIMEOUT 25 // 40 fps
#define GPS_READ_TIMEOUT 1000
#define COMPASS_READ_TIMEOUT 250
#define ACCELEROMETER_READ_TIMEOUT 250
#define TOUCH_READ_TIMEOUT 250
struct TIMERS {
bool serialEnabled;
unsigned long serialRead;
bool antikytheraEnabled;
unsigned long antikythera;
bool gpsEnabled;
unsigned long gpsRead;
bool compassEnabled;
unsigned long compassRead;
bool accelerometerEnabled;
unsigned long accelerometerRead;
bool touchEnabled;
unsigned long touchRead;
};
TIMERS timers;
char out[128];
void setup()
{
Serial.begin(115200);
randomSeed(analogRead(0));
Serial.println("randomSeed set");
// WS2801 *ws2801 = new WS2801((p32_spi *) _SPI2_BASE_ADDRESS, PIN_DSPI0_SS);
// Serial.println("WS2801 object instantiated");
// ws2801->initialize(DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_LAYERS);
// Serial.println("WS2801 initialized");
WS2811 *ws2811 = new WS2811(4, 5);
Serial.println("WS2811 object instantiated");
ws2811->initialize(DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_LAYERS);
Serial.println("WS2811 initialized");
Antikythera::numDisplays = NUM_DISPLAYS;
Antikythera::displays = new ATKIDisplay*[NUM_DISPLAYS];
Serial.println("ATK added display pointers");
// Antikythera::displays[0] = ws2801;
// Serial.println("set ATK display[0] = WS2801");
Antikythera::displays[0] = ws2811;
Serial.println("set ATK display[0] = WS2811");
Serial.println("Send initial program.");
timers.serialEnabled = true;
}
void loop()
{
unsigned long now = millis();
if (timers.gpsEnabled && (timers.gpsRead + GPS_READ_TIMEOUT) <= now) {
timers.gpsRead = now;
now = millis();
}
if (timers.compassEnabled && (timers.compassRead + COMPASS_READ_TIMEOUT) <= now) {
timers.compassRead = now;
now = millis();
}
if (timers.accelerometerEnabled && (timers.accelerometerRead + ACCELEROMETER_READ_TIMEOUT) <= now) {
timers.accelerometerRead = now;
now = millis();
}
if (timers.antikytheraEnabled && (timers.antikythera + ANTIKYTHERA_TIMEOUT) <= now) {
#ifdef ANTIKYTHERA_DEBUG
if (!Antikythera::evaluate(now, &Serial)) {
#else
if (!Antikythera::evaluate(now)) {
#endif
timers.antikytheraEnabled = false;
Serial.print("\nError running program: ");
#ifdef ANTIKYTHERA_DEBUG
Serial.println(Antikythera::lastErrorString);
#endif
}
timers.antikythera = now;
now = millis();
sprintf(out, "time(%lu) elapsed:%lu", timers.antikythera, (now - timers.antikythera));
Serial.println(out);
}
if (timers.serialEnabled && (timers.serialRead + SERIAL_READ_TIMEOUT) <= now) {
if (Serial.available() > 0) {
if (Antikythera::load(&Serial)) {
Serial.println("\nProgram loaded and running.");
timers.antikytheraEnabled = true;
} else {
Serial.print("\nError loading program: ");
timers.antikytheraEnabled = false;
#ifdef ANTIKYTHERA_DEBUG
Serial.println(Antikythera::lastErrorString);
#endif
}
}
timers.serialRead = now;
// now = millis();
}
}