Documentation
¶
Overview ¶
package scanner contains implementations for handling input events from a barcode&qr code scanner
Package scanner provides functions for reading barcode scans from usb-connected barcode scanner devices as if they were keyboards, i.e., by using the corresponding '/dev/input/event' device, inspired by this post on linuxquestions.org:
Also found important Go-specific information by reviewing the code from this repo on github:
Index ¶
Constants ¶
const ( StateIdle = "state_idle" StateSingleWaitForCode = "state_single_wait_for_code" StateInitPermScan = "state_init_perm_scan" StatePermWaitForCode = "state_perm_wait_for_code" )
const ( ActionAddItem = "action_add_item" ActionRemoveItem = "action_remove_item" ActionRemoveItemAddToList = "action_remove_item_add_to_list" ActionAddToList = "action_add_to_list" ActionInitPermScan = "action_init_perm_scan" ActionStopPermScan = "action_stop_perm_scan" )
const ( EVENT_BUFFER = 64 EVENT_CAPTURES = 16 SCANNER_DEVICE = "/dev/input/event0" // default location on the Pi )
Variables ¶
var EVENT_SIZE = int(unsafe.Sizeof(InputEvent{}))
var ErrInvalidAction = errors.New("invalid action scanned")
var KEYCODES = map[byte]string{
0x02: "1",
0x03: "2",
0x04: "3",
0x05: "4",
0x06: "5",
0x07: "6",
0x08: "7",
0x09: "8",
0x0a: "9",
0x0b: "0",
0x0c: "-",
0x10: "q",
0x11: "w",
0x12: "e",
0x13: "r",
0x14: "t",
0x15: "y",
0x16: "u",
0x17: "i",
0x18: "o",
0x19: "p",
0x1e: "a",
0x1f: "s",
0x20: "d",
0x21: "f",
0x22: "g",
0x23: "h",
0x24: "j",
0x25: "k",
0x26: "l",
0x2A: "",
0x2c: "z",
0x2d: "x",
0x2e: "c",
0x2f: "v",
0x30: "b",
0x31: "n",
0x32: "m",
0x35: "_",
}
KEYCODES is the map of hex found in the InputEvent.Code field, and its corresponding char (string) representation [source: Vojtech Pavlik (author of the Linux Input Drivers project), via linuxquestions.org user bricedebrignaisplage]
Functions ¶
func ScanForever ¶
ScanForever takes a linux input device string pointing to the scanner to read from, invokes the given function on the resulting barcode string when complete, or the errfn on Error, then goes back to read/scan again
Types ¶
type GPRCStateListener ¶
type GPRCStateListener struct { }
func (*GPRCStateListener) StateUpdated ¶
func (l *GPRCStateListener) StateUpdated(state State)
type IHandler ¶
type IHandler interface {
// contains filtered or unexported methods
}
IHandler handles actions triggered by the scanner automaton
type InputEvent ¶
InputEvent is a Go implementation of the native linux device input_event struct, as described in the kernel documentation (https://www.kernel.org/doc/Documentation/input/input.txt), with a big assist from https://github.com/gvalkov/golang-evdev
type Scanner ¶
type StateListener ¶
type StateListener interface {
StateUpdated(state State)
}
listener which is called after each scan event and may be used to display state information to the user