-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyThirdScript.lua
96 lines (81 loc) · 2.46 KB
/
MyThirdScript.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
scriptId = 'edu.stanford.myo.mythirdscript'
scriptTitle = "My Third Script"
scriptDetailsUrl = ""
locked = true
myo.setLockingPolicy("none")
appTitle = ""
function onForegroundWindowChange(app, title)
myo.debug("onForegroundWindowChange: " .. app .. ", " .. title)
appTitle = title
return true
end
function activeAppName()
return appTitle
end
function onPoseEdge(pose, edge)
myo.debug("onPoseEdge: " .. pose .. ": " .. edge)
pose = conditionallySwapWave(pose)
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
local keyEdge = edge == "off" and "up" or "down"
-- if (pose == "waveOut") then
-- onWaveOut(keyEdge)
-- elseif (pose == "waveIn") then
-- onWaveIn(keyEdge)
-- elseif (pose == "fist") then
-- onFist(keyEdge)
-- elseif (pose == "fingersSpread") then
-- onFingersSpread(keyEdge)
-- end
x, y, z = myo.getAccel()
strength = x*x + y*y + z*z
strength = math.sqrt(strength)
yawn = myo.getYaw()
pitch = myo.getPitch()
roll = myo.getRoll()
if (strength < 0.9) then
myo.debug(" block " .. strength)
myo.debug(" yaw = " .. yawn .. " pitch = " .. pitch .. " roll = " .. roll)
elseif (strength < 1.3 and roll > 0.5) then
myo.debug(" uppercut " .. strength)
-- myo.debug(" yaw = " .. yawn .. " pitch = " .. pitch .. " roll = " .. roll)
elseif (strength < 1.8 and roll < 0) then
myo.debug(" jab " .. strength)
elseif (strength > 1.8) then
myo.debug(" high " .. strength)
end
--myo.debug("x = " .. x .. ", y = " .. y .. ", z = " .. z)
end
function onWaveOut(keyEdge)
myo.debug("Next")
--myo.vibrate("short")
myo.keyboard("tab", keyEdge)
end
function onWaveIn(keyEdge)
myo.debug("Previous")
--myo.vibrate("short")
--myo.vibrate("short")
myo.keyboard("tab",keyEdge,"shift")
end
function onFist(keyEdge)
myo.debug("Enter")
--myo.vibrate("medium")
myo.keyboard("return",keyEdge)
end
function onFingersSpread(keyEdge)
myo.debug("Escape")
--myo.vibrate("long")
myo.keyboard("escape", keyEdge)
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