can you create a new C++ project on Bela and replace the content of its render.cpp
file with the following:
#include <fcntl.h>
#include <linux/input.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(){
// Variables keyboard control
struct input_event ev;
const char *dev = "/dev/input/event1";
// qwerty keyboard capture
int fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s:.\n", dev);
return -1;
}
while (1)
{
ssize_t n = read(fd, &ev, sizeof ev);
if (n < 0) {
fprintf(stderr, "Error while reading: %d %s\n", errno, strerror(errno));
return -1;
} else if (n != sizeof(ev)) {
fprintf(stderr, "Read unexpected length\n");
return -1;
} else {
if (ev.type == EV_KEY && ev.value == 0 && ev.value <= 2)
{
// key released
int keyValue = ev.code;
printf("Released %d\n", keyValue);
}
if (ev.type == EV_KEY && ev.value == 1 && ev.value <= 2)
{
// key pressed
int keyValue = ev.code;
printf("Pressed %d\n", keyValue);
}
}
usleep(10000);
}
close(fd); // won't actually get here unless an error occurs
return 0;
}
You may have to edit the path in const char *dev = "/dev/input/event1";
if your pedal shows up at a different place ... running find /dev/input -exec ls -l {} \;
may help you disambiguate.
The code is adapted from here.
If the above prints some values as you press the key then you can either use Python to read from the device and send OSC, or I can add OSC support to this. To install Python packages via automated methods you probably need to connect your board to the internet (see https://learn.bela.io/using-bela/bela-techniques/connecting-to-wifi/)).