btk

package module
v0.0.0-...-9539038 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2017 License: MIT Imports: 13 Imported by: 0

README

btk

GoDoc

Keyboard relay from USB to Bluetooth

NOTE: Only works on Linux

More detail and deployment instruction coming soon

Usage

  • Install dependencies
sudo apt-get install bluez
  • Modify /lib/systemd/system/bluetooth.service:

Change

ExecStart=/usr/lib/bluetooth/bluetoothd

to

ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=input

Then sudo service bluetooth restart

  • Download the binary program

Built binary release comming soon, if you want to try now, build it from source

  • Start
sudo ./btk

Build

go get github.com/inoc603/btk
cd $GOPATH/src/github.com/inoc603/btk
make build

TODO

  • Be able to plug/unplug usb keyboard without restarting the program
  • Reset usb keyboard after the program crashes

Credits

Inspired by these amazing projects and articles:

Documentation

Index

Constants

View Source
const (
	PSMCTRL = 0x11
	PSMINTR = 0x13
	BUFSIZE = 1024

	FDBITS = 32
)
View Source
const (
	BTPROTO_L2CAP = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bluetooth

type Bluetooth struct {
	// contains filtered or unexported fields
}

Bluetooth represents a bluetooth socket connection

func ListenBluetooth

func ListenBluetooth(psm uint, bklen int, block bool) (*Bluetooth, error)

ListenBluetooth creates L2CAP socket and lets it listen on given PSM

func NewBluetoothSocket

func NewBluetoothSocket(fd int) (*Bluetooth, error)

NewBluetoothSocket creates L2CAP socket wrapper with given file descriptor This file descriptor is provided by BlueZ DBus interface e.g. org.bluez.Profile1.NewConnection()

func (*Bluetooth) Accept

func (bt *Bluetooth) Accept() (*Bluetooth, error)

Accept accepts on listening socket and return received connection

func (*Bluetooth) Close

func (bt *Bluetooth) Close() error

Close closes the socket

func (*Bluetooth) Read

func (bt *Bluetooth) Read(b []byte) (int, error)

func (*Bluetooth) SetBlocking

func (bt *Bluetooth) SetBlocking(block bool) error

SetBlocking sets socket to blocking mode(true) or Non-blocking mode(false)

func (*Bluetooth) Write

func (bt *Bluetooth) Write(d []byte) (int, error)

type Client

type Client struct {
	Dev   dbus.ObjectPath
	Sintr *Bluetooth
	Sctrl *Bluetooth
	Done  chan struct{}
}

Client represents a bluetooth client

type HidProfile

type HidProfile struct {
	// contains filtered or unexported fields
}

HidProfile represents a dbus profile for the keyboard

func NewHidProfile

func NewHidProfile(path string) (*HidProfile, error)

NewHidProfile returns a new HidProfile on the given path

func (*HidProfile) Close

func (p *HidProfile) Close()

Close shuts down the profile

func (*HidProfile) Connection

func (p *HidProfile) Connection() chan *Client

Connection returns a channel of new bluetooth connection

func (*HidProfile) Disconnection

func (p *HidProfile) Disconnection() chan *Client

Disconnection is designed to returns a channel of disconnction requests, but currently it doesn't work

func (*HidProfile) Export

func (p *HidProfile) Export() error

Export exports the profile

func (*HidProfile) NewConnection

func (p *HidProfile) NewConnection(dev dbus.ObjectPath, fd dbus.UnixFD, fdProps map[string]dbus.Variant) *dbus.Error

NewConnection handles new bluetooth connections

func (*HidProfile) Register

func (p *HidProfile) Register(desc string) error

Register registers the profile to dbus

func (*HidProfile) Release

func (p *HidProfile) Release() *dbus.Error

Release is called when the profile is unregisterd

func (*HidProfile) RequestDisconnection

func (p *HidProfile) RequestDisconnection(dev dbus.ObjectPath) *dbus.Error

RequestDisconnection ... I don't know how to use this yet

func (*HidProfile) Unregister

func (p *HidProfile) Unregister() error

Unregister unregisters the profile from dbus

type Keyboard

type Keyboard struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Keyboard represents a HID keyboard

func NewKeyboard

func NewKeyboard() (*Keyboard, error)

NewKeyboard returns a new keyboard on the first usb keyboard connected.

func (*Keyboard) Client

func (kb *Keyboard) Client() *Client

Client returns the current bluetooth client of the keyboard

func (*Keyboard) Connect

func (kb *Keyboard) Connect(client *Client) error

Connect hooks up the given client with the usb keyboard, and start piping keypresses to the client. Will return an error if the keyboard is already in use

func (*Keyboard) Desc

func (kb *Keyboard) Desc() string

Desc returns the HID descriptor of the usb keyboard

func (*Keyboard) Disconnect

func (kb *Keyboard) Disconnect(client *Client) error

Disconnect closes the connection to the given bluetooth client Currently this is just some cleanning up. It can't close the actual bluetooth connection, and will block on the attempt TODO: Find a way to close the connection

func (*Keyboard) HandleHID

func (kb *Keyboard) HandleHID()

HandleHID starts a loop to read from the usb keyboard, it blocks until there's a fatal error reading from the keyboard, e.g. keyboard disconnection

func (*Keyboard) Stop

func (kb *Keyboard) Stop()

Stop close the usb keyboard

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL