###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2014 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any
# later version. Please see the file LICENSE-GPL for details.
#
# Web Page: http://mielke.cc/brltty/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

# udev rules file for brltty

SUBSYSTEM=="usb_device", GOTO="brltty_usb_begin"
SUBSYSTEM=="usb", KERNEL!="*:*", GOTO="brltty_usb_begin"
GOTO="brltty_end"

LABEL="brltty_usb_begin"

# BEGIN_USB_DEVICES

# Device: 0403:6001
# Generic Identifier
# Vendor: Future Technology Devices International, Ltd
# Product: FT232 USB-Serial (UART) IC
# Albatross [all models]
# Cebra [all models]
# HIMS [Sync Braille]
# HandyTech [FTDI chip]
ENV{PRODUCT}=="403/6001/*", ENV{BRLTTY_BRAILLE_DRIVER}="at,ce,hm,ht", GOTO="brltty_usb_run"

# Device: 0403:DE58
# Hedo [MobilLine]
ENV{PRODUCT}=="403/de58/*", ENV{BRLTTY_BRAILLE_DRIVER}="hd", GOTO="brltty_usb_run"

# Device: 0403:DE59
# Hedo [ProfiLine]
ENV{PRODUCT}=="403/de59/*", ENV{BRLTTY_BRAILLE_DRIVER}="hd", GOTO="brltty_usb_run"

# Device: 0403:F208
# Papenmeier [all models]
ENV{PRODUCT}=="403/f208/*", ENV{BRLTTY_BRAILLE_DRIVER}="pm", GOTO="brltty_usb_run"

# Device: 0403:FE70
# Baum [Vario40 (40 cells)]
ENV{PRODUCT}=="403/fe70/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE71
# Baum [PocketVario (24 cells)]
ENV{PRODUCT}=="403/fe71/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE72
# Baum [SuperVario 40 (40 cells)]
ENV{PRODUCT}=="403/fe72/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE73
# Baum [SuperVario 32 (32 cells)]
ENV{PRODUCT}=="403/fe73/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE74
# Baum [SuperVario 64 (64 cells)]
ENV{PRODUCT}=="403/fe74/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE75
# Baum [SuperVario 80 (80 cells)]
ENV{PRODUCT}=="403/fe75/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE76
# Baum [VarioPro 80 (80 cells)]
ENV{PRODUCT}=="403/fe76/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0403:FE77
# Baum [VarioPro 64 (64 cells)]
ENV{PRODUCT}=="403/fe77/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0452:0100
# Metec [all models]
ENV{PRODUCT}=="452/100/*", ENV{BRLTTY_BRAILLE_DRIVER}="mt", GOTO="brltty_usb_run"

# Device: 045E:930A
# HIMS [Braille Sense (USB 1.1)]
# HIMS [Braille Sense (USB 2.0)]
# HIMS [Braille Sense U2 (USB 2.0)]
ENV{PRODUCT}=="45e/930a/*", ENV{BRLTTY_BRAILLE_DRIVER}="hm", GOTO="brltty_usb_run"

# Device: 045E:930B
# HIMS [Braille Edge]
ENV{PRODUCT}=="45e/930b/*", ENV{BRLTTY_BRAILLE_DRIVER}="hm", GOTO="brltty_usb_run"

# Device: 06B0:0001
# Alva [Satellite (5nn)]
ENV{PRODUCT}=="6b0/1/*", ENV{BRLTTY_BRAILLE_DRIVER}="al", GOTO="brltty_usb_run"

# Device: 0798:0001
# Voyager [all models]
ENV{PRODUCT}=="798/1/*", ENV{BRLTTY_BRAILLE_DRIVER}="vo", GOTO="brltty_usb_run"

# Device: 0798:0624
# Alva [BC624]
ENV{PRODUCT}=="798/624/*", ENV{BRLTTY_BRAILLE_DRIVER}="al", GOTO="brltty_usb_run"

# Device: 0798:0640
# Alva [BC640]
ENV{PRODUCT}=="798/640/*", ENV{BRLTTY_BRAILLE_DRIVER}="al", GOTO="brltty_usb_run"

