michael@0: /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // mostly derived from the Allegro source code at: michael@0: // http://alleg.svn.sourceforge.net/viewvc/alleg/allegro/branches/4.9/src/macosx/hidjoy.m?revision=13760&view=markup michael@0: michael@0: #include "mozilla/dom/GamepadService.h" michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: michael@0: namespace { michael@0: michael@0: using mozilla::dom::GamepadService; michael@0: michael@0: using std::vector; michael@0: michael@0: struct Button { michael@0: int id; michael@0: IOHIDElementRef element; michael@0: }; michael@0: michael@0: struct Axis { michael@0: int id; michael@0: IOHIDElementRef element; michael@0: CFIndex min; michael@0: CFIndex max; michael@0: }; michael@0: michael@0: // These values can be found in the USB HID Usage Tables: michael@0: // http://www.usb.org/developers/hidpage michael@0: #define GENERIC_DESKTOP_USAGE_PAGE 0x01 michael@0: #define JOYSTICK_USAGE_NUMBER 0x04 michael@0: #define GAMEPAD_USAGE_NUMBER 0x05 michael@0: #define AXIS_MIN_USAGE_NUMBER 0x30 michael@0: #define AXIS_MAX_USAGE_NUMBER 0x35 michael@0: #define BUTTON_USAGE_PAGE 0x09 michael@0: michael@0: class Gamepad { michael@0: private: michael@0: IOHIDDeviceRef mDevice; michael@0: vector