Home Contents | # keyboard:setWheel | Keyboard | Core4 Lua Event System

## SYNOPSIS

#include <lua/sidekick-pins.lh>
#include <lua/scancode.lh>

1. kbdhandle:setWheel(wheel, { group=..., pin1=..., pin2=..., scancode1=..., scancode2=..., [flags = ...]})
2. kbdhandle:setWheel(wheel)
3. (deprecated) kbdhandle:setWheel(wheel, pin1, pin2, scancode1, scancode2, [flags])

## DESCRIPTION

Core4 has support for quadrature rotary encoders.

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

The wheel parameter numbers the wheel starting from 0 up to a controller specific limit.

The values of group and pin1 + pin2 indicate the pin numbers of the two quadrature signals from the encoder. Both pins must be in the same IO group.

There are different types of encoders available. Optical encoders usually report a single signal edge per 'click' of the wheel (flags = 0). Mechanical encoders often report two (flags = 1) or four (flags = 3) signal edges per 'click'. The flags parameter must be specified accordingly, default is 0.

Wheel events are reported as a simulated key-down/key-up pair. The value of scancode1 is used for a forward/clockwise turn, while scancode2 reports the reverse/anti-clockwise direction. 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 wheel.

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 five encoders which must be connected to two generic I/O pins 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.

## V4½ Controller

The V4½ supports four encoders, 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 with center push button and two additional separate push buttons. 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) })

## NOTES

It is recommended to stick to the definition that says scancode1 is for forward and scancode2 is for reverse direction. If you get the event reports swapped, you should swap the values for pin1 and pin2, not the scancodes.

## SEE ALSO

keyboard:setButton