Hideharu Tsunemoto / Mbed 2 deprecated SmallDoseMeter_Single_AE_LPC11U35

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 08:51:33 2018 +0000
Revision:
0:871ab6846b18
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
H_Tsunemoto 0:871ab6846b18 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
H_Tsunemoto 0:871ab6846b18 2 *
H_Tsunemoto 0:871ab6846b18 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
H_Tsunemoto 0:871ab6846b18 4 * and associated documentation files (the "Software"), to deal in the Software without
H_Tsunemoto 0:871ab6846b18 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
H_Tsunemoto 0:871ab6846b18 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
H_Tsunemoto 0:871ab6846b18 7 * Software is furnished to do so, subject to the following conditions:
H_Tsunemoto 0:871ab6846b18 8 *
H_Tsunemoto 0:871ab6846b18 9 * The above copyright notice and this permission notice shall be included in all copies or
H_Tsunemoto 0:871ab6846b18 10 * substantial portions of the Software.
H_Tsunemoto 0:871ab6846b18 11 *
H_Tsunemoto 0:871ab6846b18 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
H_Tsunemoto 0:871ab6846b18 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
H_Tsunemoto 0:871ab6846b18 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
H_Tsunemoto 0:871ab6846b18 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
H_Tsunemoto 0:871ab6846b18 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
H_Tsunemoto 0:871ab6846b18 17 */
H_Tsunemoto 0:871ab6846b18 18
H_Tsunemoto 0:871ab6846b18 19 #ifndef USBMOUSE_H
H_Tsunemoto 0:871ab6846b18 20 #define USBMOUSE_H
H_Tsunemoto 0:871ab6846b18 21
H_Tsunemoto 0:871ab6846b18 22 #include "USBHID.h"
H_Tsunemoto 0:871ab6846b18 23
H_Tsunemoto 0:871ab6846b18 24 #define REPORT_ID_MOUSE 2
H_Tsunemoto 0:871ab6846b18 25
H_Tsunemoto 0:871ab6846b18 26 /* Common usage */
H_Tsunemoto 0:871ab6846b18 27
H_Tsunemoto 0:871ab6846b18 28 enum MOUSE_BUTTON
H_Tsunemoto 0:871ab6846b18 29 {
H_Tsunemoto 0:871ab6846b18 30 MOUSE_LEFT = 1,
H_Tsunemoto 0:871ab6846b18 31 MOUSE_RIGHT = 2,
H_Tsunemoto 0:871ab6846b18 32 MOUSE_MIDDLE = 4,
H_Tsunemoto 0:871ab6846b18 33 };
H_Tsunemoto 0:871ab6846b18 34
H_Tsunemoto 0:871ab6846b18 35 /* X and Y limits */
H_Tsunemoto 0:871ab6846b18 36 /* These values do not directly map to screen pixels */
H_Tsunemoto 0:871ab6846b18 37 /* Zero may be interpreted as meaning 'no movement' */
H_Tsunemoto 0:871ab6846b18 38 #define X_MIN_ABS (1) /*!< Minimum value on x-axis */
H_Tsunemoto 0:871ab6846b18 39 #define Y_MIN_ABS (1) /*!< Minimum value on y-axis */
H_Tsunemoto 0:871ab6846b18 40 #define X_MAX_ABS (0x7fff) /*!< Maximum value on x-axis */
H_Tsunemoto 0:871ab6846b18 41 #define Y_MAX_ABS (0x7fff) /*!< Maximum value on y-axis */
H_Tsunemoto 0:871ab6846b18 42
H_Tsunemoto 0:871ab6846b18 43 #define X_MIN_REL (-127) /*!< The maximum value that we can move to the left on the x-axis */
H_Tsunemoto 0:871ab6846b18 44 #define Y_MIN_REL (-127) /*!< The maximum value that we can move up on the y-axis */
H_Tsunemoto 0:871ab6846b18 45 #define X_MAX_REL (127) /*!< The maximum value that we can move to the right on the x-axis */
H_Tsunemoto 0:871ab6846b18 46 #define Y_MAX_REL (127) /*!< The maximum value that we can move down on the y-axis */
H_Tsunemoto 0:871ab6846b18 47
H_Tsunemoto 0:871ab6846b18 48 enum MOUSE_TYPE
H_Tsunemoto 0:871ab6846b18 49 {
H_Tsunemoto 0:871ab6846b18 50 ABS_MOUSE,
H_Tsunemoto 0:871ab6846b18 51 REL_MOUSE,
H_Tsunemoto 0:871ab6846b18 52 };
H_Tsunemoto 0:871ab6846b18 53
H_Tsunemoto 0:871ab6846b18 54 /**
H_Tsunemoto 0:871ab6846b18 55 *
H_Tsunemoto 0:871ab6846b18 56 * USBMouse example
H_Tsunemoto 0:871ab6846b18 57 * @code
H_Tsunemoto 0:871ab6846b18 58 * #include "mbed.h"
H_Tsunemoto 0:871ab6846b18 59 * #include "USBMouse.h"
H_Tsunemoto 0:871ab6846b18 60 *
H_Tsunemoto 0:871ab6846b18 61 * USBMouse mouse;
H_Tsunemoto 0:871ab6846b18 62 *
H_Tsunemoto 0:871ab6846b18 63 * int main(void)
H_Tsunemoto 0:871ab6846b18 64 * {
H_Tsunemoto 0:871ab6846b18 65 * while (1)
H_Tsunemoto 0:871ab6846b18 66 * {
H_Tsunemoto 0:871ab6846b18 67 * mouse.move(20, 0);
H_Tsunemoto 0:871ab6846b18 68 * wait(0.5);
H_Tsunemoto 0:871ab6846b18 69 * }
H_Tsunemoto 0:871ab6846b18 70 * }
H_Tsunemoto 0:871ab6846b18 71 *
H_Tsunemoto 0:871ab6846b18 72 * @endcode
H_Tsunemoto 0:871ab6846b18 73 *
H_Tsunemoto 0:871ab6846b18 74 *
H_Tsunemoto 0:871ab6846b18 75 * @code
H_Tsunemoto 0:871ab6846b18 76 * #include "mbed.h"
H_Tsunemoto 0:871ab6846b18 77 * #include "USBMouse.h"
H_Tsunemoto 0:871ab6846b18 78 * #include <math.h>
H_Tsunemoto 0:871ab6846b18 79 *
H_Tsunemoto 0:871ab6846b18 80 * USBMouse mouse(ABS_MOUSE);
H_Tsunemoto 0:871ab6846b18 81 *
H_Tsunemoto 0:871ab6846b18 82 * int main(void)
H_Tsunemoto 0:871ab6846b18 83 * {
H_Tsunemoto 0:871ab6846b18 84 * uint16_t x_center = (X_MAX_ABS - X_MIN_ABS)/2;
H_Tsunemoto 0:871ab6846b18 85 * uint16_t y_center = (Y_MAX_ABS - Y_MIN_ABS)/2;
H_Tsunemoto 0:871ab6846b18 86 * uint16_t x_screen = 0;
H_Tsunemoto 0:871ab6846b18 87 * uint16_t y_screen = 0;
H_Tsunemoto 0:871ab6846b18 88 *
H_Tsunemoto 0:871ab6846b18 89 * uint32_t x_origin = x_center;
H_Tsunemoto 0:871ab6846b18 90 * uint32_t y_origin = y_center;
H_Tsunemoto 0:871ab6846b18 91 * uint32_t radius = 5000;
H_Tsunemoto 0:871ab6846b18 92 * uint32_t angle = 0;
H_Tsunemoto 0:871ab6846b18 93 *
H_Tsunemoto 0:871ab6846b18 94 * while (1)
H_Tsunemoto 0:871ab6846b18 95 * {
H_Tsunemoto 0:871ab6846b18 96 * x_screen = x_origin + cos((double)angle*3.14/180.0)*radius;
H_Tsunemoto 0:871ab6846b18 97 * y_screen = y_origin + sin((double)angle*3.14/180.0)*radius;
H_Tsunemoto 0:871ab6846b18 98 *
H_Tsunemoto 0:871ab6846b18 99 * mouse.move(x_screen, y_screen);
H_Tsunemoto 0:871ab6846b18 100 * angle += 3;
H_Tsunemoto 0:871ab6846b18 101 * wait(0.01);
H_Tsunemoto 0:871ab6846b18 102 * }
H_Tsunemoto 0:871ab6846b18 103 * }
H_Tsunemoto 0:871ab6846b18 104 *
H_Tsunemoto 0:871ab6846b18 105 * @endcode
H_Tsunemoto 0:871ab6846b18 106 */
H_Tsunemoto 0:871ab6846b18 107 class USBMouse: public USBHID
H_Tsunemoto 0:871ab6846b18 108 {
H_Tsunemoto 0:871ab6846b18 109 public:
H_Tsunemoto 0:871ab6846b18 110
H_Tsunemoto 0:871ab6846b18 111 /**
H_Tsunemoto 0:871ab6846b18 112 * Constructor
H_Tsunemoto 0:871ab6846b18 113 *
H_Tsunemoto 0:871ab6846b18 114 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
H_Tsunemoto 0:871ab6846b18 115 * @param vendor_id Your vendor_id (default: 0x1234)
H_Tsunemoto 0:871ab6846b18 116 * @param product_id Your product_id (default: 0x0001)
H_Tsunemoto 0:871ab6846b18 117 * @param product_release Your preoduct_release (default: 0x0001)
H_Tsunemoto 0:871ab6846b18 118 *
H_Tsunemoto 0:871ab6846b18 119 */
H_Tsunemoto 0:871ab6846b18 120 USBMouse(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0001, uint16_t product_release = 0x0001):
H_Tsunemoto 0:871ab6846b18 121 USBHID(0, 0, vendor_id, product_id, product_release, false)
H_Tsunemoto 0:871ab6846b18 122 {
H_Tsunemoto 0:871ab6846b18 123 button = 0;
H_Tsunemoto 0:871ab6846b18 124 this->mouse_type = mouse_type;
H_Tsunemoto 0:871ab6846b18 125 connect();
H_Tsunemoto 0:871ab6846b18 126 };
H_Tsunemoto 0:871ab6846b18 127
H_Tsunemoto 0:871ab6846b18 128 /**
H_Tsunemoto 0:871ab6846b18 129 * Write a state of the mouse
H_Tsunemoto 0:871ab6846b18 130 *
H_Tsunemoto 0:871ab6846b18 131 * @param x x-axis position
H_Tsunemoto 0:871ab6846b18 132 * @param y y-axis position
H_Tsunemoto 0:871ab6846b18 133 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
H_Tsunemoto 0:871ab6846b18 134 * @param z wheel state (>0 to scroll down, <0 to scroll up)
H_Tsunemoto 0:871ab6846b18 135 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 136 */
H_Tsunemoto 0:871ab6846b18 137 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
H_Tsunemoto 0:871ab6846b18 138
H_Tsunemoto 0:871ab6846b18 139
H_Tsunemoto 0:871ab6846b18 140 /**
H_Tsunemoto 0:871ab6846b18 141 * Move the cursor to (x, y)
H_Tsunemoto 0:871ab6846b18 142 *
H_Tsunemoto 0:871ab6846b18 143 * @param x-axis position
H_Tsunemoto 0:871ab6846b18 144 * @param y-axis position
H_Tsunemoto 0:871ab6846b18 145 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 146 */
H_Tsunemoto 0:871ab6846b18 147 bool move(int16_t x, int16_t y);
H_Tsunemoto 0:871ab6846b18 148
H_Tsunemoto 0:871ab6846b18 149 /**
H_Tsunemoto 0:871ab6846b18 150 * Press one or several buttons
H_Tsunemoto 0:871ab6846b18 151 *
H_Tsunemoto 0:871ab6846b18 152 * @param button button state (ex: press(MOUSE_LEFT))
H_Tsunemoto 0:871ab6846b18 153 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 154 */
H_Tsunemoto 0:871ab6846b18 155 bool press(uint8_t button);
H_Tsunemoto 0:871ab6846b18 156
H_Tsunemoto 0:871ab6846b18 157 /**
H_Tsunemoto 0:871ab6846b18 158 * Release one or several buttons
H_Tsunemoto 0:871ab6846b18 159 *
H_Tsunemoto 0:871ab6846b18 160 * @param button button state (ex: release(MOUSE_LEFT))
H_Tsunemoto 0:871ab6846b18 161 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 162 */
H_Tsunemoto 0:871ab6846b18 163 bool release(uint8_t button);
H_Tsunemoto 0:871ab6846b18 164
H_Tsunemoto 0:871ab6846b18 165 /**
H_Tsunemoto 0:871ab6846b18 166 * Double click (MOUSE_LEFT)
H_Tsunemoto 0:871ab6846b18 167 *
H_Tsunemoto 0:871ab6846b18 168 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 169 */
H_Tsunemoto 0:871ab6846b18 170 bool doubleClick();
H_Tsunemoto 0:871ab6846b18 171
H_Tsunemoto 0:871ab6846b18 172 /**
H_Tsunemoto 0:871ab6846b18 173 * Click
H_Tsunemoto 0:871ab6846b18 174 *
H_Tsunemoto 0:871ab6846b18 175 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
H_Tsunemoto 0:871ab6846b18 176 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 177 */
H_Tsunemoto 0:871ab6846b18 178 bool click(uint8_t button);
H_Tsunemoto 0:871ab6846b18 179
H_Tsunemoto 0:871ab6846b18 180 /**
H_Tsunemoto 0:871ab6846b18 181 * Scrolling
H_Tsunemoto 0:871ab6846b18 182 *
H_Tsunemoto 0:871ab6846b18 183 * @param z value of the wheel (>0 to go down, <0 to go up)
H_Tsunemoto 0:871ab6846b18 184 * @returns true if there is no error, false otherwise
H_Tsunemoto 0:871ab6846b18 185 */
H_Tsunemoto 0:871ab6846b18 186 bool scroll(int8_t z);
H_Tsunemoto 0:871ab6846b18 187
H_Tsunemoto 0:871ab6846b18 188 /*
H_Tsunemoto 0:871ab6846b18 189 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
H_Tsunemoto 0:871ab6846b18 190 *
H_Tsunemoto 0:871ab6846b18 191 * @returns pointer to the report descriptor
H_Tsunemoto 0:871ab6846b18 192 */
H_Tsunemoto 0:871ab6846b18 193 virtual uint8_t * reportDesc();
H_Tsunemoto 0:871ab6846b18 194
H_Tsunemoto 0:871ab6846b18 195 protected:
H_Tsunemoto 0:871ab6846b18 196 /*
H_Tsunemoto 0:871ab6846b18 197 * Get configuration descriptor
H_Tsunemoto 0:871ab6846b18 198 *
H_Tsunemoto 0:871ab6846b18 199 * @returns pointer to the configuration descriptor
H_Tsunemoto 0:871ab6846b18 200 */
H_Tsunemoto 0:871ab6846b18 201 virtual uint8_t * configurationDesc();
H_Tsunemoto 0:871ab6846b18 202
H_Tsunemoto 0:871ab6846b18 203 private:
H_Tsunemoto 0:871ab6846b18 204 MOUSE_TYPE mouse_type;
H_Tsunemoto 0:871ab6846b18 205 uint8_t button;
H_Tsunemoto 0:871ab6846b18 206 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
H_Tsunemoto 0:871ab6846b18 207 };
H_Tsunemoto 0:871ab6846b18 208
H_Tsunemoto 0:871ab6846b18 209 #endif