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