/* * Callback to enumerate joysticks */ static BOOL enumerateJoysticks (AIN_Device *device, void *UserData) { APTR context = ((struct enumPacket *)UserData)->context; uint32 *count = ((struct enumPacket *)UserData)->count; struct joystick *joy = &((struct enumPacket *)UserData)->joyList[*count]; BOOL result = FALSE; if (*count < MAX_JOYSTICKS) { if (device->Type == AINDT_JOYSTICK) { unsigned int i; joy->context = context; joy->id = device->DeviceID; joy->name = my_strdup (device->DeviceName); joy->axisCount = device->NumAxes; joy->buttonCount = device->NumButtons; if (joy->axisCount > MAX_AXES) joy->axisCount = MAX_AXES; if (joy->buttonCount > MAX_BUTTONS) joy->buttonCount = MAX_BUTTONS; /* Query offsets in ReadDevice buffer for axes' data */ for (i = 0; i < joy->axisCount; i++) result = AIN_Query (joy->context, joy->id, AINQ_AXIS_OFFSET, i, &(joy->axisBufferOffset[i]), 4); /* Query offsets in ReadDevice buffer for buttons' data */ for (i = 0; i < joy->buttonCount; i++) result = result && AIN_Query (joy->context, joy->id, AINQ_BUTTON_OFFSET, i, &(joy->buttonBufferOffset[i]), 4); if (result) { write_log ("Found joystick #%d (AI ID=%d) '%s' with %d axes, %d buttons\n", *count, joy->id, joy->name, joy->axisCount, joy->buttonCount); (*count)++; } } } return result; }
static void update_inputs(ULONG ID) { char name[256]; unsigned int i; int num, offset; for (i = 0; i < inputs.count; i++) { lib_free(inputs.names[i]); } memset(&inputs, 0, sizeof(inputs)); inputs.offsets[0] = 0; inputs.names[0] = lib_stralloc("-"); inputs.types[0] = TYPE_NONE; inputs.count++; if (ID == -1) { return; } /* BUTTON */ AIN_Query(CTX, ID, AINQ_NUMBUTTONS, 0, &num, sizeof(num)); AIN_Query(CTX, ID, AINQ_BUTTON_OFFSET, 0, &offset, sizeof(offset)); for (i = 0; i < num; i++) { name[0] = '\0'; AIN_Query(CTX, ID, AINQ_BUTTONNAME, i, name, sizeof(name)); if (name[0] != '\0') { inputs.offsets[inputs.count] = offset + i; inputs.names[inputs.count] = lib_stralloc(name); inputs.types[inputs.count] = TYPE_BUTTON; inputs.count++; } } /* AXES */ AIN_Query(CTX, ID, AINQ_NUMAXES, 0, &num, sizeof(num)); AIN_Query(CTX, ID, AINQ_AXIS_OFFSET, 0, &offset, sizeof(offset)); for (i = 0; i < num; i++) { name[0] = '\0'; AIN_Query(CTX, ID, AINQ_AXISNAME, i, name, sizeof(name)); if (name[0] != '\0') { inputs.offsets[inputs.count] = offset + i; inputs.names[inputs.count] = lib_stralloc(name); inputs.types[inputs.count] = TYPE_AXES; inputs.count++; } } /* HATS */ AIN_Query(CTX, ID, AINQ_NUMHATS, 0, &num, sizeof(num)); AIN_Query(CTX, ID, AINQ_HAT_OFFSET, 0, &offset, sizeof(offset)); for (i = 0; i < num; i++) { name[0] = '\0'; AIN_Query(CTX, ID, AINQ_HATNAME, i, name, sizeof(name)); if (name[0] != '\0') { inputs.offsets[inputs.count] = offset + i; inputs.names[inputs.count] = lib_stralloc(name); inputs.types[inputs.count] = TYPE_HAT; inputs.count++; } } }