Am 14.03.2014 15:07, schrieb Rob:
> the vusb looks interesting! What I want to do is following: a user puts the
> iButton on the reader. The id should be stored in a database, together with
> the time (by using some Python).
> 
Simply use Python::Tk and bind for keypresses. It's a little tricky to sort it
out from the "real" keypresses but it's possible with good knowledge of Tk. You
have to dynamically create and delete keyboard bindings around the %%b and 
<Enter>
keypress events. I got original the idea from handling barcode readers. They act
like keyboards, too.

Disadvantage of the above solution is it only works outside of input boxes (and
your application needs the keyboard focus to check for events) or it gets really
complicated.


So I changed my POS application to sampling /dev/input/eventX directly. My Tcl
test code for that solution is:
-----------------------------------------------------------------------------
#!/usr/bin/tclsh

set fd [open [lindex $::argv 0] r]
fconfigure $fd -translation binary -buffering none
set keys [dict create]

set keycodes {
        2 1
        3 2
        4 3
        5 4
        6 5
        7 6
        8 7
        9 8
        10 9
        11 0
        30 a
        48 b
        46 c
        32 d
        18 e
        33 f
        23 i
        36 j
        {42 6} %
        28 \n
}


proc sample {} {
        if {[eof $::fd]} exit
        binary scan $DATA x[ expr 2*$::tcl_platform(wordSize) ]ssi type code 
value
        switch -- $type {
                0 {evaluate [dict keys $::keys]}
                1 {if {$value} {dict set ::keys $code {}} {dict unset ::keys 
$code}}
        }
}

proc evaluate {keys} {
        if {![dict exists $::keycodes $keys]} return
        if {$keys ne 28} {
                append ::line [dict get $::keycodes $keys]
        } {
                if {[regexp 
{^%%b([i|j])([[:xdigit:]]{2})([[:xdigit:]]{12})([[:xdigit:]]{2})$} $::line 
match command family id crc]} {
                        puts "$command $family $id $crc"
                }
                set ::line {}
        }
}


fileevent $fd readable sample

vwait endless
-----------------------------------------------------------------------------

Along, I've made a small kernel patch to avoid the lock creating tty keypresses.
Basically a blacklisting of the lock's USB id. If you like to go the second way,
I'll post the patch, too. It's not required, though.


Kind regards

        Jan





------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Owfs-developers mailing list
Owfs-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to