42 static const unsigned char BBOX_RESET = 0x20;
43 static const int VRPN_DIAL_RANGE = 200;
49 char *serialPortName):
59 sprintf(message,
"vrpn_raw_SGIBox: error opening serial port: %s\n",serialPortName);
80 unsigned char inbuf[100];
82 unsigned char lightson[5] = {0x75, 0xff, 0xff, 0xff, 0xff};
83 unsigned char lightsoff[5] = {0x75, 0x00, 0x00, 0x00, 0x00};
85 unsigned char activatebuttons[5] = {0x73, 0xff, 0xff, 0xff, 0xff};
86 unsigned char enablebuttons[5] = {0x71, 0xff, 0xff, 0xff, 0xff};
87 unsigned char enabledials[3] = {0x50, 0xff, 0xff};
96 perror(
"vrpn_raw_SGIBox::reset(): Can't flush incoming buffer");
100 perror(
"vrpn_raw_SGIBox::reset(): Can't write reset command");
104 perror(
"vrpn_raw_SGIBox::reset(): Can't write reset command");
111 perror(
"vrpn_raw_SGIBox::reset(): Can't read or no data from serial port");
115 printf(
"vrpn_raw_SGIBox::reset(): Box's response to reset command: %02x\n", inbuf[0]);
118 for (i = 0; i < ret; i++) {
119 if (inbuf[i] != BBOX_RESET) {
121 fprintf(stderr,
"vrpn_raw_SGIBox::reset(): Bad response to reset command : %02x- please restart sgiBox vrpn server\n",inbuf[i]);
127 if (serialfd != -1) {
128 printf(
"vrpn_raw_SGIBox: flashing the lights on then off...\n");
130 perror(
"vrpn_raw_SGIBox::reset(): Can't turn the lights on");
135 perror(
"vrpn_raw_SGIBox::reset(): Can't turn the lights off");
143 if (serialfd != -1) {
147 perror(
"vrpn_raw_SGIBox::reset(): Can't enable dials");
152 printf(
"vrpn_raw_SGIBOX::reset() : Enabled Dials\n");
157 for (i=0; i < 2; i++) {
160 perror(
"vrpn_raw_SGIBox::reset(): Can't enable buttons");
165 printf(
"vrpn_raw_SGIBOX::reset() : Enabled Buttons\n");
169 perror(
"vrpn_raw_SGIBox::reset(): Can't activate buttons\n");
174 printf(
"vrpn_raw_SGIBOX::reset() : Activated Buttons\n");
206 unsigned char command) {
207 if ( (command >= base_command) && (command < (base_command+8)) ) {
208 buttons[base_button + (command-base_command)] = 1;
216 unsigned char command) {
217 if ( (command >= base_command) && (command < (base_command+8)) ) {
218 buttons[base_button + (command-base_command)] = 0;
231 unsigned char command;
235 printf(
"."); fflush(stdout);
246 perror(
"vrpn_raw_SGIBOX::get_report(): error reading serial port - reseting...");
253 printf(
"vrpn_raw_SGIBox::get_report(): Got %02x\n", command);
257 if (command == 0x20) {
258 perror(
"vrpn_raw_SGIBOX::get_report(): Got reset response when we didn't expect it - reseting...\n");
264 if ( command >= 0xC0 ) {
286 if ( (command >= 0x30) && (command <= 0x37) ) {
288 printf(
"vrpn_raw_SGIBOX::get_report(): Got dial event\n");
290 unsigned char dial_value[2];
291 int i = command - 0x30;
293 struct timeval timeout = {0, 10000};
298 perror(
"vrpn_raw_SGIBOX: starting getting a dial command from box, but message wasn't completed -reseting ...");
303 printf(
"vrpn_raw_SGIBOX::get_report(): Dial event %02x:[ %02x %02x] \n",
304 command,dial_value[0],dial_value[1]);
308 value = static_cast<short>((dial_value[0]<<8) | dial_value[1]);
314 int temp = value - mid_values[i];
315 if (temp > VRPN_DIAL_RANGE) {
317 mid_values[i] = value - VRPN_DIAL_RANGE;
318 }
else if (temp < -VRPN_DIAL_RANGE) {
320 mid_values[i] = value + VRPN_DIAL_RANGE;
327 dials[i] = (value-last_values[i])/(
double)(VRPN_DIAL_RANGE);
328 last_values[i] = value;
335 ( (command >= 0x30) && (command <= 0x37) ) ||
339 perror(
"vrpn_raw_SGIBOX: unrecognized command from sgiBox - reseting...");
352 unsigned char lights[4];
353 unsigned char msg[5];
357 for (bank = 0; bank < 4; bank++) {
359 for (i = 0; i < 8; i++) {
360 int buttonLightNumber = bank*8 + i;
362 lights[bank]=static_cast<unsigned char>(lights[bank]|1<<i);
370 msg[0] = 0x75; memcpy(&msg[1],lights,4);
372 perror(
"Could not write light control message");
395 printf(
"vrpn_raw_SGIBox::Get first new connection, reset the box\n");