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