scanner

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 11 Imported by: 0

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:

http://www.linuxquestions.org/questions/programming-9/read-from-a-usb-barcode-scanner-that-simulates-a-keyboard-495358/#post2767643

Also found important Go-specific information by reviewing the code from this repo on github:

https://github.com/gvalkov/golang-evdev

Index

Constants

View Source
const (
	StateIdle              = "state_idle"
	StateSingleWaitForCode = "state_single_wait_for_code"
	StateInitPermScan      = "state_init_perm_scan"
	StatePermWaitForCode   = "state_perm_wait_for_code"
)
View Source
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"
)
View Source
const (
	EVENT_BUFFER   = 64
	EVENT_CAPTURES = 16
	SCANNER_DEVICE = "/dev/input/event0" // default location on the Pi
)

Variables

View Source
var EVENT_SIZE = int(unsafe.Sizeof(InputEvent{}))
View Source
var ErrInvalidAction = errors.New("invalid action scanned")
View Source
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

func ScanForever(device string, fn func(string), errFn func(error))

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 Handler

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

func GetHandler

func GetHandler(hdb *hdb.HomeDB, bring *bring.Bring) *Handler

type IHandler

type IHandler interface {
	// contains filtered or unexported methods
}

IHandler handles actions triggered by the scanner automaton

type InputEvent

type InputEvent struct {
	Time  syscall.Timeval
	Type  uint16
	Code  uint16
	Value int32
}

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 Scanner struct {
	PreviousState string
	State         string
	Action        string
	// contains filtered or unexported fields
}

func Get

func Get(handler IHandler) *Scanner

func (*Scanner) Start

func (s *Scanner) Start(deviceId string)

type State

type State struct {
	From   string
	To     string
	Action string
	Error  error
}

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

Jump to

Keyboard shortcuts

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