Recent

Author Topic: Read Input Events  (Read 576 times)

nicolap

  • Newbie
  • Posts: 3
Read Input Events
« on: April 28, 2019, 07:55:42 pm »
Hi all,
I was in need to read a Rotary Encoder (like a Volume Knob) attached to an Raspberry PI and found nothing usefull.
So I translated some Kernel Header and wrote a pair of small program to read events and test it all.

This is the very first release, note that:
- tested on Raspberry PI with fpc 3.0.4 and Kernel 4.14.98;
- I used Delphi mode because I know it, not tested in fpc mode;
- there are some strange conditional define left because I write in the Delphi IDE, do a compile to check syntax then copy to the Raspberry PI and compile with fpc :-) ;
- a lot of strings has to be added to test program

Succesfully tested with:
- a rotary encoder, in config.txt:
  dtoverlay=rotary-encoder,pin_a=17,pin_b=27,steps-per-period=2,relative_axis
- a push button:
  dtoverlay=gpio-key,gpio=23,active_low,gpio_pull=up,label=P3,keycode=4
- a touch screen (USB, from a WaveShare 5" model B)

Files:
- IOCtl.pas conversion from ioctl.h, added e function to build ioctl codes at runtime because Pascal have not the flexibility of C preprocessor.
- input.pas conversion from input.h.
- inputeventcodes.pas conversion from input-event-codes.h.
- InputUtils.pas some simple helper functions.
- event.dpr a conversion from evtest.c, a simple program to show present event handlers and to check it.
- rotary.pas a class to read rotary encoder, uses threads.
- rotarytest.lpr a small program to test the TRotary class.

On GitHub: fpc_linux_events