diff --git a/bin/find-device-port-linux-udev b/bin/find-device-port-linux-udev index 79201857..0e284c37 100644 --- a/bin/find-device-port-linux-udev +++ b/bin/find-device-port-linux-udev @@ -2,14 +2,27 @@ use warnings; use strict; + +use FindBin qw{$Bin}; + +die "Usage: $0 VID PID\n" unless @ARGV == 2; + my $vid = shift; my $pid = shift; my $prefix = '/dev/serial/by-id/'; my @paths = `ls $prefix`; my %devices; +sub debug { + print STDERR @_; +} + +debug "Looking for USB device with vid=$vid and pid=$pid\n"; + for my $path (@paths) { chomp($path); + debug "Examining $path\n"; + debug " not symlink\n" unless -l $prefix . $path; next unless -l $prefix . $path; my @data = `udevadm info -q property --name=${prefix}${path}`; for my $line (@data) { @@ -17,15 +30,36 @@ for my $path (@paths) { my ( $key, $val ) = split( /=/, $line, 2 ); $devices{$path}{$key} = $val; } - if ( ( hex $devices{$path}{'ID_VENDOR_ID'} == hex $vid ) - && ( hex $devices{$path}{'ID_MODEL_ID'} == hex $pid ) ) - { + if ( hex $devices{$path}{'ID_VENDOR_ID'} != hex $vid ) { + debug " ID_VENDOR_ID $devices{$path}{'ID_VENDOR_ID'} != $vid\n"; + next; + } + if ( hex $devices{$path}{'ID_MODEL_ID'} != hex $pid ) { + debug " ID_MODEL_ID $devices{$path}{'ID_MODEL_ID'} != $pid\n"; + next; + } - if ( $devices{$path}{'ID_MM_CANDIDATE'} ) { - warn "Yikes. ModemManager wants to pwn your keyboard"; - } + debug " Found keyboard!\n"; - print $devices{$path}{DEVNAME}; - exit(0); + if ( $devices{$path}{'ID_MM_DEVICE_IGNORE'} ) { + debug " ID_MM_DEVICE_IGNORE is set - good!\n"; } + + if ( $devices{$path}{'ID_MM_CANDIDATE'}) { + my $rules = "$Bin/../etc/99-kaleidoscope.rules"; + debug <&2 +Couldn't autodetect the keyboard's serial port. +If you see this message and your keyboard is connected to your computer, +it probably means that our serial port detection logic is buggy or incomplete. + +Please report this issue at https://github.com/keyboardio/Kaleidoscope +EOF + exit 1 + elif echo "$DEVICE_PORT" | grep -q '[[:space:]]'; then + cat <&2 +Unexpected whitespace found in detected serial port: + + $DEVICE_PORT + +If you see this message, it means that our serial port +detection logic is buggy or incomplete. + +Please report this issue at https://github.com/keyboardio/Kaleidoscope +EOF + exit 1 + fi + + if ! [ -w "$DEVICE_PORT" ]; then + cat <&2 + +$DEVICE_PORT is not writable: + + `ls -l $DEVICE_PORT` + +You are currently in the following groups: + + `id -Gn` + +Please ensure you have followed the instructions on setting up your +account to be in the right group: + +https://github.com/keyboardio/Kaleidoscope/wiki/Install-Arduino-support-on-Linux + +EOF + exit 1 fi } diff --git a/etc/99-kaleidoscope.rules b/etc/99-kaleidoscope.rules index cae399b2..c69b9053 100644 --- a/etc/99-kaleidoscope.rules +++ b/etc/99-kaleidoscope.rules @@ -1,4 +1,2 @@ -SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2300", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}="1" -SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2301", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}="1" - - +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2300", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_CANDIDATE}:="0" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="2301", SYMLINK+="model01", ENV{ID_MM_DEVICE_IGNORE}:="1", ENV{ID_MM_CANDIDATE}:="0"