USB Mouse (relative) example for mbed NXP LPC11U24 beta

Committer:
chris
Date:
Mon Oct 24 10:26:27 2011 +0000
Revision:
0:163560051396

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:163560051396 1 /* GenericMouse.h */
chris 0:163560051396 2 /* Copyright (c) 2011 ARM Limited. All rights reserved. */
chris 0:163560051396 3
chris 0:163560051396 4 #ifndef _GENERIC_MOUSE_
chris 0:163560051396 5 #define _GENERIC_MOUSE_
chris 0:163560051396 6
chris 0:163560051396 7 #include "USBHID.h"
chris 0:163560051396 8
chris 0:163560051396 9 #define REPORT_ID_MOUSE 2
chris 0:163560051396 10
chris 0:163560051396 11 /* Common usage */
chris 0:163560051396 12 #define MOUSE_LEFT (1U << 0) /*!< Left Button */
chris 0:163560051396 13 #define MOUSE_RIGHT (1U << 1) /*!< Right Button */
chris 0:163560051396 14 #define MOUSE_MIDDLE (1U << 2) /*!< Middle Button */
chris 0:163560051396 15
chris 0:163560051396 16 /* X and Y limits */
chris 0:163560051396 17 /* These values do not directly map to screen pixels */
chris 0:163560051396 18 /* Zero may be interpreted as meaning 'no movement' */
chris 0:163560051396 19 #define X_MIN_ABS (1) /*!< Minimum value on x-axis */
chris 0:163560051396 20 #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */
chris 0:163560051396 21 #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */
chris 0:163560051396 22 #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */
chris 0:163560051396 23
chris 0:163560051396 24 #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */
chris 0:163560051396 25 #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */
chris 0:163560051396 26 #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */
chris 0:163560051396 27 #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */
chris 0:163560051396 28
chris 0:163560051396 29
chris 0:163560051396 30
chris 0:163560051396 31 /** Generic Mouse
chris 0:163560051396 32 *
chris 0:163560051396 33 * This class is just an API to use in a child class. See USBMouse.h for instance for more information.
chris 0:163560051396 34 *
chris 0:163560051396 35 */
chris 0:163560051396 36 class GenericMouse
chris 0:163560051396 37 {
chris 0:163560051396 38 public:
chris 0:163560051396 39 /**
chris 0:163560051396 40 * Constructor for a Generic Mouse
chris 0:163560051396 41 */
chris 0:163560051396 42 GenericMouse(){ button = 0;};
chris 0:163560051396 43
chris 0:163560051396 44 /**
chris 0:163560051396 45 * Update the state of the mouse
chris 0:163560051396 46 *
chris 0:163560051396 47 * @param x x-axis position (can be absolute or relative)
chris 0:163560051396 48 * @param y y-axis position (can be absolute or relative)
chris 0:163560051396 49 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
chris 0:163560051396 50 * @param z wheel state (>0 to scroll down, <0 to scroll up)
chris 0:163560051396 51 * @return true if there is no error, false otherwise
chris 0:163560051396 52 */
chris 0:163560051396 53 virtual bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z){return false;};
chris 0:163560051396 54
chris 0:163560051396 55 /**
chris 0:163560051396 56 * Move the cursor to (x, y)
chris 0:163560051396 57 *
chris 0:163560051396 58 * @param x x-axis position (can be absolute or relative)
chris 0:163560051396 59 * @param y y-axis position (can be absolute or relative)
chris 0:163560051396 60 * @return true if there is no error, false otherwise
chris 0:163560051396 61 */
chris 0:163560051396 62 bool move(int16_t x, int16_t y);
chris 0:163560051396 63
chris 0:163560051396 64 /**
chris 0:163560051396 65 * Press one or several buttons
chris 0:163560051396 66 *
chris 0:163560051396 67 * @param button button state (ex: press(MOUSE_LEFT))
chris 0:163560051396 68 * @return true if there is no error, false otherwise
chris 0:163560051396 69 */
chris 0:163560051396 70 bool press(uint8_t button);
chris 0:163560051396 71
chris 0:163560051396 72 /**
chris 0:163560051396 73 * Release one or several buttons
chris 0:163560051396 74 *
chris 0:163560051396 75 * @param button button state (ex: release(MOUSE_LEFT))
chris 0:163560051396 76 * @return true if there is no error, false otherwise
chris 0:163560051396 77 */
chris 0:163560051396 78 bool release(uint8_t button);
chris 0:163560051396 79
chris 0:163560051396 80 /**
chris 0:163560051396 81 * Double click (MOUSE_LEFT)
chris 0:163560051396 82 *
chris 0:163560051396 83 * @return true if there is no error, false otherwise
chris 0:163560051396 84 */
chris 0:163560051396 85 bool doubleClick();
chris 0:163560051396 86
chris 0:163560051396 87 /**
chris 0:163560051396 88 * Click
chris 0:163560051396 89 *
chris 0:163560051396 90 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
chris 0:163560051396 91 * @return true if there is no error, false otherwise
chris 0:163560051396 92 */
chris 0:163560051396 93 bool click(uint8_t button);
chris 0:163560051396 94
chris 0:163560051396 95 /**
chris 0:163560051396 96 * Scrolling
chris 0:163560051396 97 *
chris 0:163560051396 98 * @param z value of the wheel (>0 to go down, <0 to go up)
chris 0:163560051396 99 * @return true if there is no error, false otherwise
chris 0:163560051396 100 */
chris 0:163560051396 101 bool scroll(int8_t z);
chris 0:163560051396 102
chris 0:163560051396 103 private:
chris 0:163560051396 104 uint8_t button;
chris 0:163560051396 105 };
chris 0:163560051396 106
chris 0:163560051396 107 #endif