-
Notifications
You must be signed in to change notification settings - Fork 1
/
fpsgesture.myo
198 lines (167 loc) · 3.9 KB
/
fpsgesture.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
scriptId = 'com.mhacksv.fpsgesture'
scriptTitle = "FPS Gesture"
scriptDetailsUrl = ""
centerPitch = 0
centerYaw = 0
PITCHSPACE = .7
YAWSPACE = .5
MELEEMINSPEED = 300
BUTTONPUSHED = false
BUTTONMIDDLE = false
BUTTONRIGHT = false
MELEETRUE = false
function onPoseEdge(pose, edge)
myo.debug("onPoseEdge: " .. pose .. ": " .. edge)
pose = swapWave(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.debug("Switch down")
myo.keyboard("e", "press")
end
function onWaveIn()
myo.debug("Switch up")
myo.keyboard("q", "press")
end
function onFist()
myo.debug("Pills")
myo.keyboard("4", "press")
end
function onFingersSpread()
myo.debug("Throwable")
myo.keyboard("5", "press")
end
function swapWave(pose) -- inverts wave if on left arm
if myo.getArm() == "left" then
if pose == "waveIn" then
pose = "waveOut"
elseif pose == "waveOut" then
pose = "waveIn"
end
end
return pose
end
function getMyoRollDegrees() --along the arm, pos= cw from user perspective
return math.deg(myo.getRoll())
end
function getMyoPitchDegrees() --up down, pos = up movement
return math.deg(myo.getPitch())
end
function getMyoYawDegrees() -- left right, pos = to the right
return math.deg(myo.getYaw())
end
function center()
centerPitch = myo.getPitch()
myo.debug("Centred")
end
function calcDeltaPitch(currentPitch, centerPitch)
local deltaPitch = currentPitch - centerPitch
if (deltaPitch > 3.14) then
deltaPitch = deltaPitch- 6.28
elseif(deltaPitch < -3.14) then
deltaPitch = deltaPitch + 6.28
end
return deltaPitch
end
function calcDeltaYaw(currentYaw, centerYaw)
local deltaYaw = currentYaw - centerYaw
if (deltaYaw > 3.14) then
deltaYaw = deltaYaw- 6.28
elseif(deltaYaw < -3.14) then
deltaYaw = deltaYaw + 6.28
end
return deltaYaw
end
function switchWeapons()
if(not BUTTONPUSHEDQ) then
myo.keyboard("q", "down")
myo.keyboard("q", "up")
end
BUTTONPUSHEDQ = true
end
function aimDownSights()
if(not BUTTONMIDDLE) then
myo.mouse("center", "down")
myo.mouse("center", "up")
BUTTONMIDDLE = true;
myo.debug("aim down")
end
end
function hipFire()
if(BUTTONMIDDLE) then
myo.mouse("center", "down")
myo.mouse("center", "up")
BUTTONMIDDLE=false
myo.debug("hipfire")
end
if(BUTTONPUSHEDQ) then
BUTTONPUSHEDQ=false
end
end
function melee()
if(not BUTTONRIGHT) then
myo.mouse("right", "down")
myo.mouse("right", "up")
BUTTONRIGHT = true
end
end
function meleeReset()
BUTTONRIGHT=false
end
----------Required Callback Functions-------------
function activeAppName()
return "FPS Game"
end
function onForegroundWindowChange(app, title)---------------NEEDS TO CHANGE
myo.debug("onForegroundWindowChange: " .. app .. ", " .. title)
--myo.setLockingPolicy("none")
local truth = platform == "Windows" and app == "left4dead2.exe"
if(truth) then
center()
end
return truth
end
function onActiveChange(isActive)
if (isActive) then
--do something if the script is activated
end
end
function onUnlock()
--do something when the myo is unlocked (double tap)
end
function onLock()
--do something when the myp is locked (time runs out)
end
function onPeriodic()
local x,y,z = myo.getGyro()
if (z>MELEEMINSPEED or z< -MELEEMINSPEED) then
myo.debug("melee" .. ", " .. y .. ", " .. z)
melee()
MELEETRUE=true
else
meleeReset()
end
if (not MELEETRUE) then
local currentPitch = myo.getPitch()
local deltaPitch = calcDeltaPitch(currentPitch, centerPitch)
if (deltaPitch < -PITCHSPACE) then
switchWeapons()
elseif (deltaPitch > PITCHSPACE) then
myo.debug("aimdown")
---aimDownSights()
else
hipFire()
end
end
MELEETRUE=false
end