I have a solution: this works for getting data from a Wacom intuous tablet on Bela and send it to OSC:
/**
* How to use on Bela:
* Create a new C++ project on Bela and replace the content of its render.cpp file with this file.
* Make sure, compiler constant BELA is defined (the #define BELA statement below is uncommented)
* Replace the WACOM_DEVICE by the actual device (event), the WACOM is assigned to
*/
#define BELA
#define WACOM_DEVICE "/dev/input/event9"
/**
* How to read the data in SuperCollider:
thisProcess.openUDPPort(5555); // the port will stay open until you restart sclang or recompile the class library
x = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/wacom/x');
y = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/wacom/y');
pressed = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/wacom/pressed');
misc = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/wacom/misc');
*/
#include <fcntl.h>
#include <linux/input.h>
#include <errno.h>
#include <stdio.h>
#include <string>
#include <unistd.h>
#ifdef BELA
#include <oscpkt.hh>
#include <libraries/UdpClient/UdpClient.h>
std::string gOscAddress = "/wacom"; // OSC address. Message format: <address> <encoderId> <encoderValue>
std::string gDestinationIp = "192.168.7.1"; // address of the host computer
int gDestinationPort = 5555;
UdpClient sock;
#endif // BELA
static void sendOsc(const std::string& subPath, const double value)
{
#ifdef BELA
oscpkt::PacketWriter pw;
pw.init();
std::string address = gOscAddress + subPath;
oscpkt::Message msg(address);
pw.addMessage(msg.pushDouble(value));
printf("%s %d\n", address.c_str(), value);
if(pw.isOk()) {
sock.send((void*)pw.packetData(), pw.packetSize());
}
#endif // BELA
}
int main() {
#ifdef BELA
if(!sock.setup(gDestinationPort, gDestinationIp.c_str()))
{
fprintf(stderr, "Unable to send to %s:%d\n", gDestinationIp.c_str(), gDestinationPort);
return 1;
}
#endif // BELA
const char *dev = WACOM_DEVICE;
// qwerty keyboard capture
int fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s:.\n", dev);
return -1;
}
struct input_absinfo absinfo;
int x_min = 0;
int x_max = 0;
int y_min = 0;
int y_max = 0;
if (ioctl(fd, EVIOCGABS(ABS_X), &absinfo) == -1) {
fprintf(stderr, "Failed to get X axis abs info\n");
return -1;
}
x_min = absinfo.minimum;
x_max = absinfo.maximum;
printf("X value range [%d, %d]", x_min, x_max);
if (ioctl(fd, EVIOCGABS(ABS_Y), &absinfo) == -1){
fprintf(stderr, "Failed to get Y axis abs info\n");
return -1;
}
y_min = absinfo.minimum;
y_max = absinfo.maximum;
printf("Y value range [%d, %d]", y_min, y_max);
double x_position_normalized = 0.0;
double y_position_normalized = 0.0;
int event_size = 0;
struct input_event ev;
while (1) {
event_size = read(fd, &ev, sizeof(struct input_event));
if (event_size != sizeof(struct input_event)) {
printf("wrong size of event: %d\n", event_size);
return -1;
}
switch (ev.type) {
case EV_ABS:
switch (ev.code) {
case ABS_X:
x_position_normalized = (double) (ev.value - x_min) / (x_max - x_min);
#ifndef BELA
printf("X: %f\n", x_position_normalized);
#endif // BELA
sendOsc("/x", x_position_normalized);
break;
case ABS_Y:
y_position_normalized = (double) (ev.value - y_min) / (y_max - y_min);
#ifndef BELA
printf("Y: %f\n", y_position_normalized);
sendOsc("/y", y_position_normalized);
#endif // BELA
break;
}
break;
case EV_KEY:
printf("Key pressed: value %d, code %d\n",ev.value, ev.code);
sendOsc("/pressed", 1.0);
break;
case EV_MSC:
printf("Msc event: value: %d, code %d\n",ev.value, ev.code);
sendOsc("/misc", 1.0);
break;
}
usleep(10000);
}
close(fd); // won't actually get here unless an error occurs
return 0;
}