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 USBMOUSEKEYBOARD_H
lucaslwl 22:5c07298d3383 20 #define USBMOUSEKEYBOARD_H
lucaslwl 22:5c07298d3383 21
lucaslwl 22:5c07298d3383 22 #define REPORT_ID_KEYBOARD 1
lucaslwl 22:5c07298d3383 23 #define REPORT_ID_MOUSE 2
lucaslwl 22:5c07298d3383 24 #define REPORT_ID_VOLUME 3
lucaslwl 22:5c07298d3383 25
lucaslwl 22:5c07298d3383 26 #include "USBMouse.h"
lucaslwl 22:5c07298d3383 27 #include "USBKeyboard.h"
lucaslwl 22:5c07298d3383 28 #include "Stream.h"
lucaslwl 22:5c07298d3383 29 #include "USBHID.h"
lucaslwl 22:5c07298d3383 30
lucaslwl 22:5c07298d3383 31 /**
lucaslwl 22:5c07298d3383 32 * USBMouseKeyboard example
lucaslwl 22:5c07298d3383 33 * @code
lucaslwl 22:5c07298d3383 34 *
lucaslwl 22:5c07298d3383 35 * #include "mbed.h"
lucaslwl 22:5c07298d3383 36 * #include "USBMouseKeyboard.h"
lucaslwl 22:5c07298d3383 37 *
lucaslwl 22:5c07298d3383 38 * USBMouseKeyboard key_mouse;
lucaslwl 22:5c07298d3383 39 *
lucaslwl 22:5c07298d3383 40 * int main(void)
lucaslwl 22:5c07298d3383 41 * {
lucaslwl 22:5c07298d3383 42 * while(1)
lucaslwl 22:5c07298d3383 43 * {
lucaslwl 22:5c07298d3383 44 * key_mouse.move(20, 0);
lucaslwl 22:5c07298d3383 45 * key_mouse.printf("Hello From MBED\r\n");
lucaslwl 22:5c07298d3383 46 * wait(1);
lucaslwl 22:5c07298d3383 47 * }
lucaslwl 22:5c07298d3383 48 * }
lucaslwl 22:5c07298d3383 49 * @endcode
lucaslwl 22:5c07298d3383 50 *
lucaslwl 22:5c07298d3383 51 *
lucaslwl 22:5c07298d3383 52 * @code
lucaslwl 22:5c07298d3383 53 *
lucaslwl 22:5c07298d3383 54 * #include "mbed.h"
lucaslwl 22:5c07298d3383 55 * #include "USBMouseKeyboard.h"
lucaslwl 22:5c07298d3383 56 *
lucaslwl 22:5c07298d3383 57 * USBMouseKeyboard key_mouse(ABS_MOUSE);
lucaslwl 22:5c07298d3383 58 *
lucaslwl 22:5c07298d3383 59 * int main(void)
lucaslwl 22:5c07298d3383 60 * {
lucaslwl 22:5c07298d3383 61 * while(1)
lucaslwl 22:5c07298d3383 62 * {
lucaslwl 22:5c07298d3383 63 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
lucaslwl 22:5c07298d3383 64 * key_mouse.printf("Hello from MBED\r\n");
lucaslwl 22:5c07298d3383 65 * wait(1);
lucaslwl 22:5c07298d3383 66 * }
lucaslwl 22:5c07298d3383 67 * }
lucaslwl 22:5c07298d3383 68 * @endcode
lucaslwl 22:5c07298d3383 69 */
lucaslwl 22:5c07298d3383 70 class USBMouseKeyboard: public USBHID, public Stream
lucaslwl 22:5c07298d3383 71 {
lucaslwl 22:5c07298d3383 72 public:
lucaslwl 22:5c07298d3383 73
lucaslwl 22:5c07298d3383 74 /**
lucaslwl 22:5c07298d3383 75 * Constructor
lucaslwl 22:5c07298d3383 76 *
lucaslwl 22:5c07298d3383 77 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
lucaslwl 22:5c07298d3383 78 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
lucaslwl 22:5c07298d3383 79 * @param vendor_id Your vendor_id (default: 0x1234)
lucaslwl 22:5c07298d3383 80 * @param product_id Your product_id (default: 0x0001)
lucaslwl 22:5c07298d3383 81 * @param product_release Your preoduct_release (default: 0x0001)
lucaslwl 22:5c07298d3383 82 *
lucaslwl 22:5c07298d3383 83 */
lucaslwl 22:5c07298d3383 84 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001):
lucaslwl 22:5c07298d3383 85 USBHID(0, 0, vendor_id, product_id, product_release, false)
lucaslwl 22:5c07298d3383 86 {
lucaslwl 22:5c07298d3383 87 lock_status = 0;
lucaslwl 22:5c07298d3383 88 button = 0;
lucaslwl 22:5c07298d3383 89 this->mouse_type = mouse_type;
lucaslwl 22:5c07298d3383 90 connect();
lucaslwl 22:5c07298d3383 91 };
lucaslwl 22:5c07298d3383 92
lucaslwl 22:5c07298d3383 93 /**
lucaslwl 22:5c07298d3383 94 * Write a state of the mouse
lucaslwl 22:5c07298d3383 95 *
lucaslwl 22:5c07298d3383 96 * @param x x-axis position
lucaslwl 22:5c07298d3383 97 * @param y y-axis position
lucaslwl 22:5c07298d3383 98 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
lucaslwl 22:5c07298d3383 99 * @param z wheel state (>0 to scroll down, <0 to scroll up)
lucaslwl 22:5c07298d3383 100 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 101 */
lucaslwl 22:5c07298d3383 102 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
lucaslwl 22:5c07298d3383 103
lucaslwl 22:5c07298d3383 104
lucaslwl 22:5c07298d3383 105 /**
lucaslwl 22:5c07298d3383 106 * Move the cursor to (x, y)
lucaslwl 22:5c07298d3383 107 *
lucaslwl 22:5c07298d3383 108 * @param x x-axis position
lucaslwl 22:5c07298d3383 109 * @param y y-axis position
lucaslwl 22:5c07298d3383 110 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 111 */
lucaslwl 22:5c07298d3383 112 bool move(int16_t x, int16_t y);
lucaslwl 22:5c07298d3383 113
lucaslwl 22:5c07298d3383 114 /**
lucaslwl 22:5c07298d3383 115 * Press one or several buttons
lucaslwl 22:5c07298d3383 116 *
lucaslwl 22:5c07298d3383 117 * @param button button state (ex: press(MOUSE_LEFT))
lucaslwl 22:5c07298d3383 118 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 119 */
lucaslwl 22:5c07298d3383 120 bool press(uint8_t button);
lucaslwl 22:5c07298d3383 121
lucaslwl 22:5c07298d3383 122 /**
lucaslwl 22:5c07298d3383 123 * Release one or several buttons
lucaslwl 22:5c07298d3383 124 *
lucaslwl 22:5c07298d3383 125 * @param button button state (ex: release(MOUSE_LEFT))
lucaslwl 22:5c07298d3383 126 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 127 */
lucaslwl 22:5c07298d3383 128 bool release(uint8_t button);
lucaslwl 22:5c07298d3383 129
lucaslwl 22:5c07298d3383 130 /**
lucaslwl 22:5c07298d3383 131 * Double click (MOUSE_LEFT)
lucaslwl 22:5c07298d3383 132 *
lucaslwl 22:5c07298d3383 133 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 134 */
lucaslwl 22:5c07298d3383 135 bool doubleClick();
lucaslwl 22:5c07298d3383 136
lucaslwl 22:5c07298d3383 137 /**
lucaslwl 22:5c07298d3383 138 * Click
lucaslwl 22:5c07298d3383 139 *
lucaslwl 22:5c07298d3383 140 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
lucaslwl 22:5c07298d3383 141 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 142 */
lucaslwl 22:5c07298d3383 143 bool click(uint8_t button);
lucaslwl 22:5c07298d3383 144
lucaslwl 22:5c07298d3383 145 /**
lucaslwl 22:5c07298d3383 146 * Scrolling
lucaslwl 22:5c07298d3383 147 *
lucaslwl 22:5c07298d3383 148 * @param z value of the wheel (>0 to go down, <0 to go up)
lucaslwl 22:5c07298d3383 149 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 150 */
lucaslwl 22:5c07298d3383 151 bool scroll(int8_t z);
lucaslwl 22:5c07298d3383 152
lucaslwl 22:5c07298d3383 153 /**
lucaslwl 22:5c07298d3383 154 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
lucaslwl 22:5c07298d3383 155 *
lucaslwl 22:5c07298d3383 156 * @code
lucaslwl 22:5c07298d3383 157 * //To send CTRL + s (save)
lucaslwl 22:5c07298d3383 158 * keyboard.keyCode('s', KEY_CTRL);
lucaslwl 22:5c07298d3383 159 * @endcode
lucaslwl 22:5c07298d3383 160 *
lucaslwl 22:5c07298d3383 161 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
lucaslwl 22:5c07298d3383 162 * @param key character to send
lucaslwl 22:5c07298d3383 163 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 164 */
lucaslwl 22:5c07298d3383 165 bool keyCode(uint8_t key, uint8_t modifier = 0);
lucaslwl 22:5c07298d3383 166
lucaslwl 22:5c07298d3383 167 /**
lucaslwl 22:5c07298d3383 168 * Send a character
lucaslwl 22:5c07298d3383 169 *
lucaslwl 22:5c07298d3383 170 * @param c character to be sent
lucaslwl 22:5c07298d3383 171 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 172 */
lucaslwl 22:5c07298d3383 173 virtual int _putc(int c);
lucaslwl 22:5c07298d3383 174
lucaslwl 22:5c07298d3383 175 /**
lucaslwl 22:5c07298d3383 176 * Control media keys
lucaslwl 22:5c07298d3383 177 *
lucaslwl 22:5c07298d3383 178 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
lucaslwl 22:5c07298d3383 179 * @returns true if there is no error, false otherwise
lucaslwl 22:5c07298d3383 180 */
lucaslwl 22:5c07298d3383 181 bool mediaControl(MEDIA_KEY key);
lucaslwl 22:5c07298d3383 182
lucaslwl 22:5c07298d3383 183 /**
lucaslwl 22:5c07298d3383 184 * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:
lucaslwl 22:5c07298d3383 185 * - First bit: NUM_LOCK
lucaslwl 22:5c07298d3383 186 * - Second bit: CAPS_LOCK
lucaslwl 22:5c07298d3383 187 * - Third bit: SCROLL_LOCK
lucaslwl 22:5c07298d3383 188 *
lucaslwl 22:5c07298d3383 189 * @returns status of lock keys
lucaslwl 22:5c07298d3383 190 */
lucaslwl 22:5c07298d3383 191 uint8_t lockStatus();
lucaslwl 22:5c07298d3383 192
lucaslwl 22:5c07298d3383 193 /*
lucaslwl 22:5c07298d3383 194 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
lucaslwl 22:5c07298d3383 195 *
lucaslwl 22:5c07298d3383 196 * @returns pointer to the report descriptor
lucaslwl 22:5c07298d3383 197 */
lucaslwl 22:5c07298d3383 198 virtual uint8_t * reportDesc();
lucaslwl 22:5c07298d3383 199
lucaslwl 22:5c07298d3383 200 /*
lucaslwl 22:5c07298d3383 201 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
lucaslwl 22:5c07298d3383 202 *
lucaslwl 22:5c07298d3383 203 * @returns if handle by subclass, return true
lucaslwl 22:5c07298d3383 204 */
lucaslwl 22:5c07298d3383 205 virtual bool EPINT_OUT_callback();
lucaslwl 22:5c07298d3383 206
lucaslwl 22:5c07298d3383 207
lucaslwl 22:5c07298d3383 208 private:
lucaslwl 22:5c07298d3383 209 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z);
lucaslwl 22:5c07298d3383 210 MOUSE_TYPE mouse_type;
lucaslwl 22:5c07298d3383 211 uint8_t button;
lucaslwl 22:5c07298d3383 212 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
lucaslwl 22:5c07298d3383 213
lucaslwl 22:5c07298d3383 214 uint8_t lock_status;
lucaslwl 22:5c07298d3383 215
lucaslwl 22:5c07298d3383 216 //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
lucaslwl 22:5c07298d3383 217 virtual int _getc() { return -1;}
lucaslwl 22:5c07298d3383 218 };
lucaslwl 22:5c07298d3383 219
lucaslwl 22:5c07298d3383 220 #endif