-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
169 lines (142 loc) · 3.7 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
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
package main
import (
"image/color"
"machine"
"reflect"
"github.com/davidadeleon/gophercon2022Badge/button"
"github.com/davidadeleon/gophercon2022Badge/il0373"
"github.com/davidadeleon/gophercon2022Badge/neopixel"
"tinygo.org/x/drivers/apds9960"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freemono"
"tinygo.org/x/tinyfont/gophers"
)
const (
width = 128
height = 296
)
var (
eDisplay *il0373.Device
neoPixelStickController = neopixel.NeoPixelController{
Pin: machine.GPIO26,
}
sensor = apds9960.New(machine.I2C1)
eController = neopixel.EffectsController{APDS9960: &sensor}
// RGBA Colors for Text Printing
//white := color.RGBA{0, 0, 0, 255}
red = color.RGBA{255, 0, 0, 255}
black = color.RGBA{255, 255, 255, 255}
)
func init() {
// Init SPI0
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 1000000,
Mode: 0,
})
// Init I2C1
machine.I2C1.Configure(machine.I2CConfig{
SCL: machine.SCL_PIN,
SDA: machine.SDA_PIN,
Frequency: machine.TWI_FREQ_400KHZ,
})
}
func main() {
println("[GC22_Badge] Starting!")
// Setup NeoPixel Stick and fill witn inital color
neoPixelStickController.Init(8)
// Setup APDS9960 Sensor
sensor.Configure(apds9960.Configuration{})
sensor.EnableGesture()
// Setup IL0373 ePaper Display
println("[GC22_Badge] Initializing display...")
eDisplay = il0373.New(
width,
height,
machine.SPI0, // SPI
machine.D9, // CS Pin
machine.D10, // DC Pin
machine.NoPin, // SRAM CS Pin
machine.NoPin, // RST Pin
machine.NoPin, // BUSY Pin
)
eDisplay.Initialize()
eDisplay.SetRotation(0)
println("[GC22_Badge] Initialized!")
// Display Namebadge
//NameBadgeDisplay()
// Create Effects Controller
eController.Init(&neoPixelStickController)
eController.Start()
// Create Button Manager
buttonManager := button.ButtonManager{
Watcher: make(chan string),
}
// Create Buttons
aButton := button.Button{
Name: "A",
Pin: machine.D11,
Mode: machine.PinInputPullup,
Action: eController.ChangeEffect,
}
bButton := button.Button{
Name: "B",
Pin: machine.D12,
Mode: machine.PinInputPullup,
Action: ChangeColor,
}
cButton := button.Button{
Name: "C",
Pin: machine.D13,
Mode: machine.PinInputPullup,
Action: eController.StopEffects,
}
// Register Buttons to Manager
buttonManager.Register(&aButton, &bButton, &cButton)
// Start Manager
buttonManager.Start()
}
func NameBadgeDisplay() {
// Clear ePaper Display
println("[GC22_Badge] Clearing Display")
eDisplay.Fill(il0373.WHITE)
// Lazy fix reversed image
for _, row := range qr_code_github_buf {
reverseSlice(row)
}
// Display
println("[GC22_Badge] Display...")
eDisplay.DisplayImage(width, height, qr_code_github_buf)
tinyfont.WriteLineRotated(eDisplay, &freemono.Bold18pt7b, 35, 290, "David", black, tinyfont.ROTATION_270)
tinyfont.WriteLineRotated(eDisplay, &freemono.Bold18pt7b, 65, 290, "De Leon", black, tinyfont.ROTATION_270)
tinyfont.WriteLineRotated(eDisplay, &gophers.Regular58pt, 125, 290, "E", black, tinyfont.ROTATION_270)
tinyfont.WriteLineRotated(eDisplay, &freemono.Regular9pt7b, 105, 245, "Built using", red, tinyfont.ROTATION_270)
tinyfont.WriteLineRotated(eDisplay, &freemono.Bold9pt7b, 120, 245, "TinyGo!", red, tinyfont.ROTATION_270)
eDisplay.Display()
eDisplay.PowerDown()
println("[GC22_Badge] Done!")
}
func ChangeColor() {
eController.ColorCh <- struct{}{}
}
func ClearPixelBar() {
neoPixelStickController.Clear()
}
/*
func EffectRGB(stopCh chan struct{}) {
for {
select {
case <-stopCh:
return
default:
for
}
}
}
*/
func reverseSlice(s interface{}) {
n := reflect.ValueOf(s).Len()
swap := reflect.Swapper(s)
for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
swap(i, j)
}
}