-
Notifications
You must be signed in to change notification settings - Fork 9
/
flash-uf2.rb
executable file
·51 lines (44 loc) · 1.09 KB
/
flash-uf2.rb
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
#!/usr/bin/env ruby
class Flasher
def device_connected?
File.directory?('/Volumes/RPI-RP2')
end
def show_searching_message
print '🔎 Searching for device (press Ctrl-C to stop).'
end
def bulk_flash(file, interval = 1)
show_searching_message
while true do
success = device_connected?
if success
sleep 1
puts
puts '🆗 Device found, flashing...'
`cp #{file} /Volumes/RPI-RP2/`
flash_success = $?.success?
if flash_success
puts '✅ Device flashed - Check LEDs'
else
puts '🛑 Device flashing unsuccessful, try again'
end
play_status_sound(flash_success)
sleep 1
show_searching_message
else
print '.'
end
sleep interval
end
end
def play_status_sound(success)
cmd = "afplay"
if success
cmd << " /System/Library/Sounds/Glass.aiff"
else
cmd << " /System/Library/Sounds/Sosumi.aiff"
end
`#{cmd}`
end
end
flasher = Flasher.new()
flasher.bulk_flash('sinc/keebio_sinc_rev3_via-2023-04-05_wde.uf2')