-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyFirstLuaScript.lua
83 lines (69 loc) · 1.49 KB
/
MyFirstLuaScript.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
scriptId = "com.MyFirstScript"
position = 0
function onForegroundWindowChange(app, title)
if (title == "Myo Runaway") then
return true
end
end
function onActiveChange(isActive)
myo.controlMouse(true)
xStart = myo.getRoll()
end
function onPeriodic()
xRoll = myo.getRoll()
changeInX = xRoll - xStart
if (changeInX < -0.1) then
if (not(position == -1)) then
position = -1
myo.keyboard("a", "press")
end
elseif (changeInX > 0.1) then
if (not(position == 1)) then
position = 1
myo.keyboard("d", "press")
end
elseif (changeInX > -0.05 and changeInX < 0.05) then
if (position == -1) then
myo.keyboard("d", "press")
elseif (position == 1) then
myo.keyboard("a", "press")
end
position = 0
end
end
function onPoseEdge(pose, edge)
pose = conditionallySwapWave(pose)
if (edge == "on") then
if (pose == "waveOut") then
onWaveOut()
elseif (pose == "waveIn") then
onWaveIn()
elseif (pose == "fist") then
onFist()
elseif (pose == "fingersSpread") then
onFingersSpread()
end
end
end
function onWaveOut()
myo.keyboard("right_arrow", "press")
end
function onWaveIn()
myo.keyboard("left_arrow", "press")
end
function onFist()
myo.mouse("left", "click")
end
function onFingersSpread()
myo.keyboard("up_arrow", "press")
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