Home  Contents

keyboard:setButton

Keyboard Core4 Lua Event System

SYNOPSIS

#include <lua/sidekick-pins.lh>
#include <lua/scancode.lh>
  1. kbdhandle:setButton(button, { group=..., pin=..., scancode=...)
  2. kbdhandle:setButton(button)
  3. (deprecated) kbdhandle:setButton(button, pin, scancode)

DESCRIPTION

Core4 has support for plain push buttons. The buttons are automatically debounced and reported to the application as standard keyboard events.

The V4 and V4½ support different ways of connections. See below for controller specific discussion.

The button parameter numbers the wheel starting from 0 up to a controller specific limit. This number is reported within input events on the keyboard handle.

The values of group and pin indicate the pin number of the button.

The value of scancode will be reported in the key press event when the button is pressed. To assign a generic scancode, use SCANCODE(KEY_xxx), using one of the scancode definitions from lua/scancode.lh

The second form of the command, with no further parameters, disables the specified button.

The third form is deprecated and only recommended to keep old code working. It does not allow to specify the group parameter. The group is fixed to GPGRP_SIDEKICK. This command is therefore only useful on the V4 controller.

V4 Controller

The V4 controller can handle up to sixteen buttons which must be connected to a generic I/O pin each. These pins are available at the GPIO port J10, the LED port J8 or the card reader port J13.

The group parameter must be set to GPGRP_SIDEKICK.

The include file usr/include/core/sidekick-pins.h (found in the SDK directory) lists the available pins together with the connector name and pin number.

The following example will configure general purpose input 0 to generate the RETURN key:

kbd:setButton(0, { group=GPGRP_SIDEKICK, pin=0, scancode=SCANCODE(KEY_RETURN) })

V4½ Controller

The V4½ supports sixteen pushbuttons, which must be connected to two generic I/O pins each.

The group parameter must be set to GPGRP_GPIO.

Actual available pins depend on the carrier board used together with the V4½ cpu.

The TBM-1000 (V4.5-CAN8 carrier with V4.5-CPU) has one rotary encoder built-in: pushbutton on input 0, rotary phases on inputs 1 and 2. This is the recommended initialization command sequence:

-- Rotary encoder kbd:setWheel(0, { group=GPGRP_GPIO, pin1=5, pin2=6, scancode1=SCANCODE(KEY_VOLUME_UP), scancode2=SCANCODE(KEY_VOLUME_DOWN), flags=1 }) -- Rotary encoder center button mapped to TAB kbd:setButton(0, { group=GPGRP_GPIO, pin=4, scancode=SCANCODE(KEY_TAB) }) -- OK button mapped to RETURN kbd:setButton(1, { group=GPGRP_GPIO, pin=9, scancode=SCANCODE(KEY_RETURN) }) -- Cancel button mapped to ESC kbd:setButton(2, { group=GPGRP_GPIO, pin=7, scancode=SCANCODE(KEY_ESCAPE) })

SEE ALSO