-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_powerpoint.lua
96 lines (78 loc) · 2.24 KB
/
sample_powerpoint.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 = 'com.thalmic.scripts.presentation'
scriptDetailsUrl = 'https://market.myo.com/app/5474c658e4b0361138df2a9e'
scriptTitle = 'PowerPoint Connector'
function onForegroundWindowChange(app, title)
return platform == "MacOS" and app == "com.microsoft.Powerpoint" or
platform == "Windows" and (app == "POWERPNT.EXE" or app == "PPTVIEW.EXE")
end
function activeAppName()
return "PowerPoint"
end
-- flag to de/activate shuttling feature
supportShuttle = false
-- Effects
function forward()
myo.keyboard("down_arrow", "press")
end
function backward()
myo.keyboard("up_arrow", "press")
end
-- Helpers
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
-- Shuttle
function shuttleBurst()
if shuttleDirection == "forward" then
forward()
elseif shuttleDirection == "backward" then
backward()
end
end
-- Triggers
function onPoseEdge(pose, edge)
-- Forward/backward and shuttle
if pose == "waveIn" or pose == "waveOut" then
local now = myo.getTimeMilliseconds()
if edge == "on" then
-- Deal with direction and arm
pose = conditionallySwapWave(pose)
if pose == "waveIn" then
shuttleDirection = "backward"
else
shuttleDirection = "forward"
end
-- Extend unlock and notify user
myo.unlock("hold")
myo.notifyUserAction()
-- Initial burst
shuttleBurst()
shuttleSince = now
shuttleTimeout = SHUTTLE_CONTINUOUS_TIMEOUT
end
if edge == "off" then
myo.unlock("timed")
shuttleTimeout = nil
end
end
end
-- All timeouts in milliseconds
SHUTTLE_CONTINUOUS_TIMEOUT = 600
SHUTTLE_CONTINUOUS_PERIOD = 300
function onPeriodic()
local now = myo.getTimeMilliseconds()
if supportShuttle and shuttleTimeout then
if (now - shuttleSince) > shuttleTimeout then
shuttleBurst()
shuttleTimeout = SHUTTLE_CONTINUOUS_PERIOD
shuttleSince = now
end
end
end