-
Notifications
You must be signed in to change notification settings - Fork 5
/
MediaKeys.myo
93 lines (82 loc) · 2.24 KB
/
MediaKeys.myo
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
scriptId = 'com.jakechapeskie.media'
minMyoConnectVersion ='0.8.1'
scriptDetailsUrl = 'https://market.myo.com/app/54eb721ee4b07a1270f42ca2'
scriptTitle = 'Global Media Keys'
ROLL_MOTION_THRESHOLD = 7 -- degrees
SLOW_MOVE_PERIOD = 20
ROLL_INTERVAL = 5
rollReference=0
rolls = 0
enabled=false
myo.setLockingPolicy("standard")
function onForegroundWindowChange(app, title)
return true
end
function activeAppName()
return scriptTitle
end
function getMyoRollDegrees()
local RollValue = math.deg(myo.getRoll())
return RollValue
end
function onUnlock()
enabled=false
end
function degreeDiff(value, base)
local diff = value - base
if diff > 180 then
diff = diff - 360
elseif diff < -180 then
diff = diff + 360
end
return diff
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
function onPoseEdge(pose, edge)
pose=conditionallySwapWave(pose)
local now = myo.getTimeMilliseconds()
if (pose ~= "rest" and pose ~= "unknown") then
-- hold if edge is on, timed if edge is off
myo.unlock(edge == "off" and "timed" or "hold")
end
--Hold to activate
if edge == "on" then
if pose == "fist" then
moveActive = edge == "on"
rollReference = getMyoRollDegrees()
rolls = 0
enabled=true
elseif pose =="waveIn" then
myo.mediaKey("previous")
elseif pose =="waveOut" then
myo.mediaKey("next")
elseif pose =="fingersSpread" then
myo.mediaKey("play_pause")
else
enabled=false
end
end
end
function onPeriodic()
if (enabled) then
local relativeRoll = degreeDiff(getMyoRollDegrees(), rollReference)
local newRolls = math.floor(relativeRoll / ROLL_INTERVAL)
local volumeKey = newRolls < rolls and "volume_down" or "volume_up"
local deltaRolls = math.abs(newRolls - rolls)
if (deltaRolls > 0) then
for i=1,deltaRolls do
myo.mediaKey(volumeKey);
end
end
rolls = newRolls
end
end