1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include <stdio.h>
- #include <stdlib.h>
- #ifndef WIN32
- #include <unistd.h>
- #endif
- #include "lo/lo.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <spnav.h>
- void sig(int s)
- {
- spnav_close();
- exit(0);
- }
- int main(void)
- {
- spnav_event sev;
- signal(SIGINT, sig);
- if(spnav_open()==-1) {
- fprintf(stderr, "failed to connect to the space navigator daemon\n");
- return 1;
- }
- lo_address t = lo_address_new(NULL, "7770");
-
-
- while(spnav_wait_event(&sev)) {
- if(sev.type == SPNAV_EVENT_MOTION) {
- printf("got motion event: t(%d, %d, %d) ", sev.motion.x, sev.motion.y, sev.motion.z);
- printf("r(%d, %d, %d)\n", sev.motion.rx, sev.motion.ry, sev.motion.rz);
- lo_send(t, "/motion", "iiiiii",sev.motion.x, sev.motion.y, sev.motion.z, sev.motion.rx, sev.motion.ry, sev.motion.rz);
-
- } else {
- printf("got button %s event b(%d)\n", sev.button.press ? "press" : "release", sev.button.bnum);
- lo_send(t, "/button", "ii", sev.button.press ? 1 : 0, sev.button.bnum);
- }
- }
- spnav_close();
- return 0;
- }
|