# Device: 0798:0680
# Alva [BC680]
ENV{PRODUCT}=="798/680/*", ENV{BRLTTY_BRAILLE_DRIVER}="al", GOTO="brltty_usb_run"

# Device: 0904:2000
# Baum [VarioPro 40 (40 cells)]
ENV{PRODUCT}=="904/2000/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2001
# Baum [EcoVario 24 (24 cells)]
ENV{PRODUCT}=="904/2001/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2002
# Baum [EcoVario 40 (40 cells)]
ENV{PRODUCT}=="904/2002/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2007
# Baum [VarioConnect 40 (40 cells)]
ENV{PRODUCT}=="904/2007/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2008
# Baum [VarioConnect 32 (32 cells)]
ENV{PRODUCT}=="904/2008/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2009
# Baum [VarioConnect 24 (24 cells)]
ENV{PRODUCT}=="904/2009/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2010
# Baum [VarioConnect 64 (64 cells)]
ENV{PRODUCT}=="904/2010/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2011
# Baum [VarioConnect 80 (80 cells)]
ENV{PRODUCT}=="904/2011/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2014
# Baum [EcoVario 32 (32 cells)]
ENV{PRODUCT}=="904/2014/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2015
# Baum [EcoVario 64 (64 cells)]
ENV{PRODUCT}=="904/2015/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:2016
# Baum [EcoVario 80 (80 cells)]
ENV{PRODUCT}=="904/2016/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0904:3000
# Baum [Refreshabraille 18 (18 cells)]
ENV{PRODUCT}=="904/3000/*", ENV{BRLTTY_BRAILLE_DRIVER}="bm", GOTO="brltty_usb_run"

# Device: 0921:1200
# HandyTech [GoHubs chip]
ENV{PRODUCT}=="921/1200/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 0F4E:0100
# FreedomScientific [Focus 1]
ENV{PRODUCT}=="f4e/100/*", ENV{BRLTTY_BRAILLE_DRIVER}="fs", GOTO="brltty_usb_run"

# Device: 0F4E:0111
# FreedomScientific [PAC Mate]
ENV{PRODUCT}=="f4e/111/*", ENV{BRLTTY_BRAILLE_DRIVER}="fs", GOTO="brltty_usb_run"

# Device: 0F4E:0112
# FreedomScientific [Focus 2]
ENV{PRODUCT}=="f4e/112/*", ENV{BRLTTY_BRAILLE_DRIVER}="fs", GOTO="brltty_usb_run"

# Device: 0F4E:0114
# FreedomScientific [Focus Blue]
ENV{PRODUCT}=="f4e/114/*", ENV{BRLTTY_BRAILLE_DRIVER}="fs", GOTO="brltty_usb_run"

# Device: 10C4:EA60
# Generic Identifier
# Vendor: Cygnal Integrated Products, Inc.
# Product: CP210x UART Bridge / myAVR mySmartUSB light
# BrailleMemo [Pocket]
# Seika [Braille Display]
ENV{PRODUCT}=="10c4/ea60/*", ENV{BRLTTY_BRAILLE_DRIVER}="mm,sk", GOTO="brltty_usb_run"

# Device: 10C4:EA80
# Generic Identifier
# Vendor: Cygnal Integrated Products, Inc.
# Product: CP210x UART Bridge
# Seika [Note Taker]
ENV{PRODUCT}=="10c4/ea80/*", ENV{BRLTTY_BRAILLE_DRIVER}="sk", GOTO="brltty_usb_run"

# Device: 1148:0301
# BrailleMemo [Smart]
ENV{PRODUCT}=="1148/301/*", ENV{BRLTTY_BRAILLE_DRIVER}="mm", GOTO="brltty_usb_run"

# Device: 1C71:C004
# BrailleNote [HumanWare APEX]
ENV{PRODUCT}=="1c71/c004/*", ENV{BRLTTY_BRAILLE_DRIVER}="bn", GOTO="brltty_usb_run"

