USB Mouse (relative) example for mbed NXP LPC11U24 beta

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GenericMouse.h Source File

GenericMouse.h

00001 /* GenericMouse.h */
00002 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
00003 
00004 #ifndef _GENERIC_MOUSE_
00005 #define _GENERIC_MOUSE_
00006 
00007 #include "USBHID.h"
00008 
00009 #define REPORT_ID_MOUSE   2
00010 
00011 /* Common usage */
00012 #define MOUSE_LEFT     (1U << 0)   /*!< Left Button */
00013 #define MOUSE_RIGHT    (1U << 1)   /*!< Right Button */
00014 #define MOUSE_MIDDLE   (1U << 2)   /*!< Middle Button */
00015 
00016 /* X and Y limits */
00017 /* These values do not directly map to screen pixels */
00018 /* Zero may be interpreted as meaning 'no movement' */
00019 #define X_MIN_ABS    (1)        /*!< Minimum value on x-axis */  
00020 #define Y_MIN_ABS    (1)        /*!< Minimum value on y-axis */
00021 #define X_MAX_ABS    (0x7fff)   /*!< Maximum value on x-axis */
00022 #define Y_MAX_ABS    (0x7fff)   /*!< Maximum value on y-axis */
00023 
00024 #define X_MIN_REL    (-127)     /*!< The maximum value that we can move to the left on the x-axis */
00025 #define Y_MIN_REL    (-127)     /*!< The maximum value that we can move up on the y-axis */
00026 #define X_MAX_REL    (127)      /*!< The maximum value that we can move to the right on the x-axis */
00027 #define Y_MAX_REL    (127)      /*!< The maximum value that we can move down on the y-axis */
00028 
00029 
00030 
00031 /** Generic Mouse
00032  *
00033  * This class is just an API to use in a child class. See USBMouse.h for instance for more information.
00034  *
00035  */
00036 class GenericMouse
00037 {
00038     public:
00039         /**
00040         *   Constructor for a Generic Mouse
00041         */
00042         GenericMouse(){ button = 0;};
00043         
00044         /**
00045         * Update the state of the mouse
00046         *
00047         * @param x x-axis position (can be absolute or relative)
00048         * @param y y-axis position (can be absolute or relative)
00049         * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
00050         * @param z wheel state (>0 to scroll down, <0 to scroll up)
00051         * @return true if there is no error, false otherwise
00052         */
00053         virtual bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z){return false;};
00054         
00055         /**
00056         * Move the cursor to (x, y)
00057         *
00058         * @param x x-axis position (can be absolute or relative)
00059         * @param y y-axis position (can be absolute or relative)
00060         * @return true if there is no error, false otherwise
00061         */
00062         bool move(int16_t x, int16_t y);
00063         
00064         /**
00065         * Press one or several buttons
00066         *
00067         * @param button button state (ex: press(MOUSE_LEFT))
00068         * @return true if there is no error, false otherwise
00069         */
00070         bool press(uint8_t button);
00071         
00072         /**
00073         * Release one or several buttons
00074         *
00075         * @param button button state (ex: release(MOUSE_LEFT))
00076         * @return true if there is no error, false otherwise
00077         */
00078         bool release(uint8_t button);
00079         
00080         /**
00081         * Double click (MOUSE_LEFT)
00082         *
00083         * @return true if there is no error, false otherwise
00084         */
00085         bool doubleClick();
00086         
00087         /**
00088         * Click
00089         *
00090         * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
00091         * @return true if there is no error, false otherwise
00092         */
00093         bool click(uint8_t button); 
00094         
00095         /**
00096         * Scrolling
00097         *
00098         * @param z value of the wheel (>0 to go down, <0 to go up)
00099         * @return true if there is no error, false otherwise
00100         */
00101         bool scroll(int8_t z);
00102         
00103     private:
00104         uint8_t button;
00105 };
00106 
00107 #endif