Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Key / Message Handling Application #146

Open
Ulrond opened this issue Nov 6, 2024 · 4 comments · May be fixed by #147
Open

Linux Key / Message Handling Application #146

Ulrond opened this issue Nov 6, 2024 · 4 comments · May be fixed by #147
Assignees
Labels
enhancement New feature or request

Comments

@Ulrond
Copy link
Contributor

Ulrond commented Nov 6, 2024

Problem

  • we need simply Linux command line application that takes a YAML message as input, and then sends it to the Linux input device.

Requirements

Write a Linux key handling app that can be built from source, but provides a yaml file, decodes the information and allows it to be sent to the correct ioctl

The yaml file input can then be defined and controlled by python_raft

	eventData->id = UIDEV_EVENT_IRKEY;
	eventData->data.irkey.keyType = keyType;
	eventData->data.irkey.keyCode = keyCode;

Resources

https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
https://kernel.org/doc/html/latest/input/uinput.html#examples

Testing and Monitoring Input Events

To test key codes or monitor input events, you can use the evtest tool, which shows key events and their codes when pressed on an input device:

Install evtest if it’s not already installed:

sudo apt install evtest

Run evtest and select the input device to monitor:

sudo evtest

Each key code follows a standardized format, allowing uniform interaction with input devices across Linux systems. These key codes are integral to applications and scripts interacting with the Linux input subsystem.

@Ulrond Ulrond transferred this issue from rdkcentral/ut-raft Nov 6, 2024
@Ulrond
Copy link
Contributor Author

Ulrond commented Nov 6, 2024

once written we need to add support into the IR module in raft, -> Common Remote

@Ulrond Ulrond added the enhancement New feature or request label Nov 6, 2024
@Ulrond Ulrond changed the title Linux Key Hanlding Application Linux Key / Message Handling Application Nov 7, 2024
@Ulrond
Copy link
Contributor Author

Ulrond commented Nov 7, 2024

Need to investigate the method more, but this is the basics, write an app that reads a config yaml and sends a message to the linux input

@kanjoe24 kanjoe24 transferred this issue from rdkcentral/ut-core Nov 19, 2024
@kanjoe24 kanjoe24 transferred this issue from rdkcentral/ut-control Nov 20, 2024
@kanjoe24
Copy link
Contributor

Can you attach an example of config yaml input here please @Ulrond

@Ulrond
Copy link
Contributor Author

Ulrond commented Nov 21, 2024

ut_core_key_input -p linux_profile_5.28.yaml is an input profile with keyvalue pair lookup from kernel 5.28, where the linux input header file is converted from https://github.com/torvalds/linux/blob/v5.15/include/uapi/linux/input-event-codes.h

e.g.

EV_KEY:
  KEY_RESERVED: 0
  KEY_ESC: 1
  KEY_1: 2
  KEY_2: 3
  KEY_3: 4
  KEY_4: 5
  KEY_5: 6
  KEY_6: 7
EV_REL:
...
EV_ABS:
...

So that you can run ut_core_key_input -p linux_profile_5.28.yaml --code KEY_ESC and it sends that through the linux input.

but here's the bigger issue, whilst we can default to just allowing passing --key we need to be able to consider scaling and could that be built in on day 1?

Event Type Purpose Codes (Examples) Value
EV_KEY Key presses and releases KEY_A, KEY_ENTER, KEY_LEFTCTRL 0 (release), 1 (press), 2 (repeat)
EV_REL Relative changes (mice, trackballs) REL_X, REL_Y, REL_WHEEL Amount of change (e.g., 5 for 5 units right)
EV_ABS Absolute position (touchscreens, joysticks) ABS_X, ABS_Y, ABS_PRESSURE Absolute position (e.g., X/Y coordinates)
EV_MSC Miscellaneous events MSC_SCAN, MSC_SERIAL Varies depending on the code
EV_SW Switches (on/off states) SW_LID, SW_TABLET_MODE 0 (off), 1 (on)
EV_LED LEDs (e.g., keyboard LEDs) LED_NUML, LED_CAPSL 0 (off), 1 (on)
EV_SND Sounds (beeps, alerts) SND_BELL, SND_TONE Usually not used
EV_REP Key repeat configuration REP_DELAY, REP_PERIOD Time in milliseconds
EV_FF Force feedback effects Varies Parameters for the effect

therefore the code looks like this for a mouse movement

struct input_event ev;
memset(&ev, 0, sizeof(ev));
ev.type = EV_REL; 
ev.code = REL_X;
ev.value = 10; // Move 10 units to the right
write(fd, &ev, sizeof(ev));

and looks like htis for a EV_KEY

void send_key(int fd, int code, int value) {
    struct input_event ev;
    memset(&ev, 0, sizeof(ev));
    ev.type = EV_KEY;
    ev.code = code;
    ev.value = value;
    write(fd, &ev, sizeof(ev));

Using the send_key() functions

// Press the 'A' key
send_key(fd, KEY_A, 1); 

// Release the 'A' key
send_key(fd, KEY_A, 0); 

So therefore the yaml needs to support these options, so this may work for all input types above.

key_example.yaml

event:
  type: EV_KEY
  code: KEY_ESC
  value: 1 # Release

and this works well..

ut_core_key_input -p linux_profile_5.28.yaml --type EV_KEY --code KEY_ESC --value 1

or

ut_core_key_input -p linux_profile_5.28.yaml --i key_example.yaml

@Ulrond Ulrond linked a pull request Nov 25, 2024 that will close this issue
@Ulrond Ulrond moved this to In Progress in UT-Core Roadmap Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

2 participants