Artifact 3129705f22a013d4684c7186f7e72aabd52a22865a0776018a4a673be2530716:
- File
src/hid/OHGameController.m
— part of check-in
[998339ff24]
at
2024-06-09 11:43:49
on branch trunk
— OHGamepad: Move some elements to OHExtendedGamepad
This allows to have a profile for limited gamepads such as found on the
Nintendo DS rather than only having the raw profile for those. (user: js, size: 2850) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3.0 only, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * version 3.0 for more details. * * You should have received a copy of the GNU Lesser General Public License * version 3.0 along with this program. If not, see * <https://www.gnu.org/licenses/>. */ #include "config.h" #import "OHGameController.h" #import "OFArray.h" #import "OFNumber.h" #import "OFSet.h" #if defined(OF_LINUX) && defined(OF_HAVE_FILES) # import "OHEvdevGameController.h" #endif #ifdef OF_WINDOWS # import "OHXInputGameController.h" #endif #ifdef OF_NINTENDO_DS # import "OHNintendoDSGameController.h" #endif #ifdef OF_NINTENDO_3DS # import "OHNintendo3DSGameController.h" #endif const uint16_t OHVendorIDSony = 0x054C; const uint16_t OHVendorIDNintendo = 0x057E; const uint16_t OHVendorIDGoogle = 0x18D1; const uint16_t OHProductIDDualShock4 = 0x09CC; const uint16_t OHProductIDDualSense = 0x0CE6; const uint16_t OHProductIDLeftJoyCon = 0x2006; const uint16_t OHProductIDRightJoyCon = 0x2007; const uint16_t OHProductIDN64Controller = 0x2019; const uint16_t OHProductIDStadiaController = 0x9400; @implementation OHGameController @dynamic name, rawProfile; + (OFArray OF_GENERIC(OHGameController *) *)controllers { #if defined(OF_LINUX) && defined(OF_HAVE_FILES) return [OHEvdevGameController controllers]; #elif defined(OF_WINDOWS) return [OHXInputGameController controllers]; #elif defined(OF_NINTENDO_DS) return [OHNintendoDSGameController controllers]; #elif defined(OF_NINTENDO_3DS) return [OHNintendo3DSGameController controllers]; #else return [OFArray array]; #endif } - (instancetype)init { if ([self isMemberOfClass: [OHGameController class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (OFNumber *)vendorID { return nil; } - (OFNumber *)productID { return nil; } - (void)retrieveState { OF_UNRECOGNIZED_SELECTOR } - (OHGamepad *)gamepad { return nil; } - (OHExtendedGamepad *)extendedGamepad { return nil; } - (OFString *)description { if (self.vendorID != nil && self.productID != nil) return [OFString stringWithFormat: @"<%@: %@ [%04X:%04X]>", self.class, self.name, self.vendorID.unsignedShortValue, self.productID.unsignedShortValue]; else return [OFString stringWithFormat: @"<%@: %@>", self.class, self.name]; } @end