-
Notifications
You must be signed in to change notification settings - Fork 10
/
iTunes.lua
222 lines (186 loc) · 5.65 KB
/
iTunes.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
212
213
214
215
216
217
218
219
220
221
222
-- TaraniTunes
-- http://github.com/GilDev/TaraniTunes
-- By GilDev
-- http://gildev.tk
-- CONFIG --
local specialFunctionId = 30 -- This special function will be reserved: 1 for SF1, 2 for SF2…
-- You NEED to use logical switches to manipulate TaraniTunes.
-- WARNING: If you use trims for changing songs for example (and I recommand you do),
-- you need to deactivate the "real" trim functions of the model, to do this,
-- go into "FLIGHT MODES" configuration, go to each flight mode you use for your model
-- and set the throttle "Trims" value (the third if you use the default AETR mode) to "--".
-- Here's how to setup the play switch to SD centered:
-- LOGICAL SWITCH L61
-- Func OR
-- V1 SD-
-- V2 SD-
-- Then set playSongLogicalSwitch to 61 below.
-- Here's how to setup the next song switch to throttle trim down:
-- LOGICAL SWITCH L62
-- Func OR
-- V1 tTd
-- V2 tTd
-- Then set nextSongLogicalSwitch to 62 below.
local playSongLogicalSwitch = 61 -- Logical switch that will play the current song
local nextSongLogicalSwitch = 62 -- Logical switch that will set the current song to the next one
local prevSongLogicalSwitch = 63 -- Logical switch that will set the current song to the previous one
local randomSongLogicalSwitch = 64 -- Logical switch that will set the current song to a random one
-- DON'T EDIT BELOW THIS LINE --
loadScript("/SOUNDS/playlist.lua")() -- Import playlist
local errorOccured = false
local screenUpdate = true
local nextScreenUpdate = false
local playingSong = 1
local selection = 1
local songChanged = false
local resetDone = false
local function error(strings)
errorStrings = strings
errorOccured = true
end
function playSong()
model.setCustomFunction(
specialFunctionId,
{
switch = playSongSwitchId,
func = 16,
name = playlist[playingSong][2]
}
)
end
function resetSong()
model.setCustomFunction(
specialFunctionId,
{
switch = -playSongSwitchId
}
)
end
local function init()
-- Calculate indexes
specialFunctionId = specialFunctionId - 1 -- SF1 is at index 0 and so on
if LCD_W == 212 then -- if Taranis X9D
playSongSwitchId = 53 + playSongLogicalSwitch
else -- if Taranis Q X7
playSongSwitchId = 44 + playSongLogicalSwitch
end
nextSongSwitchId = getFieldInfo("ls" .. nextSongLogicalSwitch).id
prevSongSwitchId = getFieldInfo("ls" .. prevSongLogicalSwitch).id
randomSongSwitchId = getFieldInfo("ls" .. randomSongLogicalSwitch).id
nextScreenUpdate = true
screenUpdate = true
songChanged = true
end
nextSongSwitchPressed = false;
prevSongSwitchPressed = false;
randomSongSwitchPressed = false;
local function background()
if resetDone then
playSong()
resetDone = false
end
if songChanged then
resetSong()
songChanged = false
resetDone = true
end
-- Next song
if getValue(nextSongSwitchId) > 0 then
if not nextSongSwitchPressed then
nextSongSwitchPressed = true
nextScreenUpdate = true
songChanged = true
screenUpdate = true
if playingSong == #playlist then
playingSong = 1
else
playingSong = playingSong + 1
end
end
else
nextSongSwitchPressed = false
end
-- Previous song
if getValue(prevSongSwitchId) > 0 then
if not prevSongSwitchPressed then
prevSongSwitchPressed = true
nextScreenUpdate = true
songChanged = true
screenUpdate = true
if playingSong == 1 then
playingSong = #playlist
else
playingSong = playingSong - 1
end
end
else
prevSongSwitchPressed = false
end
-- Random song
if getValue(randomSongSwitchId) > 0 then
if not randomSongSwitchPressed then
randomSongSwitchPressed = true
playingSong = math.random (1, #playlist)
songChanged = true
screenUpdate = true
nextScreenUpdate = true
end
else
randomSongSwitchPressed = false
end
end
local function run(event)
-- INPUT HANDLING --
if (event == EVT_ROT_RIGHT or event == EVT_MINUS_FIRST or event == EVT_MINUS_RPT) then
if selection == #playlist then
selection = 1
else
selection = selection + 1
end
screenUpdate = true
elseif (event == EVT_ROT_LEFT or event == EVT_PLUS_FIRST or event == EVT_PLUS_RPT) then
if selection == 1 then
selection = #playlist
else
selection = selection - 1
end
screenUpdate = true
elseif event == EVT_ROT_BREAK or event == EVT_ENTER_BREAK then -- Play selected song
playingSong = selection
songChanged = true
screenUpdate = true
elseif nextScreenUpdate then
selection = playingSong
nextScreenUpdate = false
end
-- DRAWING --
if screenUpdate or event == 191 then -- 191 is the event code when entering the telemetry screen
screenUpdate = false
lcd.clear();
-- Title
lcd.drawText(1, 1, "TaraniTunes", MIDSIZE)
lcd.drawText(LCD_W - 19, 1, "By", SMLSIZE)
lcd.drawText(LCD_W - 27, 9, "GilDev", SMLSIZE)
-- Separator
lcd.drawLine(0, 16, LCD_W - 1, 16, SOLID, FORCE)
-- Print error
if errorOccured then
yLine = {18, 26, 34, 42, 50}
for i = 1, #errorStrings do
lcd.drawText(1, yLine[i], errorStrings[i])
end
return
end
-- Now playing
lcd.drawText(1, 18, string.char(62) .. playlist[playingSong][1])
-- Separator
lcd.drawLine(0, 26, LCD_W - 1, 26, DOTTED, FORCE)
-- Song selector
if playlist[selection - 2] then lcd.drawText(1, 28, playlist[selection - 2][1], SMLSIZE) end
if playlist[selection - 1] then lcd.drawText(3, 35, playlist[selection - 1][1], SMLSIZE) end
if playlist[selection] then lcd.drawText(1, 42, string.char(126) .. playlist[selection][1], SMLSIZE) end
if playlist[selection + 1] then lcd.drawText(3, 49, playlist[selection + 1][1], SMLSIZE) end
if playlist[selection + 2] then lcd.drawText(1, 56, playlist[selection + 2][1], SMLSIZE) end
end
end
return {run = run, background = background, init = init}