# Device: 1C71:C005
# HumanWare [all models]
ENV{PRODUCT}=="1c71/c005/*", ENV{BRLTTY_BRAILLE_DRIVER}="hw", GOTO="brltty_usb_run"

# Device: 1FE4:0003
# HandyTech [USB-HID adapter]
ENV{PRODUCT}=="1fe4/3/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0044
# HandyTech [Easy Braille (HID)]
ENV{PRODUCT}=="1fe4/44/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0054
# HandyTech [Active Braille]
ENV{PRODUCT}=="1fe4/54/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0055
# HandyTech [Connect Braille 40]
ENV{PRODUCT}=="1fe4/55/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0064
# HandyTech [Active Star 40]
ENV{PRODUCT}=="1fe4/64/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0074
# HandyTech [Braille Star 40 (HID)]
ENV{PRODUCT}=="1fe4/74/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0081
# HandyTech [Basic Braille 16]
ENV{PRODUCT}=="1fe4/81/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0082
# HandyTech [Basic Braille 20]
ENV{PRODUCT}=="1fe4/82/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0083
# HandyTech [Basic Braille 32]
ENV{PRODUCT}=="1fe4/83/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0084
# HandyTech [Basic Braille 40]
ENV{PRODUCT}=="1fe4/84/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0086
# HandyTech [Basic Braille 64]
ENV{PRODUCT}=="1fe4/86/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:0087
# HandyTech [Basic Braille 80]
ENV{PRODUCT}=="1fe4/87/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:008A
# HandyTech [Basic Braille 48]
ENV{PRODUCT}=="1fe4/8a/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 1FE4:008B
# HandyTech [Basic Braille 160]
ENV{PRODUCT}=="1fe4/8b/*", ENV{BRLTTY_BRAILLE_DRIVER}="ht", GOTO="brltty_usb_run"

# Device: 4242:0001
# Pegasus [all models]
ENV{PRODUCT}=="4242/1/*", ENV{BRLTTY_BRAILLE_DRIVER}="pg", GOTO="brltty_usb_run"

# Device: C251:1122
# EuroBraille [Esys (version < 3.0, no SD card)]
ENV{PRODUCT}=="c251/1122/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1123
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1123/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1124
# EuroBraille [Esys (version < 3.0, with SD card)]
ENV{PRODUCT}=="c251/1124/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1125
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1125/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1126
# EuroBraille [Esys (version >= 3.0, no SD card)]
ENV{PRODUCT}=="c251/1126/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1127
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1127/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1128
# EuroBraille [Esys (version >= 3.0, with SD card)]
ENV{PRODUCT}=="c251/1128/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1129
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1129/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112A
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112a/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112B
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112b/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112C
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112c/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112D
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112d/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112E
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112e/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:112F
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/112f/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1130
# EuroBraille [Esytime]
ENV{PRODUCT}=="c251/1130/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1131
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1131/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# Device: C251:1132
# EuroBraille [reserved]
ENV{PRODUCT}=="c251/1132/*", ENV{BRLTTY_BRAILLE_DRIVER}="eu", GOTO="brltty_usb_run"

# END_USB_DEVICES

GOTO="brltty_end"

LABEL="brltty_usb_run"
ENV{BRLTTY_BRAILLE_DEVICE}="usb:$sysfs{serial}"
GOTO="brltty_run"

LABEL="brltty_run"
ENV{BRLTTY_PID_FILE}="/var/run/brltty.$kernel.pid"
ACTION=="add", GOTO="brltty_add"
ACTION=="remove", GOTO="brltty_remove"
GOTO="brltty_end"

LABEL="brltty_add"
SYMLINK+="brltty/$env{BRLTTY_BRAILLE_DRIVER}-$env{BRLTTY_BRAILLE_DEVICE}"
RUN+="/bin/brltty -E -P$env{BRLTTY_PID_FILE}"
GOTO="brltty_end"

LABEL="brltty_remove"
RUN+="/bin/sh -c 'kill -TERM `cat $env{BRLTTY_PID_FILE}`'"
GOTO="brltty_end"

LABEL="brltty_end"
