Sweet! For that kind of interface, I'd probably try to synthesize multi-axis events. Here's code that parses those events from a space navigator. It should be reasonably easy to generate events like this instead of parsing them, and write them to a named pipe. Then point earth at the pipe instead of an actual spacenav.
// Released into the public domain, 25 June 2009
// Google, inc. Jason E. Holt <jholt [at]
google.com>
//
// Documentation and example code on how to read our 3dconnexion space navigator
// using the /dev/input/event* interface.
// Our navigator shows up as:
// Bus 007 Device 004: ID 0510:1004 Sejin Electron, Inc.
#include <sys/ioctl.h>
#include <error.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
main(int argc, char **argv) {
int fd;
if ((fd = open(argv[1], O_RDONLY | O_NONBLOCK)) < 0) {
perror("opening the file you specified");
exit(1);
}
printf("ev_rel:%d ev_abs:%d ev_key:%d\n", EV_REL, EV_ABS, EV_KEY);
float x, y, z, yaw, pitch, roll;
x = y = z = yaw = pitch = roll = 0.0;
while(1) {
//int event_data[6];
struct input_event ev;
struct input_event *event_data = &ev;
int num_read = read(fd, event_data, sizeof(ev));
if (sizeof(ev) != num_read) {
printf("only read %d\n", num_read);
usleep(100000);
continue;
} else {
}
/*
printf("Timestamp %d:%d type: %hx %hx %x\n",
ev.time.tv_sec, ev.time.tv_usec,
ev.type, ev.code, ev.value);
*/
if (event_data->type == EV_KEY) {
printf("button press\n");
} else if (event_data->type != EV_REL) {
printf("Unknown event type\n");
} else {
int axis = event_data->code;
int move_amount = event_data->value;
switch(axis) {
case 0:
x = -move_amount * 0.08;
break;
case 1:
y = -move_amount * 0.08;
break;
case 2:
z = -move_amount * 0.31;
break;
case 3:
pitch = move_amount * 0.0001;
break;
case 4:
roll = move_amount * (1.0 / 24000.0);
break;
case 5:
yaw = -move_amount * 0.0001;
break;
default:
printf("unknown axis event\n");
break;
}
int state_file = open("/tmp/spacenav.tmp", O_CREAT | O_WRONLY, 0644);
if (state_file == -1) perror("opening /tmp/spacenav.tmp");
char state_string[1000];
sprintf(state_string, "%f,%f,%f,%f,%f,%f",
x,y,z,yaw,pitch,roll);
printf("%s\n", state_string);
write(state_file, state_string, strlen(state_string));
close(state_file);
rename("/tmp/spacenav.tmp", "/tmp/spacenav");
}
}
}