/* poll joystick */ void joystick(void) { int i; /* handle both virtual cbm joystick ports */ for (i = 0; i < 4; i++) { /* what kind of device is connected to the virtual port? */ int joy_port = joystick_port_map[i]; /* is HID joystick A mapped? */ if (joy_port == JOYDEV_HID_0) { if (joy_a.mapped) { BYTE joy_bits = read_joystick(&joy_a); joystick_set_value_absolute(i + 1, joy_bits); } } /* is HID joystick B mapped? */ else if (joy_port == JOYDEV_HID_1) { if (joy_b.mapped) { BYTE joy_bits = read_joystick(&joy_b); joystick_set_value_absolute(i + 1, joy_bits); } } } }
// // event handling routine for joystick device // void joystick_events(void) { event_t ev; if (!read_joystick()) return; ev.type = ev_joystick; ev.data1 = jdata.buttons; ev.data2 = (jdata.x < jleft) ? -1 : ((jdata.x > jright) ? 1 : 0); ev.data3 = (jdata.y < jup) ? -1 : ((jdata.y > jdown) ? 1 : 0); D_PostEvent(&ev); }
int main() { init_joystick(); while(1){ read_joystick(); const rc_t * rc = get_rc(); printf("throttle: % .3f, yaw: % .3f, pitch: % .3f, roll: % .3f, " "enable: %d, mode: %d, gear: %d, aux2: %d\n", rc->throttle,rc->yaw,rc->pitch,rc->roll,rc->enable,rc->mode,rc->gear,rc->aux2); usleep(100000); } }
// // initialze joystick device // void I_InitJoystick(void) { // open the device if ((joy_fd = open(JDEVICE, O_RDONLY)) < 0) printf("I_InitJoystick: cannot open joystick device %s\n", JDEVICE); // get the axis values (assuming neutral position) and setup diffs if (read_joystick()) { jleft = jdata.x - XTHRES; jright = jdata.x + XTHRES; jup = jdata.y - YTHRES; jdown = jdata.y + YTHRES; } }
INPUT_STATE _get_pause_exit_state (void) { INPUT_STATE InputState; InputState = 0; if (KeyDown (PauseKey)) { if (PauseFunc && (*PauseFunc) ()) ; } else if (KeyDown (ExitKey)) { InputState = DEVICE_EXIT; } #if 0 for (i = 0; i < JOYSTICKS_AVAIL; i++) { DWORD joy; joy = read_joystick (i); if (joy & ControlStart) // pause { if (PauseFunc && (*PauseFunc) ()) // while (KeyDown (PauseKey)) ; } else if (joy & ControlX) // exit { // while (KeyDown (ExitKey)) // TaskSwitch (); InputState = DEVICE_EXIT; } } #endif return (InputState); }
INPUT_STATE AnyButtonPress (BOOLEAN DetectSpecial) { int i; if (DetectSpecial) { if (KeyDown (PauseKey) && PauseFunc && (*PauseFunc) ()) ; } for (i = 0; i < sizeof (KeyboardDown) / sizeof (KeyboardDown[0]); ++i) { if (KeyboardDown[i]) return (DEVICE_BUTTON1); } #if 0 for (i = 0; i < JOYSTICKS_AVAIL; i++) if (read_joystick (i)) return (DEVICE_BUTTON1); #endif return (0); }
/* Note: scancodes are a bit changed: raw_key & 0x7f = standard scancode raw_key & 0x80 = 1 if key was preceeded with 0xe0 (like the gray arrows) raw_key & 0x200 = 1 if key was depressed Robert Golias */ int Atari_Keyboard(void) { int i; int keycode; int shift_mask; last_raw_key=raw_key; /* * Trigger and Joystick handling should * be moved into the Keyboard Interrupt Routine - done for keyboard-emulated joysticks */ if (joy_in) { read_joystick(js0_centre_x, js0_centre_y); /* read real PC joystick */ if (joytypes[0]==joy_analog) { stick0=astick; trig0=atrig; } if (joytypes[1]==joy_analog) { stick1=astick; trig1=atrig; } if (joytypes[2]==joy_analog) { stick2=astick; trig2=atrig; } if (joytypes[3]==joy_analog) { stick3=astick; trig3=atrig; } } /* read LPT joysticks */ for (i=0;i<4;i++) if (joytypes[i]>=joy_lpt1 && joytypes[i]<=joy_lpt3) read_LPTjoy(lptport[i],i); /* * This needs a bit of tidying up - array lookup */ /* Atari5200 stuff */ if (machine_type == MACHINE_5200 && !ui_is_active) { switch (raw_key) { case 0x3b: keycode = AKEY_UI; break; case 0x3f: /* F5 */ keycode = AKEY_COLDSTART; /* 5200 has no warmstart */ break; case 0x44: /* F10 */ if (!norepkey) { keycode = key_shift ? AKEY_SCREENSHOT_INTERLACE : AKEY_SCREENSHOT; norepkey=TRUE; }else keycode = AKEY_NONE; break; case 0x43: keycode = AKEY_EXIT; break; case 0x02: keycode = 0x3f; break; case 0x03: keycode = 0x3d; break; case 0x04: keycode = 0x3b; break; case 0x0D: keycode = 0x23; /* = = * */ break; case 0x05: keycode = 0x37; break; case 0x06: keycode = 0x35; break; case 0x07: keycode = 0x33; break; case 0x08: keycode = 0x2f; break; case 0x09: keycode = 0x2d; break; case 0x0C: keycode = 0x27; /* - = * */ break; case 0x0a: keycode = 0x2b; break; case 0x0b: keycode = 0x25; break; case 0x3e: /* 1f : */ keycode = 0x39; /* start */ break; case 0x19: keycode = 0x31; /* pause */ break; case 0x13: keycode = 0x29; /* reset */ break; case 0x42: /* F8 */ if (!norepkey) { keycode = Atari_Exit(1) ? AKEY_NONE : AKEY_EXIT; /* invoke monitor */ norepkey = TRUE; } else keycode = AKEY_NONE; break; default: keycode = AKEY_NONE; norepkey = FALSE; break; } if (raw_key_r!=0) {raw_key=raw_key_r;raw_key_r=0;} return keycode; } /* preinitialize of keycode */ shift_mask = key_shift ? 0x40 : 0; keycode = shift_mask | (control ? 0x80 : 0); switch (raw_key) { case 0x3b: /* F1 */ if (control) { PC_keyboard = TRUE; /* PC keyboard mode (default) */ keycode = AKEY_NONE; update_leds(); } else if (key_shift) { PC_keyboard = FALSE; /* Atari keyboard mode */ keycode = AKEY_NONE; update_leds(); } else keycode = AKEY_UI; break; case 0xCF: /* gray END*/ if (!norepkey) { keycode = AKEY_BREAK; norepkey = TRUE; } else keycode = AKEY_NONE; break; case 0x44: /* F10 */ if (!norepkey) { keycode = key_shift ? AKEY_SCREENSHOT_INTERLACE : AKEY_SCREENSHOT; norepkey = TRUE; } else keycode = AKEY_NONE; break; case 0x3f: /* F5 */ keycode = key_shift ? AKEY_COLDSTART : AKEY_WARMSTART; break; case 0x40: /* F6 */ if (machine_type != MACHINE_XLXE) keycode = AKEY_PIL; else keycode = AKEY_HELP; break; case 0x42: /* F8 */ if (!norepkey && !ui_is_active) { keycode = Atari_Exit(1) ? AKEY_NONE : AKEY_EXIT; /* invoke monitor */ norepkey = TRUE; } else keycode = AKEY_NONE; break; case 0x43: /* F9 */ keycode = AKEY_EXIT; break; case 0x57: /* F11 */ keycode = AKEY_NONE; for(i = 0; i < 4; i++) { if (++joy_autofire[i] > 2) joy_autofire[i] = 0; } raw_key = 0; /* aviod continuous change */ break; case 0x01: keycode |= AKEY_ESCAPE; break; case 0xD0: case 0x50: if (PC_keyboard) keycode = AKEY_DOWN; else { keycode |= AKEY_EQUAL; keycode ^= shift_mask; } break; case 0xCB: case 0x4b: if (PC_keyboard) keycode = AKEY_LEFT; else { keycode |= AKEY_PLUS; keycode ^= shift_mask; } break; case 0xCD: case 0x4d: if (PC_keyboard) keycode = AKEY_RIGHT; else { keycode |= AKEY_ASTERISK; keycode ^= shift_mask; } break; case 0xC8: case 0x48: if (PC_keyboard) keycode = AKEY_UP; else { keycode |= AKEY_MINUS; keycode ^= shift_mask; } break; case 0x29: /* "`" key on top-left */ keycode |= AKEY_ATARI; /* Atari key (inverse video) */ break; case 0x3a: keycode |= AKEY_CAPSTOGGLE; /* Caps key */ break; case 0x02: keycode |= AKEY_1; /* 1 */ break; case 0x03: if (!PC_keyboard) keycode |= AKEY_2; else if (key_shift) keycode = AKEY_AT; else keycode |= AKEY_2; /* 2,@ */ break; case 0x04: keycode |= AKEY_3; /* 3 */ break; case 0x05: keycode |= AKEY_4; /* 4 */ break; case 0x06: keycode |= AKEY_5; /* 5 */ break; case 0x07: if (!PC_keyboard) keycode |= AKEY_6; else if (key_shift) keycode = AKEY_CIRCUMFLEX; /* 6,^ */ else keycode |= AKEY_6; break; case 0x08: if (!PC_keyboard) keycode |= AKEY_7; else if (key_shift) keycode = AKEY_AMPERSAND; /* 7,& */ else keycode |= AKEY_7; break; case 0x09: if (!PC_keyboard) keycode |= AKEY_8; else if (key_shift) keycode = AKEY_ASTERISK; /* 8,* */ else keycode |= AKEY_8; break; case 0x0a: if (!PC_keyboard) keycode |= AKEY_9; else if (key_shift) keycode = AKEY_PARENLEFT; else keycode |= AKEY_9; /* 9,( */ break; case 0x0b: if (!PC_keyboard) keycode |= AKEY_0; else if (key_shift) keycode = AKEY_PARENRIGHT; /* 0,) */ else keycode |= AKEY_0; break; case 0x0c: if (!PC_keyboard) keycode |= AKEY_LESS; else if (key_shift) keycode = AKEY_UNDERSCORE; else keycode |= AKEY_MINUS; break; case 0x0d: if (!PC_keyboard) keycode |= AKEY_GREATER; else if (key_shift) keycode = AKEY_PLUS; else keycode |= AKEY_EQUAL; break; case 0x0e: keycode |= AKEY_BACKSPACE; break; case 0x0f: keycode |= AKEY_TAB; break; case 0x10: keycode |= AKEY_q; break; case 0x11: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_SOUND_RECORDING; /* ALT+W .. Select system */ } else keycode |= AKEY_w; break; case 0x12: keycode |= AKEY_e; break; case 0x13: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_RUN; /* ALT+R .. Run file */ } else keycode |= AKEY_r; break; case 0x14: keycode |= AKEY_t; break; case 0x15: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_SYSTEM; /* ALT+Y .. Select system */ } else keycode |= AKEY_y; break; case 0x16: keycode |= AKEY_u; break; case 0x17: keycode |= AKEY_i; break; case 0x18: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_SOUND; /* ALT+O .. mono/stereo sound */ } else keycode |= AKEY_o; break; case 0x19: keycode |= AKEY_p; break; case 0x1a: if (!PC_keyboard) keycode |= AKEY_MINUS; else if (control | key_shift) keycode |= AKEY_UP; else keycode = AKEY_BRACKETLEFT; break; case 0x1b: if (!PC_keyboard) keycode |= AKEY_EQUAL; else if (control | key_shift) keycode |= AKEY_DOWN; else keycode = AKEY_BRACKETRIGHT; break; case 0x9c: case 0x1c: keycode |= AKEY_RETURN; break; case 0x1e: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_ABOUT; /* ALT+A .. About */ } else keycode |= AKEY_a; break; case 0x1f: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_SAVESTATE; /* ALT+S .. Save state */ } else keycode |= AKEY_s; break; case 0x20: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_DISK; /* ALT+D .. Disk management */ } else keycode |= AKEY_d; break; case 0x21: keycode |= AKEY_f; break; case 0x22: keycode |= AKEY_g; break; case 0x23: keycode |= AKEY_h; break; case 0x24: keycode |= AKEY_j; break; case 0x25: keycode |= AKEY_k; break; case 0x26: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_LOADSTATE; /* ALT+L .. Load state */ } else keycode |= AKEY_l; break; case 0x27: keycode |= AKEY_SEMICOLON; break; case 0x28: if (!PC_keyboard) keycode |= AKEY_PLUS; else if (key_shift) keycode = AKEY_DBLQUOTE; else keycode = AKEY_QUOTE; break; case 0x2b: /* PC key "\,|" */ case 0x56: /* PC key "\,|" */ if (!PC_keyboard) keycode |= AKEY_ASTERISK; else if (key_shift) keycode = AKEY_BAR; else keycode |= AKEY_BACKSLASH; break; case 0x2c: keycode |= AKEY_z; break; case 0x2d: keycode |= AKEY_x; break; case 0x2e: if (alt_key) { keycode = AKEY_UI; alt_function = MENU_CARTRIDGE; /* ALT+C .. Cartridge management */ } else keycode |= AKEY_c; break; case 0x2f: keycode |= AKEY_v; break; case 0x30: keycode |= AKEY_b; break; case 0x31: keycode |= AKEY_n; break; case 0x32: keycode |= AKEY_m; break; case 0x33: if (!PC_keyboard) keycode |= AKEY_COMMA; else if (key_shift && !control) keycode = AKEY_LESS; else keycode |= AKEY_COMMA; break; case 0x34: if (!PC_keyboard) keycode |= AKEY_FULLSTOP; else if (key_shift && !control) keycode = AKEY_GREATER; else keycode |= AKEY_FULLSTOP; break; case 0x35: keycode |= AKEY_SLASH; break; case 0x39: keycode |= AKEY_SPACE; break; case 0xc7: /* HOME key */ keycode |= 118; /* clear screen */ break; case 0xd2: /* INSERT key */ if (key_shift) keycode = AKEY_INSERT_LINE; else keycode = AKEY_INSERT_CHAR; break; case 0xd3: /* DELETE key */ if (key_shift) keycode = AKEY_DELETE_LINE; else keycode = AKEY_DELETE_CHAR; break; default: keycode = AKEY_NONE; norepkey = FALSE; break; } if (raw_key_r!=0) {raw_key=raw_key_r;raw_key_r=0;} return keycode; }