Kalibriersoftware Stromwerte

Dependencies:   Matrix mbed

Committer:
Racer01014
Date:
Mon Nov 23 16:09:54 2015 +0000
Revision:
0:5e35c180ed4a
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Racer01014 0:5e35c180ed4a 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Racer01014 0:5e35c180ed4a 2 *
Racer01014 0:5e35c180ed4a 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Racer01014 0:5e35c180ed4a 4 * and associated documentation files (the "Software"), to deal in the Software without
Racer01014 0:5e35c180ed4a 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Racer01014 0:5e35c180ed4a 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Racer01014 0:5e35c180ed4a 7 * Software is furnished to do so, subject to the following conditions:
Racer01014 0:5e35c180ed4a 8 *
Racer01014 0:5e35c180ed4a 9 * The above copyright notice and this permission notice shall be included in all copies or
Racer01014 0:5e35c180ed4a 10 * substantial portions of the Software.
Racer01014 0:5e35c180ed4a 11 *
Racer01014 0:5e35c180ed4a 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Racer01014 0:5e35c180ed4a 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Racer01014 0:5e35c180ed4a 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Racer01014 0:5e35c180ed4a 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Racer01014 0:5e35c180ed4a 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Racer01014 0:5e35c180ed4a 17 */
Racer01014 0:5e35c180ed4a 18
Racer01014 0:5e35c180ed4a 19 #ifndef USBKEYBOARD_H
Racer01014 0:5e35c180ed4a 20 #define USBKEYBOARD_H
Racer01014 0:5e35c180ed4a 21
Racer01014 0:5e35c180ed4a 22 #include "USBHID.h"
Racer01014 0:5e35c180ed4a 23 #include "Stream.h"
Racer01014 0:5e35c180ed4a 24
Racer01014 0:5e35c180ed4a 25 /* Modifiers */
Racer01014 0:5e35c180ed4a 26 enum MODIFIER_KEY {
Racer01014 0:5e35c180ed4a 27 KEY_CTRL = 1,
Racer01014 0:5e35c180ed4a 28 KEY_SHIFT = 2,
Racer01014 0:5e35c180ed4a 29 KEY_ALT = 4,
Racer01014 0:5e35c180ed4a 30 };
Racer01014 0:5e35c180ed4a 31
Racer01014 0:5e35c180ed4a 32
Racer01014 0:5e35c180ed4a 33 enum MEDIA_KEY {
Racer01014 0:5e35c180ed4a 34 KEY_NEXT_TRACK, /*!< next Track Button */
Racer01014 0:5e35c180ed4a 35 KEY_PREVIOUS_TRACK, /*!< Previous track Button */
Racer01014 0:5e35c180ed4a 36 KEY_STOP, /*!< Stop Button */
Racer01014 0:5e35c180ed4a 37 KEY_PLAY_PAUSE, /*!< Play/Pause Button */
Racer01014 0:5e35c180ed4a 38 KEY_MUTE, /*!< Mute Button */
Racer01014 0:5e35c180ed4a 39 KEY_VOLUME_UP, /*!< Volume Up Button */
Racer01014 0:5e35c180ed4a 40 KEY_VOLUME_DOWN, /*!< Volume Down Button */
Racer01014 0:5e35c180ed4a 41 };
Racer01014 0:5e35c180ed4a 42
Racer01014 0:5e35c180ed4a 43 enum FUNCTION_KEY {
Racer01014 0:5e35c180ed4a 44 KEY_F1 = 128, /* F1 key */
Racer01014 0:5e35c180ed4a 45 KEY_F2, /* F2 key */
Racer01014 0:5e35c180ed4a 46 KEY_F3, /* F3 key */
Racer01014 0:5e35c180ed4a 47 KEY_F4, /* F4 key */
Racer01014 0:5e35c180ed4a 48 KEY_F5, /* F5 key */
Racer01014 0:5e35c180ed4a 49 KEY_F6, /* F6 key */
Racer01014 0:5e35c180ed4a 50 KEY_F7, /* F7 key */
Racer01014 0:5e35c180ed4a 51 KEY_F8, /* F8 key */
Racer01014 0:5e35c180ed4a 52 KEY_F9, /* F9 key */
Racer01014 0:5e35c180ed4a 53 KEY_F10, /* F10 key */
Racer01014 0:5e35c180ed4a 54 KEY_F11, /* F11 key */
Racer01014 0:5e35c180ed4a 55 KEY_F12, /* F12 key */
Racer01014 0:5e35c180ed4a 56
Racer01014 0:5e35c180ed4a 57 KEY_PRINT_SCREEN, /* Print Screen key */
Racer01014 0:5e35c180ed4a 58 KEY_SCROLL_LOCK, /* Scroll lock */
Racer01014 0:5e35c180ed4a 59 KEY_CAPS_LOCK, /* caps lock */
Racer01014 0:5e35c180ed4a 60 KEY_NUM_LOCK, /* num lock */
Racer01014 0:5e35c180ed4a 61 KEY_INSERT, /* Insert key */
Racer01014 0:5e35c180ed4a 62 KEY_HOME, /* Home key */
Racer01014 0:5e35c180ed4a 63 KEY_PAGE_UP, /* Page Up key */
Racer01014 0:5e35c180ed4a 64 KEY_PAGE_DOWN, /* Page Down key */
Racer01014 0:5e35c180ed4a 65
Racer01014 0:5e35c180ed4a 66 RIGHT_ARROW, /* Right arrow */
Racer01014 0:5e35c180ed4a 67 LEFT_ARROW, /* Left arrow */
Racer01014 0:5e35c180ed4a 68 DOWN_ARROW, /* Down arrow */
Racer01014 0:5e35c180ed4a 69 UP_ARROW, /* Up arrow */
Racer01014 0:5e35c180ed4a 70 };
Racer01014 0:5e35c180ed4a 71
Racer01014 0:5e35c180ed4a 72 /**
Racer01014 0:5e35c180ed4a 73 * USBKeyboard example
Racer01014 0:5e35c180ed4a 74 * @code
Racer01014 0:5e35c180ed4a 75 *
Racer01014 0:5e35c180ed4a 76 * #include "mbed.h"
Racer01014 0:5e35c180ed4a 77 * #include "USBKeyboard.h"
Racer01014 0:5e35c180ed4a 78 *
Racer01014 0:5e35c180ed4a 79 * USBKeyboard key;
Racer01014 0:5e35c180ed4a 80 *
Racer01014 0:5e35c180ed4a 81 * int main(void)
Racer01014 0:5e35c180ed4a 82 * {
Racer01014 0:5e35c180ed4a 83 * while (1)
Racer01014 0:5e35c180ed4a 84 * {
Racer01014 0:5e35c180ed4a 85 * key.printf("Hello World\r\n");
Racer01014 0:5e35c180ed4a 86 * wait(1);
Racer01014 0:5e35c180ed4a 87 * }
Racer01014 0:5e35c180ed4a 88 * }
Racer01014 0:5e35c180ed4a 89 *
Racer01014 0:5e35c180ed4a 90 * @endcode
Racer01014 0:5e35c180ed4a 91 */
Racer01014 0:5e35c180ed4a 92 class USBKeyboard: public USBHID, public Stream {
Racer01014 0:5e35c180ed4a 93 public:
Racer01014 0:5e35c180ed4a 94
Racer01014 0:5e35c180ed4a 95 /**
Racer01014 0:5e35c180ed4a 96 * Constructor
Racer01014 0:5e35c180ed4a 97 *
Racer01014 0:5e35c180ed4a 98 *
Racer01014 0:5e35c180ed4a 99 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
Racer01014 0:5e35c180ed4a 100 * @param vendor_id Your vendor_id (default: 0x1235)
Racer01014 0:5e35c180ed4a 101 * @param product_id Your product_id (default: 0x0050)
Racer01014 0:5e35c180ed4a 102 * @param product_release Your preoduct_release (default: 0x0001)
Racer01014 0:5e35c180ed4a 103 *
Racer01014 0:5e35c180ed4a 104 */
Racer01014 0:5e35c180ed4a 105 USBKeyboard(uint16_t vendor_id = 0x1235, uint16_t product_id = 0x0050, uint16_t product_release = 0x0001):
Racer01014 0:5e35c180ed4a 106 USBHID(0, 0, vendor_id, product_id, product_release, false) {
Racer01014 0:5e35c180ed4a 107 lock_status = 0;
Racer01014 0:5e35c180ed4a 108 connect();
Racer01014 0:5e35c180ed4a 109 };
Racer01014 0:5e35c180ed4a 110
Racer01014 0:5e35c180ed4a 111 /**
Racer01014 0:5e35c180ed4a 112 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
Racer01014 0:5e35c180ed4a 113 *
Racer01014 0:5e35c180ed4a 114 * @code
Racer01014 0:5e35c180ed4a 115 * //To send CTRL + s (save)
Racer01014 0:5e35c180ed4a 116 * keyboard.keyCode('s', KEY_CTRL);
Racer01014 0:5e35c180ed4a 117 * @endcode
Racer01014 0:5e35c180ed4a 118 *
Racer01014 0:5e35c180ed4a 119 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
Racer01014 0:5e35c180ed4a 120 * @param key character to send
Racer01014 0:5e35c180ed4a 121 * @returns true if there is no error, false otherwise
Racer01014 0:5e35c180ed4a 122 */
Racer01014 0:5e35c180ed4a 123 bool keyCode(uint8_t key, uint8_t modifier = 0);
Racer01014 0:5e35c180ed4a 124
Racer01014 0:5e35c180ed4a 125 /**
Racer01014 0:5e35c180ed4a 126 * Send a character
Racer01014 0:5e35c180ed4a 127 *
Racer01014 0:5e35c180ed4a 128 * @param c character to be sent
Racer01014 0:5e35c180ed4a 129 * @returns true if there is no error, false otherwise
Racer01014 0:5e35c180ed4a 130 */
Racer01014 0:5e35c180ed4a 131 virtual int _putc(int c);
Racer01014 0:5e35c180ed4a 132
Racer01014 0:5e35c180ed4a 133 /**
Racer01014 0:5e35c180ed4a 134 * Control media keys
Racer01014 0:5e35c180ed4a 135 *
Racer01014 0:5e35c180ed4a 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)
Racer01014 0:5e35c180ed4a 137 * @returns true if there is no error, false otherwise
Racer01014 0:5e35c180ed4a 138 */
Racer01014 0:5e35c180ed4a 139 bool mediaControl(MEDIA_KEY key);
Racer01014 0:5e35c180ed4a 140
Racer01014 0:5e35c180ed4a 141 /*
Racer01014 0:5e35c180ed4a 142 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
Racer01014 0:5e35c180ed4a 143 *
Racer01014 0:5e35c180ed4a 144 * @returns pointer to the report descriptor
Racer01014 0:5e35c180ed4a 145 */
Racer01014 0:5e35c180ed4a 146 virtual uint8_t * reportDesc();
Racer01014 0:5e35c180ed4a 147
Racer01014 0:5e35c180ed4a 148 /*
Racer01014 0:5e35c180ed4a 149 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
Racer01014 0:5e35c180ed4a 150 *
Racer01014 0:5e35c180ed4a 151 * @returns if handle by subclass, return true
Racer01014 0:5e35c180ed4a 152 */
Racer01014 0:5e35c180ed4a 153 virtual bool EP1_OUT_callback();
Racer01014 0:5e35c180ed4a 154
Racer01014 0:5e35c180ed4a 155 /**
Racer01014 0:5e35c180ed4a 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:
Racer01014 0:5e35c180ed4a 157 * - First bit: NUM_LOCK
Racer01014 0:5e35c180ed4a 158 * - Second bit: CAPS_LOCK
Racer01014 0:5e35c180ed4a 159 * - Third bit: SCROLL_LOCK
Racer01014 0:5e35c180ed4a 160 *
Racer01014 0:5e35c180ed4a 161 * @returns status of lock keys
Racer01014 0:5e35c180ed4a 162 */
Racer01014 0:5e35c180ed4a 163 uint8_t lockStatus();
Racer01014 0:5e35c180ed4a 164
Racer01014 0:5e35c180ed4a 165 protected:
Racer01014 0:5e35c180ed4a 166 /*
Racer01014 0:5e35c180ed4a 167 * Get configuration descriptor
Racer01014 0:5e35c180ed4a 168 *
Racer01014 0:5e35c180ed4a 169 * @returns pointer to the configuration descriptor
Racer01014 0:5e35c180ed4a 170 */
Racer01014 0:5e35c180ed4a 171 virtual uint8_t * configurationDesc();
Racer01014 0:5e35c180ed4a 172
Racer01014 0:5e35c180ed4a 173 private:
Racer01014 0:5e35c180ed4a 174 //dummy otherwise it doesn,t compile (we must define all methods of an abstract class)
Racer01014 0:5e35c180ed4a 175 virtual int _getc() {
Racer01014 0:5e35c180ed4a 176 return -1;
Racer01014 0:5e35c180ed4a 177 };
Racer01014 0:5e35c180ed4a 178
Racer01014 0:5e35c180ed4a 179 uint8_t lock_status;
Racer01014 0:5e35c180ed4a 180
Racer01014 0:5e35c180ed4a 181 };
Racer01014 0:5e35c180ed4a 182
Racer01014 0:5e35c180ed4a 183 #endif