First Release

Dependencies:   USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBJoystick.h Source File

USBJoystick.h

00001 /* USBJoystick.h */
00002 /* USB device example: Joystick*/
00003 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
00004 /* Modified Mouse code for Joystick - WH 2012 */
00005 
00006 // PS3向け改修版
00007 
00008 #ifndef USBJOYSTICK_H
00009 #define USBJOYSTICK_H
00010 
00011 #include "USBHID.h"
00012 
00013 #define REPORT_ID_JOYSTICK  4
00014 
00015 #define JOYSTICK_UP    (1<<0)
00016 #define JOYSTICK_DOWN  (1<<1)
00017 #define JOYSTICK_LEFT  (1<<2)
00018 #define JOYSTICK_RIGHT (1<<3)
00019 
00020 class USBJoystick: public USBHID
00021 {
00022     private:
00023         int8_t      _x;
00024         int8_t      _y;
00025         int8_t      _z;
00026         int8_t      _rz;
00027         uint32_t        _buttons;
00028         uint8_t     _stick; 
00029         
00030         void _init();
00031 
00032    public:
00033         /**
00034          *   Constructor
00035          *
00036          * @param vendor_id Your vendor_id (default: 0x1234)
00037          * @param product_id Your product_id (default: 0x0002)
00038          * @param product_release Your product_release (default: 0x0001)
00039          */
00040          USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0100, uint16_t product_release = 0x0001): 
00041              USBHID(0, 0, vendor_id, product_id, product_release, false)
00042              { 
00043                  _init();
00044                  connect();
00045              };
00046          
00047          /**
00048          * Write a state of the mouse
00049          *
00050          * @param x  x-axis position
00051          * @param y  y-axis position
00052          * @param z  z-axis position
00053          * @param rz rotate-z position
00054          * @param buttons buttons state
00055          * @param stick rest of buttons, and hat state 0 (up), 1 (right, 2 (down), 3 (left) or 4 (neutral)
00056          * @returns true if there is no error, false otherwise
00057          */
00058          bool update(int16_t x, int16_t y, int16_t z, int16_t rz, uint32_t buttons, uint8_t stick);
00059 
00060          /**
00061          * Write a state of the mouse
00062          *
00063          * @returns true if there is no error, false otherwise
00064          */
00065          bool update();
00066 
00067          
00068          /*
00069          * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
00070          *
00071          * @returns pointer to the report descriptor
00072          */
00073          virtual uint8_t * reportDesc();
00074 
00075 };
00076 
00077 #endif