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 USBKEYBOARD_H
KISScientific 0:d75ca4e39672 20 #define USBKEYBOARD_H
KISScientific 0:d75ca4e39672 21
KISScientific 0:d75ca4e39672 22 #include "USBHID.h"
KISScientific 0:d75ca4e39672 23 #include "Stream.h"
KISScientific 0:d75ca4e39672 24
KISScientific 0:d75ca4e39672 25 /* Modifiers */
KISScientific 0:d75ca4e39672 26 enum MODIFIER_KEY {
KISScientific 0:d75ca4e39672 27 KEY_CTRL = 1,
KISScientific 0:d75ca4e39672 28 KEY_SHIFT = 2,
KISScientific 0:d75ca4e39672 29 KEY_ALT = 4,
KISScientific 0:d75ca4e39672 30 };
KISScientific 0:d75ca4e39672 31
KISScientific 0:d75ca4e39672 32
KISScientific 0:d75ca4e39672 33 enum MEDIA_KEY {
KISScientific 0:d75ca4e39672 34 KEY_NEXT_TRACK, /*!< next Track Button */
KISScientific 0:d75ca4e39672 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
KISScientific 0:d75ca4e39672 36 KEY_STOP, /*!< Stop Button */
KISScientific 0:d75ca4e39672 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
KISScientific 0:d75ca4e39672 38 KEY_MUTE, /*!< Mute Button */
KISScientific 0:d75ca4e39672 39 KEY_VOLUME_UP, /*!< Volume Up Button */
KISScientific 0:d75ca4e39672 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
KISScientific 0:d75ca4e39672 41 };
KISScientific 0:d75ca4e39672 42
KISScientific 0:d75ca4e39672 43 enum FUNCTION_KEY {
KISScientific 0:d75ca4e39672 44 KEY_F1 = 128, /* F1 key */
KISScientific 0:d75ca4e39672 45 KEY_F2, /* F2 key */
KISScientific 0:d75ca4e39672 46 KEY_F3, /* F3 key */
KISScientific 0:d75ca4e39672 47 KEY_F4, /* F4 key */
KISScientific 0:d75ca4e39672 48 KEY_F5, /* F5 key */
KISScientific 0:d75ca4e39672 49 KEY_F6, /* F6 key */
KISScientific 0:d75ca4e39672 50 KEY_F7, /* F7 key */
KISScientific 0:d75ca4e39672 51 KEY_F8, /* F8 key */
KISScientific 0:d75ca4e39672 52 KEY_F9, /* F9 key */
KISScientific 0:d75ca4e39672 53 KEY_F10, /* F10 key */
KISScientific 0:d75ca4e39672 54 KEY_F11, /* F11 key */
KISScientific 0:d75ca4e39672 55 KEY_F12, /* F12 key */
KISScientific 0:d75ca4e39672 56
KISScientific 0:d75ca4e39672 57 KEY_PRINT_SCREEN, /* Print Screen key */
KISScientific 0:d75ca4e39672 58 KEY_SCROLL_LOCK, /* Scroll lock */
KISScientific 0:d75ca4e39672 59 KEY_CAPS_LOCK, /* caps lock */
KISScientific 0:d75ca4e39672 60 KEY_NUM_LOCK, /* num lock */
KISScientific 0:d75ca4e39672 61 KEY_INSERT, /* Insert key */
KISScientific 0:d75ca4e39672 62 KEY_HOME, /* Home key */
KISScientific 0:d75ca4e39672 63 KEY_PAGE_UP, /* Page Up key */
KISScientific 0:d75ca4e39672 64 KEY_PAGE_DOWN, /* Page Down key */
KISScientific 0:d75ca4e39672 65
KISScientific 0:d75ca4e39672 66 RIGHT_ARROW, /* Right arrow */
KISScientific 0:d75ca4e39672 67 LEFT_ARROW, /* Left arrow */
KISScientific 0:d75ca4e39672 68 DOWN_ARROW, /* Down arrow */
KISScientific 0:d75ca4e39672 69 UP_ARROW, /* Up arrow */
KISScientific 0:d75ca4e39672 70 };
KISScientific 0:d75ca4e39672 71
KISScientific 0:d75ca4e39672 72 /**
KISScientific 0:d75ca4e39672 73 * USBKeyboard example
KISScientific 0:d75ca4e39672 74 * @code
KISScientific 0:d75ca4e39672 75 *
KISScientific 0:d75ca4e39672 76 * #include "mbed.h"
KISScientific 0:d75ca4e39672 77 * #include "USBKeyboard.h"
KISScientific 0:d75ca4e39672 78 *
KISScientific 0:d75ca4e39672 79 * USBKeyboard key;
KISScientific 0:d75ca4e39672 80 *
KISScientific 0:d75ca4e39672 81 * int main(void)
KISScientific 0:d75ca4e39672 82 * {
KISScientific 0:d75ca4e39672 83 * while (1)
KISScientific 0:d75ca4e39672 84 * {
KISScientific 0:d75ca4e39672 85 * key.printf("Hello World\r\n");
KISScientific 0:d75ca4e39672 86 * wait(1);
KISScientific 0:d75ca4e39672 87 * }
KISScientific 0:d75ca4e39672 88 * }
KISScientific 0:d75ca4e39672 89 *
KISScientific 0:d75ca4e39672 90 * @endcode
KISScientific 0:d75ca4e39672 91 */
KISScientific 0:d75ca4e39672 92 class USBKeyboard: public USBHID, public Stream {
KISScientific 0:d75ca4e39672 93 public:
KISScientific 0:d75ca4e39672 94
KISScientific 0:d75ca4e39672 95 /**
KISScientific 0:d75ca4e39672 96 * Constructor
KISScientific 0:d75ca4e39672 97 *
KISScientific 0:d75ca4e39672 98 *
KISScientific 0:d75ca4e39672 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
KISScientific 0:d75ca4e39672 100 * @param vendor_id Your vendor_id (default: 0x1235)
KISScientific 0:d75ca4e39672 101 * @param product_id Your product_id (default: 0x0050)
KISScientific 0:d75ca4e39672 102 * @param product_release Your preoduct_release (default: 0x0001)
KISScientific 0:d75ca4e39672 103 *
KISScientific 0:d75ca4e39672 104 */
KISScientific 0:d75ca4e39672 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
KISScientific 0:d75ca4e39672 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
KISScientific 0:d75ca4e39672 107 lock_status = 0;
KISScientific 0:d75ca4e39672 108 connect();
KISScientific 0:d75ca4e39672 109 };
KISScientific 0:d75ca4e39672 110
KISScientific 0:d75ca4e39672 111 /**
KISScientific 0:d75ca4e39672 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
KISScientific 0:d75ca4e39672 113 *
KISScientific 0:d75ca4e39672 114 * @code
KISScientific 0:d75ca4e39672 115 * //To send CTRL + s (save)
KISScientific 0:d75ca4e39672 116 * keyboard.keyCode('s', KEY_CTRL);
KISScientific 0:d75ca4e39672 117 * @endcode
KISScientific 0:d75ca4e39672 118 *
KISScientific 0:d75ca4e39672 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
KISScientific 0:d75ca4e39672 120 * @param key character to send
KISScientific 0:d75ca4e39672 121 * @returns true if there is no error, false otherwise
KISScientific 0:d75ca4e39672 122 */
KISScientific 0:d75ca4e39672 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
KISScientific 0:d75ca4e39672 124
KISScientific 0:d75ca4e39672 125 /**
KISScientific 0:d75ca4e39672 126 * Send a character
KISScientific 0:d75ca4e39672 127 *
KISScientific 0:d75ca4e39672 128 * @param c character to be sent
KISScientific 0:d75ca4e39672 129 * @returns true if there is no error, false otherwise
KISScientific 0:d75ca4e39672 130 */
KISScientific 0:d75ca4e39672 131 virtual int _putc(int c);
KISScientific 0:d75ca4e39672 132
KISScientific 0:d75ca4e39672 133 /**
KISScientific 0:d75ca4e39672 134 * Control media keys
KISScientific 0:d75ca4e39672 135 *
KISScientific 0:d75ca4e39672 136 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
KISScientific 0:d75ca4e39672 137 * @returns true if there is no error, false otherwise
KISScientific 0:d75ca4e39672 138 */
KISScientific 0:d75ca4e39672 139 bool mediaControl(MEDIA_KEY key);
KISScientific 0:d75ca4e39672 140
KISScientific 0:d75ca4e39672 141 /*
KISScientific 0:d75ca4e39672 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
KISScientific 0:d75ca4e39672 143 *
KISScientific 0:d75ca4e39672 144 * @returns pointer to the report descriptor
KISScientific 0:d75ca4e39672 145 */
KISScientific 0:d75ca4e39672 146 virtual uint8_t * reportDesc();
KISScientific 0:d75ca4e39672 147
KISScientific 0:d75ca4e39672 148 /*
KISScientific 0:d75ca4e39672 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
KISScientific 0:d75ca4e39672 150 *
KISScientific 0:d75ca4e39672 151 * @returns if handle by subclass, return true
KISScientific 0:d75ca4e39672 152 */
KISScientific 0:d75ca4e39672 153 virtual bool EP1_OUT_callback();
KISScientific 0:d75ca4e39672 154
KISScientific 0:d75ca4e39672 155 /**
KISScientific 0:d75ca4e39672 156 * 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:
KISScientific 0:d75ca4e39672 157 * - First bit: NUM_LOCK
KISScientific 0:d75ca4e39672 158 * - Second bit: CAPS_LOCK
KISScientific 0:d75ca4e39672 159 * - Third bit: SCROLL_LOCK
KISScientific 0:d75ca4e39672 160 *
KISScientific 0:d75ca4e39672 161 * @returns status of lock keys
KISScientific 0:d75ca4e39672 162 */
KISScientific 0:d75ca4e39672 163 uint8_t lockStatus();
KISScientific 0:d75ca4e39672 164
KISScientific 0:d75ca4e39672 165 protected:
KISScientific 0:d75ca4e39672 166 /*
KISScientific 0:d75ca4e39672 167 * Get configuration descriptor
KISScientific 0:d75ca4e39672 168 *
KISScientific 0:d75ca4e39672 169 * @returns pointer to the configuration descriptor
KISScientific 0:d75ca4e39672 170 */
KISScientific 0:d75ca4e39672 171 virtual uint8_t * configurationDesc();
KISScientific 0:d75ca4e39672 172
KISScientific 0:d75ca4e39672 173 private:
KISScientific 0:d75ca4e39672 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
KISScientific 0:d75ca4e39672 175 virtual int _getc() {
KISScientific 0:d75ca4e39672 176 return -1;
KISScientific 0:d75ca4e39672 177 };
KISScientific 0:d75ca4e39672 178
KISScientific 0:d75ca4e39672 179 uint8_t lock_status;
KISScientific 0:d75ca4e39672 180
KISScientific 0:d75ca4e39672 181 };
KISScientific 0:d75ca4e39672 182
KISScientific 0:d75ca4e39672 183 #endif