-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.cpp
65 lines (59 loc) · 2.72 KB
/
user.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
62
63
64
65
#if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
// This file provides a crude way to "drop in" user code to the eyes,
// allowing concurrent operations without having to maintain a bunch of
// special derivatives of the eye code (which is still undergoing a lot
// of development). Just replace the source code contents of THIS TAB ONLY,
// compile and upload to board. Shouldn't need to modify other eye code.
// User globals can go here, recommend declaring as static, e.g.:
// static int foo = 42;
// Called once near the end of the setup() function.
void user_setup(void) {
}
// Called periodically during eye animation. This is invoked in the
// interval before starting drawing on the last eye so it won't exacerbate
// visible tearing in eye rendering.
// This function BLOCKS, it does NOT multitask with the eye animation code,
// and performance here will have a direct impact on overall refresh rates,
// so keep it simple. Avoid loops (e.g. if animating something like a servo
// or NeoPixels in response to some trigger) and instead rely on state
// machines or similar. Additionally, calls to this function are NOT time-
// constant -- eye rendering time can vary frame to frame, so animation or
// other over-time operations won't look very good using simple +/-
// increments, it's better to use millis() or micros() and work
// algebraically with elapsed times instead.
void user_loop(void) {
/*
Suppose we have a global bool "animating" (meaning something is in
motion) and global uint32_t's "startTime" (the initial time at which
something triggered movement) and "transitionTime" (the total time
over which movement should occur, expressed in microseconds).
Maybe it's servos, maybe NeoPixels, or something different altogether.
This function might resemble something like (pseudocode):
if(!animating) {
Not in motion, check sensor for trigger...
if(read some sensor) {
Motion is triggered! Record startTime, set transition
to 1.5 seconds and set animating flag:
startTime = micros();
transitionTime = 1500000;
animating = true;
No motion actually takes place yet, that will begin on
the next pass through this function.
}
} else {
Currently in motion, ignore trigger and move things instead...
uint32_t elapsed = millis() - startTime;
if(elapsed < transitionTime) {
Part way through motion...how far along?
float ratio = (float)elapsed / (float)transitionTime;
Do something here based on ratio, 0.0 = start, 1.0 = end
} else {
End of motion reached.
Take whatever steps here to move into final position (1.0),
and then clear the "animating" flag:
animating = false;
}
}
*/
}
#endif // 0