Class: Rpremote::BootselCommand
- Inherits:
-
Object
- Object
- Rpremote::BootselCommand
- Defined in:
- lib/rpremote/bootsel_command.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: Error
Constant Summary collapse
- SHELL_READY_TIMEOUT =
2.0- RETRY_INTERVAL =
0.25- RESET_FLASH_FIRMWARE =
File.join("firmware", "nuke_universal.uf2").freeze
Class Method Summary collapse
- .enter(mount:, port:, baud:, timeout:, output:, services: {}) ⇒ Object
- .run(args, defaults:, output: $stdout, services: {}) ⇒ Object
Class Method Details
.enter(mount:, port:, baud:, timeout:, output:, services: {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rpremote/bootsel_command.rb', line 39 def self.enter(mount:, port:, baud:, timeout:, output:, services: {}) serial = services.fetch(:serial, Serial) device = services.fetch(:device, Device) shell = services.fetch(:shell, Shell) flasher = services.fetch(:flasher, Flasher) sleeper = services.fetch(:sleeper) { ->(seconds) { sleep(seconds) } } clock = services.fetch(:clock) { -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) } } deadline = clock.call + timeout request_bootsel( port: port, baud: baud, deadline: deadline, output: output, serial: serial, device: device, shell: shell, sleeper: sleeper, clock: clock ) remaining = deadline - clock.call raise Error, "timed out waiting for R2P2 Shell to accept a BOOTSEL request" unless remaining.positive? target = flasher.new(timeout: remaining).wait_for_mount(mount: mount) output.puts("BOOTSEL ready: #{target}") target end |
.run(args, defaults:, output: $stdout, services: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rpremote/bootsel_command.rb', line 13 def self.run(args, defaults:, output: $stdout, services: {}) = (args, defaults) raise ArgumentError, "bootsel does not accept arguments" unless args.empty? reset_flasher = nil if [:reset_flash_memory] flasher = services.fetch(:flasher, Flasher) reset_flasher = flasher.new(timeout: [:timeout]) target = reset_flasher.find_mounted([:mount]) output.puts("BOOTSEL ready: #{target}") if target end target ||= enter(**.slice(:mount, :port, :baud, :timeout), output: output, services: services) reset_flash_memory(target, output: output, flasher: reset_flasher) if [:reset_flash_memory] target end |