====== Keypad Widget / Keypad Driver ====== The keypad widget and keypad driver allows use of common buttons like up, down, left, right, ok/confirm and cancel. Added to CVS/SVN in Feb. 2006, the keypad code is still undergoing some development, and is only available on a couple of displays: [[:Crystalfontz|Crystalfontz]] 635, [[:LCD2USB|LCD2USB]] and [[:LW_ABP|LW_ABP]]. LCD4Linux-0.10.1-RC1 also supports [[:CwLinux]]. It's currently the only widget which doesn't make use of the //update// parameter. Instead of using preset time intervals, updates are performed when the button is actually pressed or released. At that time the expression is re-evaluated. This allows you to [[:plugin_exec|execute some program]] (perhaps reboot?) or simply change the value of a variable which is used by another widget. The mapping between keypad widgets and output lines is done in the //Layout// section: Just as you would place other widgets with //Row*.Col*// lines, you can map a keypad widget using a 'Keypad#' line. Note that the '#' used is of little consequence, just make it unique from the other keys used in that same layout. Here's the definition of a keypad widget: Widget { class 'Keypad' position state expression } ---- ===== Parameters: ===== |**position**|what button is toggled, defaults to confirm| |**state**|whether holding the button down or letting it go, defaults to pressed| |**expression**|expression to evaluate on button toggle| ---- ===== Example: ===== simple keypad example to increment a displayed variable: Widget mytext { class 'Text' expression foo update 100 } Widget keyok { class 'Keypad' position 'confirm' expression foo = foo + 1 } Variable { foo 1 } Layout demokeypad { Row1.Col1 'mytext' Keypad1 'keyok' } more sophisticated example to scroll thru dmesg output: Widget dmesg1 { class 'Text' expression file::readline('/var/log/dmesg',currline) width 20 update tick } Widget dmesg2 { class 'Text' expression file::readline('/var/log/dmesg',currline+1) width 20 update tick } Widget dmesg3 { class 'Text' expression file::readline('/var/log/dmesg',currline+2) width 20 update tick } Widget dmesg4 { class 'Text' expression file::readline('/var/log/dmesg',currline+3) width 20 update tick } Widget keyup { class 'Keypad' position 'up' state 'pressed' expression currline = currline-1 } Widget keydown { class 'Keypad' position 'down' state 'pressed' expression currline = currline+1 } Layout showdmesg { Row1 { Col1 'dmesg1' } Row2 { Col1 'dmesg2' } Row3 { Col1 'dmesg3' } Row4 { Col1 'dmesg4' } Keypad1 'keyup' Keypad2 'keydown' } Variables { tick 100 currline 1 } an example to use with reboot confirm: (right arrow selects reboot, left arrow cancels, confirm reboots using exec) widget keyRight{ class 'Keypad' position 'right' state 'pressed' expression msg = 'Reboot? OK to confirm' ; rebootmenu = 1 } widget keyConfirm{ class 'Keypad' position 'confirm' state 'pressed' expression msg = rebootmenu == 1 ? exec('/sbin/shutdown -r now',1000000) : 'Right arrow to reboot' exec('/sbin/shutdown -r now', 1000000); } widget keyLeft{ class 'Keypad' position 'left' state 'pressed' expression msg = 'Right arrow to reboot' ; rebootmenu = 0 } widget msgtxt { class 'Text' expression msg width 20 update 100 } Layout Default { Row1.Col1 'msgtxt' Row2.Col1 rebootmenu Keypad1 'keyRight' Keypad2 'keyConfirm' Keypad3 'keyLeft' } Variables { tick 500 msg 'Right arrow to reboot' rebootmenu 0 } ----