rasProject_01 / weSweetHome  R. 240
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
weUSBscan.h File Reference

USB 1D / 2D scanners mimicking keyboards on Raspberry Pi. More...

#include "sysBasic.h"
#include <wchar.h>
#include <locale.h>

Variables

char const deRawCoDisAltGrph [120]
 Key position number to character, AltGr, German keyboard. More...
 
char const deRawCoDisNoShift [90]
 Key position number to character, no shift, German keyboard. More...
 
char const deRawCoDisShifted [90]
 Key position number to character, shifted, German keyboard. More...
 
wchar_t raw2wcharAltGrph [102]
 Key position number to character, with AltGR. More...
 
wchar_t raw2wcharNoShift [60]
 Key position number to character, no shift. More...
 
wchar_t raw2wcharShifted [60]
 Key position number to character, with shift. More...
 
unsigned char scanKeyAction [32]
 The one keystroke read buffer. More...
 
int scanKeybLang
 The keyboard language. More...
 
wchar_t scanResult [162]
 The result of one scan. More...
 
char const usRawCoDisNoShift [90]
 Key position number to character, no shift, US keyboard. More...
 
char const usRawCoDisShifted [90]
 Key position number to character, shifted, US keyboard. More...
 

Detailed Description

USB 1D / 2D scanners mimicking keyboards on Raspberry Pi.

Copyright (c) 2020 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 236 2.02.2021
Rev. 232 03.09.2020 : new (extracted from testOnPi.c)
Rev. 234 05.12.2020 : cosmetic changes

This is a supplementary basic library to handle USB barcode and QR code scanners. By plug'n play such scanner would normally appear as device

/dev/hidraw0

. To make this usable for scanner application programs run without sudo apply

sudo chmod 664 /dev/hidraw0

before.

Devices

The only device used and tested so far is a "USB Wired 2D Barcode Scanner" <MJ-8200>. It seems to ha a lot of bethren with similar software. Emulated non-US keyboards seem alien to the developers; see deRawCoDisNoShift.

Variable Documentation

◆ usRawCoDisNoShift

char const usRawCoDisNoShift[90]
extern

Key position number to character, no shift, US keyboard.

This utf-8 or multibyte character array respectively string describes the translation of key number to character for a US keyboard.
It will have to be transfered as wide character array to raw2wcharNoShift.

◆ usRawCoDisShifted

char const usRawCoDisShifted[90]
extern

Key position number to character, shifted, US keyboard.

See the explanation at usRawCoDisNoShift.

See also
raw2wcharShifted

◆ deRawCoDisNoShift

char const deRawCoDisNoShift[90]
extern

Key position number to character, no shift, German keyboard.

This utf-8 or multibyte character array respectively string describes the translation of key number to character for a US keyboard.
It will have to be transfered as wide character array to raw2wcharNoShift.

Remarks on non US keyboard emulations by the "USB Wired 2D Barcode Scanner" <MJ-8200> and consorts:
We strongly recommend not to use them and refrain from applications using more than primitive USASCII. As "German keyboard", e.g., the scanner does neither recognise nor send ÇÏÇôǬÇ?Ç?Ç?Ç?. Besides being called German without umlauts [sic!] the scanner is ignorant to some other characters on every German keyboard (which are probably there because of being used in Western Europe). Additionally the scanner when set to German inserts additional strings of characters with no obvious sense or system.
In the end we consider everything beyond factory reset (except low beeper volume) as not functional.
Without the hard bug of inventing characters and string not contained in the QR-code, the so called German keyboard would give us some extra characters — but not umlauts.

◆ deRawCoDisShifted

char const deRawCoDisShifted[90]
extern

Key position number to character, shifted, German keyboard.

See the explanation at usRawCoDisNoShift.

See also
raw2wcharShifted deRawCoDisNoShift

◆ deRawCoDisAltGrph

char const deRawCoDisAltGrph[120]
extern

Key position number to character, AltGr, German keyboard.

See the explanation at usRawCoDisNoShift.

See also
raw2wcharShifted deRawCoDisNoShift

◆ raw2wcharNoShift

wchar_t raw2wcharNoShift[60]
extern

Key position number to character, no shift.

The length is 60. Valid characters are in the 4..56 key number range; there may be gaps. 0..3 are errors.

See also
usRawCoDisNoShift

◆ raw2wcharShifted

wchar_t raw2wcharShifted[60]
extern

Key position number to character, with shift.

The length is 60. Valid characters are in the 4..56 key number range; there may be gaps. 0..3 are errors.

See also
usRawCoDisShifted

◆ raw2wcharAltGrph

wchar_t raw2wcharAltGrph[102]
extern

Key position number to character, with AltGR.

The length is 60. Valid characters are in the 4..56 key number range; there will be many gaps. 0..3 are errors.

See also
usRawCoDisShifted

◆ scanKeybLang

int scanKeybLang
extern

The keyboard language.

The language of the USB keyboard (see scanKeyAction) emulated by the scanner is stored here as: 0=US (default), 10=DE

◆ scanResult

wchar_t scanResult[162]
extern

The result of one scan.

The result of consecutive keystrokes (see scanKeyAction) is stored here as array respectively string of wide characters.

◆ scanKeyAction

unsigned char scanKeyAction[32]
extern

The one keystroke read buffer.

Keyboard input comes in blocks of 8 bytes each. Hence a length of 8 would be sufficient. Hence, 32 is a reserve for device errors or the driver not recognising the gap between blocks.

The 8 bytes are:

Bit/Value: 0/1 1/2 2/4 3/8 4/16 5/32 6/64 7/128
[0] Modifier keys Left: cntl shift Alt Win Right: cntl shift AltGr Win
[1] Reserved field always 0
[2] Keypress 1 in a funny code (4 is a)
[3] 2nd simultaneously pressed key
[4..7] Keypress 3..6

As scanners won't "press" more than one key at a time only bytes [0] and [1] will contain information.
Byte[2] will be a crazy key code for a..z1..90... athwart to any utf or unicode. In the end the semantic of that "code" is a mixture of key value and key position on the keyboard. In the end few scanners get more than an American (and a Chinese?) keybord right. When setting the scanner to German keyboard you may miss one or two of ÇÏ Çô Ǭ Ç? Ç? Ç? Ç?.

On byte [0] one should see only three values: /code 0 : no modifier, no shift 2 : shift, that means a->A 64: altGr