Lucas Lim / Mbed 2 deprecated HSP_Temperature_Barometer_CS3237

Dependencies:   mbed

Committer:
lucaslwl
Date:
Mon Aug 26 08:11:41 2019 +0000
Revision:
22:5c07298d3383
add library folder

Who changed what in which revision?

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