summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorAndrés Cuervo <andrescuervor@gmail.com>2023-11-28 21:24:39 +0000
committerAndrés Cuervo <andrescuervor@gmail.com>2023-11-28 21:24:39 +0000
commit8b3a6f9bfd6cc51aa42ba68f3259b78381b38cd8 (patch)
tree966f18258d72c5c74bf6a70ec30b38ad1c6b97bb /virtual-programs
parentAdd logging on key presses (diff)
downloadfolk-8b3a6f9bfd6cc51aa42ba68f3259b78381b38cd8.tar.gz
folk-8b3a6f9bfd6cc51aa42ba68f3259b78381b38cd8.zip
Add readCount logging
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/keyboard.folk134
1 files changed, 72 insertions, 62 deletions
diff --git a/virtual-programs/keyboard.folk b/virtual-programs/keyboard.folk
index 03abbf88..c6dba2a2 100644
--- a/virtual-programs/keyboard.folk
+++ b/virtual-programs/keyboard.folk
@@ -1,60 +1,5 @@
set ::debug_keyboard true
-# Keeping this here for reference, do this in a loop for each keyboard that is Claimed as out :)
-# TODO: DELETE THIS, move this logic into virtual-programs/keyboard.folk
-while false {
- package require Thread
- proc errorproc {id errorInfo} {puts "Thread error in $id: $errorInfo"}
- thread::errorproc errorproc
-
- try {
- set keyboardThread [thread::create [format {
- source "pi/KeyCodes.tcl"
- source "lib/c.tcl"
- source "pi/cUtils.tcl"
- Keyboard::init
- puts "Keyboard tid: [getTid]"
-
- set keyStates [list up down repeat]
- set modifiers [dict create \
- shift 0 \
- ctrl 0 \
- alt 0 \
- ]
- # TODO: DELETE THIS, move this logic into virtual-programs/keyboard.folk
- while false {
- lassign [Keyboard::getKeyEvent] keyCode eventType
-
- set shift [dict get $modifiers shift]
- set key [keyFromCode $keyCode $shift]
- set keyState [lindex $keyStates $eventType]
-
- set isDown [expr {$keyState != "up"}]
- if {[string match *SHIFT $key]} {
- dict set modifiers shift $isDown
- }
- if {[string match *CTRL $key]} {
- dict set modifiers ctrl $isDown
- }
- if {[string match *ALT $key]} {
- dict set modifiers alt $isDown
- }
-
- set heldModifiers [dict keys [dict filter $modifiers value 1]]
-
- # Use `list` to escape special chars (brackets, quotes, whitespace)
- thread::send -async "%s" [subst {
- Retract keyboard claims key /k/ is /t/ with modifiers /m/
- Assert keyboard claims key [list $key] is [list $keyState] with modifiers [list $heldModifiers]
- }]
- }
- } [thread::id]]]
- puts "Keyboard thread id: $keyboardThread"
- } on error error {
- puts stderr "Keyboard thread failed: $error"
- }
-}
-
proc udevadmProperties {device} {
return [exec udevadm info --query=property --name=$device]
}
@@ -174,21 +119,31 @@ set keyboardDevices [walkInputEventPaths]
foreach keyboard $keyboardDevices {
set eventPath [dict get $keyboard eventPath]
Start process "keyboard-$eventPath" {
+ source "pi/KeyCodes.tcl"
+ Wish $::thisProcess shares statements like \
+ [list Assert keyboard /k/ claims key /code/ is /value/ /keyboardsList/]
+ Wish $::thisProcess shares statements like \
+ [list keyboard /k/ claims key /code/ is /value/ /keyboardsList/]
variable evtBytes 16
variable evtFormat iissi
if {[exec getconf LONG_BIT] == 64} {
- set evtBytes 24
- set evtFormat wwssi
+ set evtBytes 24
+ set evtFormat wwssi
}
set keyboardSpecifier $eventPath
+ set eventPathChannel [open $eventPath r]
puts "starting keyboard process for $keyboard"
+ set readCount 0
while 1 {
- puts "reading ... ($eventPath)"
- binary scan [read [open $eventPath r] $evtBytes] $evtFormat tvSec tvUsec type code value
- puts "read: $tvSec $tvUsec $type $code $value"
+ set readCount [incr $readCount]
+ puts "reading ... (readCount: $readCount) ($eventPath) from ($eventPathChannel)"
+ binary scan [read $eventPathChannel $evtBytes] $evtFormat tvSec tvUsec type code value
if {$type == 0x01} {
- puts "got key event ($keyboardSpecifier): $code | $value"
- return [list $code $value]
+ puts "read: $tvSec $tvUsec $type ([expr $type == 0x01]) $code $value"
+ puts "got key event ($keyboardSpecifier): $code => [keyFromCode $code false] | $value"
+ Retract keyboard $keyboardSpecifier claims key /k/ is /t/
+ Assert keyboard $keyboardSpecifier claims key [keyFromCode $code false] is [list $value]
+ # return [list $code $value]
}
}
@@ -398,4 +353,59 @@ Start process "keyboard" {
# Claim the default keyboard is "beep"
# Need to modify getKeyPress (define it in here, even, maybe???) to listen to all keyboards hmmmm
# Maybe it should even return a keyboard originator in the return value?
+}
+
+# Keeping this here for reference, do this in a loop for each keyboard that is Claimed as out :)
+# TODO: DELETE THIS, move this logic into virtual-programs/keyboard.folk
+while false {
+ package require Thread
+ proc errorproc {id errorInfo} {puts "Thread error in $id: $errorInfo"}
+ thread::errorproc errorproc
+
+ try {
+ set keyboardThread [thread::create [format {
+ source "pi/KeyCodes.tcl"
+ source "lib/c.tcl"
+ source "pi/cUtils.tcl"
+ Keyboard::init
+ puts "Keyboard tid: [getTid]"
+
+ set keyStates [list up down repeat]
+ set modifiers [dict create \
+ shift 0 \
+ ctrl 0 \
+ alt 0 \
+ ]
+ # TODO: DELETE THIS, move this logic into virtual-programs/keyboard.folk
+ while false {
+ lassign [Keyboard::getKeyEvent] keyCode eventType
+
+ set shift [dict get $modifiers shift]
+ set key [keyFromCode $keyCode $shift]
+ set keyState [lindex $keyStates $eventType]
+
+ set isDown [expr {$keyState != "up"}]
+ if {[string match *SHIFT $key]} {
+ dict set modifiers shift $isDown
+ }
+ if {[string match *CTRL $key]} {
+ dict set modifiers ctrl $isDown
+ }
+ if {[string match *ALT $key]} {
+ dict set modifiers alt $isDown
+ }
+
+ set heldModifiers [dict keys [dict filter $modifiers value 1]]
+
+ # Use `list` to escape special chars (brackets, quotes, whitespace)
+ thread::send -async "%s" [subst {
+ Retract keyboard claims key /k/ is /t/ with modifiers /m/
+ Assert keyboard claims key [list $key] is [list $keyState] with modifiers [list $heldModifiers]
+ }]
+ }
+ } [thread::id]]]
+ puts "Keyboard thread id: $keyboardThread"
+ } on error error {
+ puts stderr "Keyboard thread failed: $error"
+ }
} \ No newline at end of file