This is a data logger program to be implemented with an instrument amplifier.

Dependencies:   mbed

Committer:
KISScientific
Date:
Tue Apr 04 18:01:11 2017 +0000
Revision:
0:d75ca4e39672
This is a data logger program.

Who changed what in which revision?

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