Class: Rpremote::Device
- Inherits:
-
Object
show all
- Defined in:
- lib/rpremote/device.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: MultipleDevicesError, NotFoundError
Constant Summary
collapse
- GLOBS =
["/dev/cu.usbmodem*", "/dev/tty.usbmodem*"].freeze
Class Method Summary
collapse
Class Method Details
.main_port(explicit_port = nil, available_ports: ports) ⇒ String
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/rpremote/device.rb', line 15
def main_port(explicit_port = nil, available_ports: ports)
return validate_explicit_port(explicit_port) if explicit_port
callout_ports = available_ports.grep(%r{\A/dev/cu\.})
candidates = callout_ports.empty? ? available_ports : callout_ports
candidates = candidates.select { |path| cdc_zero?(path, candidates) }
case candidates.length
when 0
raise NotFoundError, "R2P2 serial port not found; connect the Pico 2 or use --port PORT"
when 1
candidates.first
else
raise MultipleDevicesError,
"multiple R2P2 devices found; use --port PORT (#{candidates.join(", ")})"
end
end
|
.ports ⇒ Array[String]
11
12
13
|
# File 'lib/rpremote/device.rb', line 11
def ports
GLOBS.flat_map { |pattern| Dir.glob(pattern) }.sort
end
|