-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.lua
131 lines (115 loc) · 2.49 KB
/
project.lua
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
scriptId = 'com.project'
locked = true
getOut = false
inLoop = false
count = 0
unlockedSince = 0
turn = false
lastTime = 0
previousTime = 0
appTitle = ''
function onForegroundWindowChange(app, title)
myo.debug("Title: " .. title)
appTitle = title
return true
end
function activeAppName()
return appTitle
end
function onPoseEdge(pose, edge)
pose = conditionallySwapWave(pose)
if(edge == "on") then
if (pose == "thumbToPinky") then
toggleLock()
end
if (not locked) then
if (pose == "waveIn" ) then
nextSong()
elseif (pose == "waveOut") then
prevSong()
elseif (pose == "fist") then
play()
elseif (pose == "fingersSpread") then
initRoll = myo.getRoll()
turn = true
end
end
else
turn = false
end
end
function toggleLock()
locked = not locked
if (locked) then
myo.vibrate("short")
myo.keyboard("left_alt", "down")
while not (count == 0) do
myo.keyboard("tab", "press")
count = count - 1
end
myo.keyboard("left_alt", "up")
start = myo.getTimeMilliseconds()
while (myo.getTimeMilliseconds() - start < 250) do
end
else
myo.vibrate("medium")
doTab = true
end
end
function nextSong()
myo.keyboard("right_arrow", "press")
end
function prevSong()
myo.keyboard("left_arrow", "press")
end
function play()
myo.keyboard("space", "press")
end
function adjustVolume()
end
function volumeDown()
now = myo.getTimeMilliseconds()
if (now - lastTime > 250) then
myo.keyboard("down_arrow", "press", "control")
lastTime = myo.getTimeMilliseconds()
end
end
function volumeUp()
now = myo.getTimeMilliseconds()
if (now - lastTime > 250) then
myo.keyboard("up_arrow", "press", "control")
lastTime = myo.getTimeMilliseconds()
end
end
function onPeriodic()
if (turn) then
if (myo.getRoll() - initRoll > 0.1) then
volumeUp()
elseif (myo.getRoll() - initRoll < -0.1) then
volumeDown()
end
end
if not (activeAppName() == "MiniPlayer")and doTab then
count = count + 1
myo.keyboard("left_alt", "down" )
for i = 1, count, 1 do
myo.keyboard("tab", "press")
end
myo.keyboard("left_alt", "up")
start = myo.getTimeMilliseconds()
while (myo.getTimeMilliseconds() - start < 250) do
end
else
doTab = false
end
end
function conditionallySwapWave(pose)
if myo.getArm() == "left" then
if pose == "waveIn" then
pose = "waveOut"
elseif pose == "waveOut" then
pose = "waveIn"
end
end
return pose
end