forked from system76/qmk_firmware
-
Notifications
You must be signed in to change notification settings - Fork 2
/
launch-midi.sh
executable file
·405 lines (336 loc) · 8.22 KB
/
launch-midi.sh
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/env bash
# will download pre-built binaries from:
# https://github.com/garrettjwilke/qmk_firmware/releases/latest
PROJECT_NAME=launch-midi-firmware
ARGUMENT=$1
message-box() {
MESSAGE=$1
cat << EOF
---------------------------------
$MESSAGE
---------------------------------
EOF
}
BRANCH_CHECK=$(git status | grep "On branch launch_midi")
if [[ "$BRANCH_CHECK" == "" ]]
then
git stash
git checkout launch_midi
fi
OS_CHECK=$(uname -a | awk '{print $1}')
case $OS_CHECK in
Darwin) OS=mac;;
Linux) OS=linux;;
*) message-box "This script requires Linux"; exit;;
esac
install-deps() {
./util/qmk_install.sh
git submodule init
git submodule update
QMK_CHECK=$(which qmk)
if [[ "$QMK_CHECK" == "" ]]
then
if [[ "$OS" == "linux" ]]
then
DISTRO_CHECK=$(cat /etc/os-release | grep "^NAME" | sed 's/NAME\=//g' | tr -d \")
if [[ "$DISTRO_CHECK" == "Arch Linux" ]] || [[ "$DISTRO_CHECK" == "Manjaro Linux" ]]
then
sudo pacman -Syy
sudo pacman -S qmk usbutils wget --noconfirm
elif [[ "$DISTRO_CHECK" == "Ubuntu" ]] || [[ "$DISTRO_CHECK" == "Pop!_OS" ]]
then
python3 -m pip install qmk
PATH=$PATH:$HOME/.local/bin
echo "export PATH=\$PATH:\$HOME/.local/bin" >> ~/.bashrc
else
message-box "QMK not installed."
echo "Install QMK using pip or your package manager."
echo ""
exit
fi
elif [[ "$OS" == "mac" ]]
then
echo "qmk not installed"
brew install qmk
fi
fi
clear
message-box "All tools installed"
sleep 2
if [[ "$OS" == "linux" ]]
then
exec bash ./launch-midi.sh
fi
}
help-menu() {
message-box "Launch Keyboard MIDI Firmware"
cat << EOF
System76 Launch Keyboard MIDI Firmware
What this script does:
1 - Identify which Launch Keyboard you have connected.
2 - Ask you which firmware you would like to flash.
There are 2 firmwares: Piano and Ghoti
Piano
* Keys are set up like a piano, with sharps/flats above your natural keys.
* There are 2 rows of 2 octaves each.
* Has 32 Pad Drum Layer.
Ghoti
* Keys are set up in vertical columns. There are 5 notes per column.
* Each column creates a perfect 4th of the adjacent column to the right.
* Has 32 Pad Drum Layer.
3 - Build and ask to flash MIDI Firmware to Launch Keyboard.
EOF
exit
}
qmk-check() {
PATH=$PATH:$HOME/.local/bin
# check for qmk
QMK_CHECK=$(which qmk)
if [[ "$QMK_CHECK" == "" ]]
then
clear
message-box "QMK is not installed."
echo "Would you like to install QMK? (y/n):"
echo ""
read yn
case $yn in
y|Y|yes|Yes|YES) install-deps;;
n|N|no|No|NO) exit;;
esac
fi
# check if qmk setup was ran
QMK_SETUP=$(qmk -h | grep flash)
if [[ "$QMK_SETUP" == "" ]]
then
clear
message-box "Run qmk setup"
echo "QMK is installed but the required tools are not installed."
echo "Would you like to install the QMK tools? (y/n):"
read yn
case $yn in
y|Y|yes|Yes|YES) qmk setup;;
n|N|no|No|NO) exit;;
esac
fi
}
dep-test() {
qmk-check
for i in wget sha256sum tar avrdude dfu-programmer dfu-util
do
DEP=$(which $i)
if [[ "$DEP" == "" ]]
then
message-box "$i is not installed."
if [[ "$i" == "avrdude" ]] || [[ "$i" == "dfu-programmer" ]] || [[ "$i" == "dfu-util" ]]
then
echo "$i can be installed by running:"
echo " qmk setup"
echo ""
fi
exit
fi
done
}
build-firmware() {
qmk-check
KEYBOARD_LIST="launch_1 launch_2 launch_3 launch_lite_1 launch_heavy_1 launch_heavy_3"
make clean
for i in $KEYBOARD_LIST
do
message-box "building midi_piano firmware for $i"
sleep 1
make system76/${i}:midi_piano
if [ $? -gt 0 ]
then
message-box "Error building MIDI Firmware."
echo "Keyboard: $i"
echo "Firmware: midi_piano"
echo ""
exit
fi
# launch_lite_ does not have enough keys for ghoti layout. skipping launch_lite_*
if [[ "$i" != "launch_lite_1" ]]
then
message-box "building midi_ghoti firmware for $i"
sleep 1
make system76/${i}:midi_ghoti
if [ $? -gt 0 ]
then
message-box "Error building MIDI Firmware."
echo "Keyboard: $i"
echo "Firmware: midi_piano"
echo ""
exit
fi
fi
done
if [ -d $PROJECT_NAME ]
then
rm -rf $PROJECT_NAME*
fi
mkdir $PROJECT_NAME
mv system76_launch* ${PROJECT_NAME}/
pushd $PROJECT_NAME
sha256sum system76_launch_* > ../${PROJECT_NAME}.list
popd
tar -czf ${PROJECT_NAME}.tar.gz $PROJECT_NAME ${PROJECT_NAME}.list
message-box "Firmware build complete"
echo "all firmware built to $PROJECT_NAME directory"
echo "${PROJECT_NAME}.tar.gz created"
echo ""
exit
}
if [[ "$ARGUMENT" == "--git" ]]
then
message-box "Push all changes to git"
echo "Push to git? (y/n)"
echo ""
read GIT
case $GIT in
Y|y|Yes|YES|yes) git add .; git commit -m "launch_midi"; git push; message-box "pushed to git"; echo ""; exit;;
N|n|No|NO|no) message-box "not pushing to git"; echo ""; exit;;
*) message-box "invalid input. exiting"; echo ""; exit;;
esac
elif [[ "$ARGUMENT" == "--build" ]]
then
build-firmware
exit
elif [[ "$ARGUMENT" == "--help" ]] || [[ "$ARGUMENT" == "-h" ]]
then
help-menu
elif [[ "$ARGUMENT" == "" ]]
then
:
else
message-box "Invalid flag: $ARGUMENT"
echo "Run with --help to see options"
echo ""
exit
fi
# set empty vars
FIRMWARE=""
dep-test
# find which Launch Keyboard is connected
if [[ "$OS" == "linux" ]]
then
KEYBOARD=$(lsusb | grep "(launch_*" | awk '{print $NF}' | tr -d "():")
elif [[ "$OS" == "mac" ]]
then
KEYBOARD=$(system_profiler SPUSBDataType | grep "(launch_*" | awk '{print $NF}' | tr -d "():")
fi
if [[ "$KEYBOARD" == "" ]]
then
message-box "Launch Keyboard not connected."
exit
fi
clear
message-box "Keyboard Detected - $KEYBOARD"
sleep 2
# ask user which version they want to flash
while true
do
clear
# launch_lite only has piano layout
if [[ "$KEYBOARD" == "launch_lite_1" ]]
then
message-box "Select a firmware to flash"
cat << EOF
Keyboard: $KEYBOARD
[ 1 ] Piano with 32 Drum Pads
- Keys are arranged like a piano
- 32 Drum Pad Layer
[ 2 ] Factory Default Firmware
[ q ] Quit
Press 1 or 2 - (q to quit):
EOF
read LAYOUT
case $LAYOUT in
1) FIRMWARE=midi_piano; break;;
2) FIRMWARE=default; break;;
q|Q|quit|Quit|QUIT) exit;;
*) echo "invalid input";;
esac
break
fi
message-box "Select a firmware to flash"
cat << EOF
Keyboard: $KEYBOARD
[ 1 ] Piano with 32 Drum Pads
- Keys are arranged like a piano
- 32 Drum Pad Layer
[ 2 ] Ghoti with 32 Drum Pads
- Keys are arranged chromatically in vertical columns
- Each column has 5 half-steps
- Adjacent notes are all Perfect Fourths
- You can travel the Circle of Fifths by shifting a chord left or right
- Steep learning curve.
- 32 Drum Pad Layer
[ 3 ] Factory Default Firmware
[ q ] Quit
Press 1 or 2 - (q to quit):
EOF
read LAYOUT
case $LAYOUT in
1) FIRMWARE=midi_piano; break;;
2) FIRMWARE=midi_ghoti; break;;
3) FIRMWARE=default; break;;
q|Q|quit|Quit|QUIT) exit;;
*) echo "invalid input";;
esac
done
if [[ "$FIRMWARE" == "" ]]
then
message-box "Error. Firmware select failed."
exit
elif [[ "$FIRMWARE" == "default" ]]
then
git stash
git checkout launch-3
fi
# build firmware
make clean
make system76/${KEYBOARD}:${FIRMWARE}
if [ $? -gt 0 ]
then
if [[ "$FIRMWARE" == "default" ]]
then
git stash
git checkout launch_midi
fi
message-box "Build failed"
exit
fi
# instruct user how to put keyboard into DFU
clear
message-box "Put Launch into bootloader mode"
cat << EOF
Keyboard: $KEYBOARD - Firmware: $FIRMWARE
1. Press ENTER then unplug the cable from your $KEYBOARD
2. Press and hold the ESC key
3. Plug in Launch while holding the ESC key
4. Release the ESC key when you see that the firware has flashed.
(or press q to quit)
EOF
read INPUT
case $INPUT in
q|Q|quit|Quit|QUIT) exit;;
esac
make system76/${KEYBOARD}:${FIRMWARE}:dfu
if [ $? -gt 0 ]
then
if [[ "$FIRMWARE" == "default" ]]
then
git stash
git checkout launch_midi
fi
message-box "Flash failed"
else
if [[ "$FIRMWARE" == "default" ]]
then
git stash
git checkout launch_midi
fi
clear
message-box "Flashed MIDI Firmware to $KEYBOARD"
fi
exit