-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script.lua
211 lines (152 loc) · 4.63 KB
/
Script.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
scriptId = 'co.project.powerpoint'
centerYaw = 0
centerPitch = 0
center = 0
PI = math.pi
TWOPI = PI * 2
YAW_DEADZONE = .5
ROLL_DEADZONE = .6
pitch_DEADZONE = .4
lastTimeRightSlide = myo.getTimeMilliseconds() -- for given enough time between inputs
lastTimeLeftSlide = myo.getTimeMilliseconds() -- for given enough time between inputs
lastTimeEnterSlide = myo.getTimeMilliseconds() -- for given enough time between inputs
rightSlide = true -- for preventing the unnecessary inputs
leftSlide = true -- for preventing the unnecessary inputs
enterSlideShow = true -- for preventing the unnecessary inputs
exitSlideShow = false --- for preventing uncessary inputs
pause = true
function onForegroundWindowChange(app, title)
center()
myo.setLockingPolicy("none")
return app == "com.microsoft.Powerpoint"
--return true
end
--- this call to center the radials to the current position.
function center()
myo.debug("Centred")
centerYaw = myo.getYaw()
centerRoll = myo.getRoll()
centerPitch = myo.getPitch()
pause = true
myo.vibrate("short")
end
function onPeriodic() --- this is a native call back function tha executes every milliseconds
if (centerYaw == 0 or centerPitch == 0 or centerRoll == 0 ) then
--- go back becuase we haven't done anything
return
end
local currentYaw = myo.getYaw()
local currentRoll = myo.getRoll()
local currentPitch = myo.getPitch()
local deltaYaw = calculateDeltaRadians(currentYaw, centerYaw)
local deltaRoll = calculateDeltaRadians(currentRoll,centerRoll)
local deltaPitch = calculateDeltaRadians(currentPitch,centerPitch)
if (deltaYaw > YAW_DEADZONE) then
rightSlide()
elseif (deltaYaw < -YAW_DEADZONE) then
leftSlide()
end
if (math.abs( deltaRoll ) > ROLL_DEADZONE) then
pauseResume()
end
if(deltaPitch > pitch_DEADZONE ) then
exitSlideShowfunc()
elseif (deltaPitch < -pitch_DEADZONE) then
enterSlideShowfunc()
end
end
---functions for manipulating slideshow
function rightSlide()
local now = myo.getTimeMilliseconds()
if ( now - lastTimeRightSlide > 1000) then
myo.debug("Going to the next slide")
myo.keyboard("right_arrow","press")
lastTimeRightSlide = myo.getTimeMilliseconds()
local timegain = myo.getTimeMilliseconds()
if (timegain - now > 300) then --- trying to center again
myo.debug("centering again")
center()
end
else
myo.debug("too soon to go the next slide ")
return
end
end
function leftSlide()
local now = myo.getTimeMilliseconds()
if( now - lastTimeLeftSlide > 2000 ) then
myo.debug("Going to the previous slide")
myo.keyboard("left_arrow","press")
lastTimeLeftSlide = myo.getTimeMilliseconds()
local timegain = myo.getTimeMilliseconds()
if (timegain - now > 300) then --trying to center again
myo.debug("centering again")
center()
end
else
myo.debug("too soon, to go the the previous Slide ")
return
end
end
function enterSlideShowfunc()
if(enterSlideShow) then
local now = myo.getTimeMilliseconds()
myo.debug("Entering SlideShow slide")
myo.keyboard("return","press","command")
lastTimeEnterSlide = myo.getTimeMilliseconds()
exitSlideShow = true
enterSlideShow = false
local timegain = myo.getTimeMilliseconds()
if (timegain - now > 1000) then --trying to center again
myo.debug("centering again")
center()
end
else
myo.debug("slide show can't be entered, it's already engaged")
return
end
end
function exitSlideShowfunc()
local now = myo.getTimeMilliseconds()
if (now - lastTimeEnterSlide > 1000) then
if(exitSlideShow) then
myo.debug("exiting SlideShow ")
myo.keyboard("escape","press")
exitSlideShow = false
enterSlideShow = true
local timegain = myo.getTimeMilliseconds()
if (timegain - now > 1000) then --trying to center again
myo.debug("centering again")
center()
end
end
else
myo.debug("Slide show can't be exited, because it's too soon ")
return
end
end
function pauseResume()
local now = myo.getTimeMilliseconds()
if(pause) then
myo.keyboard("w","press")
local timegain = myo.getTimeMilliseconds()
pause = false
if (now - timegain > 1000) then --trying to center again
myo.debug("centering again")
center()
end
else
myo.debug("powerPoint slide not active so can't resume")
return
end
end
--- this is the function I found online that calculated the delta or the change to the Yaw axis but I implemented for the all AXises
function calculateDeltaRadians(currentRad, centerRad)
local deltaRad = currentRad - centerRad
if (deltaRad > math.pi) then
deltRad = deltaRad - TWOPI
elseif(centerRad < -math.pi) then
deltaRad = delta + TWOPI
end
return deltaRad
end