-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
137 lines (107 loc) · 2.64 KB
/
main.go
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
//go:build rp2040
// +build rp2040
package main
import (
"fmt"
"machine"
"time"
"golang.org/x/image/colornames"
)
func main() {
// mcu, _ := newMCU()
// mcu.lcd.FillScreen(colornames.Black)
// tinydraw.Rectangle(mcu, 40, 40, 160, 160, colornames.White)
// from := V(127, 127)
// to := V(60, 0).Rotated(math32.Pi / 6).Add(from)
// tinydraw.Line(mcu, int16(from.X), int16(from.Y), int16(to.X), int16(to.Y), colornames.White)
// temp := to.Sub(from).Normal().Add(from)
// tinydraw.Line(mcu, int16(from.X), int16(from.Y), int16(temp.X), int16(temp.Y), colornames.White)
// mcu.Display()
// for {
// time.Sleep(time.Second)
// }
if err := run(); err != nil {
for {
fmt.Println("error calling newDisplay:", err)
time.Sleep(time.Second)
}
}
}
func run() error {
mcu, err := newMCU(5 * time.Minute)
if err != nil {
return err
}
spiral := &spiral{}
everyMin := time.Unix(0, 0)
everySec := time.Unix(0, 0)
wasSleeping := true
var minHand, hourHand Line
now := time.Now()
timeSet := false
min := minSinceMidnight(now)
t := timedata[min]
im := t.imaginary
mi := t.index
var offset time.Duration
for {
now = time.Now().Add(offset)
// if the time hasn't been set yet
// and the user pressed enter, get the time
if !timeSet && machine.Serial.Buffered() > 0 {
// if the user pressed enter go into setup
for machine.Serial.Buffered() > 0 {
b, _ := machine.Serial.ReadByte()
if b == '\r' || b == '\n' {
offset = time.Until(getUserTime())
now = time.Now().Add(offset)
everyMin = time.Unix(0, 0)
timeSet = true
fmt.Println("time set to:", now, "\r")
break
}
}
}
if now.Sub(everySec) > time.Second {
fmt.Printf("bat(v):%.2f,sleeping:%v\r\n", mcu.Volts(), wasSleeping)
everySec = now
}
//
// Check for movement / sleep
//
if mcu.Sleeping() {
wasSleeping = true
time.Sleep(500 * time.Millisecond)
continue
} else if wasSleeping {
wasSleeping = false
min = minSinceMidnight(now)
t = timedata[min]
im = t.imaginary
mi = t.index
}
mcu.FillDisplay(colornames.Black)
spiral.calc(.5, im)
// Every minute, get the new imaginary value
if now.Sub(everyMin) > time.Minute {
min = minSinceMidnight(now)
t = timedata[min]
im = t.imaginary
mi = t.index
spiral.calc(.5, im)
minHand.B = spiral.joints[mi]
minHand.A = spiral.joints[mi+1]
hourHand.A = spiral.joints[mi+1]
hourHand.B = spiral.joints[mi+2]
everyMin = now
}
spiral.draw(mcu, mi)
if timeSet {
drawHand(mcu, hourHand, .6, colornames.Red)
drawHand(mcu, minHand, .9, colornames.Orange)
}
mcu.DrawBattery(3.8)
mcu.Display()
im += .004
}
}