Class: Rpremote::BootselCommand

Inherits:
Object
  • Object
show all
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 =

Returns:

  • (String)
File.join("firmware", "nuke_universal.uf2").freeze

Class Method Summary collapse

Class Method Details

.enter(mount:, port:, baud:, timeout:, output:, services: {}) ⇒ Object

Raises:



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

Raises:

  • (ArgumentError)


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: {})
  options = parse_options(args, defaults)
  raise ArgumentError, "bootsel does not accept arguments" unless args.empty?

  reset_flasher = nil
  if options[:reset_flash_memory]
    flasher = services.fetch(:flasher, Flasher)
    reset_flasher = flasher.new(timeout: options[:timeout])
    target = reset_flasher.find_mounted(options[:mount])
    output.puts("BOOTSEL ready: #{target}") if target
  end
  target ||= enter(**options.slice(:mount, :port, :baud, :timeout), output: output, services: services)
  reset_flash_memory(target, output: output, flasher: reset_flasher) if options[:reset_flash_memory]
  target
end