-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.go
170 lines (152 loc) · 4.38 KB
/
actions.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
170
package main
import (
"log"
"time"
"github.com/thiefmaster/controller/apis"
"github.com/thiefmaster/controller/comm"
"github.com/thiefmaster/controller/ddc"
)
func showFancyIntro(cmdChan chan<- comm.Command, delay time.Duration) {
for i := knob; i <= buttonBottomRight; i++ {
cmdChan <- comm.NewClearLEDCommand(i)
}
for i := LED5; i <= LED1; i++ {
cmdChan <- comm.NewClearLEDCommand(i)
time.Sleep(delay)
}
}
func showFancyOutro(cmdChan chan<- comm.Command) {
for i := knob; i <= buttonBottomRight; i++ {
cmdChan <- comm.NewClearLEDCommand(i)
}
for j := 0; j < 2; j++ {
for i := LED5; i <= LED1; i++ {
cmdChan <- comm.NewSetLEDCommand(i, '1')
time.Sleep(50 * time.Millisecond)
}
for i := LED1; i >= LED5; i-- {
cmdChan <- comm.NewClearLEDCommand(i)
time.Sleep(50 * time.Millisecond)
}
}
}
func toggleMonitors(cmdChan chan<- comm.Command, state *appState) {
if state.monitorsOn {
log.Printf("turning monitors off")
ddc.SetMonitorsStandby()
} else {
log.Printf("turning monitors on")
ddc.SetMonitorsOn()
}
state.monitorsOn = !state.monitorsOn
cmdChan <- comm.NewToggleLEDCommand(buttonBottomRight, !state.monitorsOn)
}
func lockDesktop(state *appState) {
log.Println("locking desktop")
apis.LockDesktop()
if state.config.Numlock {
apis.SetNumLock(false)
}
}
func playStopAnimation(cmdChan chan<- comm.Command) {
go func() {
for i := 0; i < 5; i++ {
cmdChan <- comm.NewSetLEDCommand(knob, 'R')
time.Sleep(100 * time.Millisecond)
}
}()
go func() {
time.Sleep(50 * time.Millisecond)
for i := 0; i < 5; i++ {
time.Sleep(100 * time.Millisecond)
cmdChan <- comm.NewSetLEDCommand(knob, 'Y')
}
cmdChan <- comm.NewClearLEDCommand(knob)
}()
}
func foobarNext(state *appState, cmdChan chan<- comm.Command) {
log.Println("playing next song")
if err := apis.FoobarNext(state.config.Foobar); err != nil {
log.Printf("foobar next failed: %v\n", err)
return
}
cmdChan <- comm.NewSetLEDCommand(knob, 'R')
time.AfterFunc(150*time.Millisecond, func() {
cmdChan <- comm.NewSetLEDCommand(knob, 'G')
time.AfterFunc(150*time.Millisecond, func() {
cmdChan <- newCommandForFoobarState(state)
})
})
}
func foobarStop(state *appState, cmdChan chan<- comm.Command) {
log.Println("stopping playback")
if err := apis.FoobarStop(state.config.Foobar); err != nil {
log.Printf("foobar stop failed: %v\n", err)
return
}
playStopAnimation(cmdChan)
}
func foobarTogglePause(state *appState) {
log.Println("toggling pause")
if err := apis.FoobarTogglePause(state.foobarState, state.config.Foobar); err != nil {
log.Printf("foobar pause failed: %v\n", err)
}
}
func foobarAdjustVolume(state *appState, cmdChan chan<- comm.Command, delta int) {
log.Printf("adjusting volume by %+d\n", delta)
volume, isMin, isMax, err := apis.FoobarAdjustVolume(state.foobarState, float64(delta), state.config.Foobar)
if err != nil {
log.Printf("foobar volume change failed: %v\n", err)
return
}
log.Printf("new volume: %f\n", volume)
if isMin {
cmdChan <- comm.NewSetLEDCommand(knob, 'R')
time.AfterFunc(1*time.Second, func() {
cmdChan <- newCommandForFoobarState(state)
})
} else if isMax {
cmdChan <- comm.NewSetLEDCommand(knob, 'G')
time.AfterFunc(1*time.Second, func() {
cmdChan <- newCommandForFoobarState(state)
})
}
}
func foobarSeek(state *appState, delta int) {
log.Printf("seeking %+d", delta)
if err := apis.FoobarSeekRelative(delta*5, state.config.Foobar); err != nil {
log.Printf("foobar seek failed: %v\n", err)
return
}
}
func newCommandForFoobarState(state *appState) comm.Command {
if state.foobarState.State == apis.FoobarStatePaused {
return comm.NewSetLEDCommand(knob, 'Y')
} else {
return comm.NewClearLEDCommand(knob)
}
}
func tubeRemoteTogglePause() {
log.Println("toggling youtube pause")
apis.TubeRemoteTogglePause()
}
func tubeRemoteStop(cmdChan chan<- comm.Command) {
log.Println("stopping youtube")
apis.TubeRemoteStop()
playStopAnimation(cmdChan)
}
func tubeRemoteAdjustVolume(delta int) {
log.Printf("adjusting youtube volume by %+d\n", delta)
apis.TubeRemoteAdjustVolume(delta * 2)
}
func tubeRemoteSeek(delta int) {
log.Printf("seeking %+d on youtube\n", delta)
apis.TubeRemoteSeek(delta * 5)
}
func newCommandForTubeRemoteState(state *appState) comm.Command {
if state.tubeRemoteState.State == apis.TubeRemoteStatePaused {
return comm.NewSetLEDCommand(knob, 'Y')
} else {
return comm.NewClearLEDCommand(knob)
}
}