Digispark Kullanarak Konfigüre Edilebilir Random Parola Üretici Yapımı – Bölüm 1
Arkadaşlar Merhaba ,
Şuradaki yazımda digispark kartının klavye ve mouse olarak kullanılabileceğinden bahsetmiştim sizlere ve mouse’u random hareket ettirerek ekran koruyucunun devreye girmesini engelleyebileceğimiz donanımı nasıl tasarlayacağımızı anlatmaya çalışmıştım.. Bu yazımda ise yine aynı kartı klavye olarak nasıl kullanacağımızı ve random parolalar üretmek için bir cihazı nasıl tasarlayacağımızı anlatmaya çalışacağım.
Ne istiyorum ?
Bilgisayarımın usb portuna takılı kalacak , kendi algoritması ile değiştirilebilen uzunluklarda şifre üretebilecek , şifrelerin büyükharf,küçükharf,rakam ve bazı özel karakterleri içerebildiği , klavyemden özel bir tuş kombinasyonu ile tetikleyebildiğim bir donanım.
Nasıl tasarladım ?
Klavyemin capslock tuşunu çok yoğun olarak kullanmadığım için caps-lock tuşuna 2 defa basılması durumunda digispark donanımımı harekete geçirmeyi uygun gördüm.
Sistem 8 haneli bir şifre üretmek için , önce 0 ile 4 arasında random bir rakam üretiyor. Üretmiş olduğu bu rakam
0 için özel karakter
1 için küçük harf
2 için rakam
3 için büyük harf
olarak karar verme amacı ile kullanılıyor. Böylece şifrenin içinde bulunacak karakter türleri ve sayıları de randomize edilmiş oluyor.
Sonrasında üreteceği karakter türü belirlenince , cihaz içerisinde tanımlı karakter setinden yine random olarak bir karakter seçiliyor ve parolanın birinci karakteri olarak kullanılıyor. Bu işlem uygun parola uzunluğuna ulaşana kadar devam ediyor.
Parola oluşturulduktan sonra ise ekranda bulunan bir notepad , metin kutusu , parola kutusu gibi bir yere klavye basışı gibi gönderiliyor.
Parola oluşturma algoritmasını oldukça basit tuttum. Zira amacım kırılmaz bir parola oluşturmak değil , basit bir donanım ile hızlıca randomize kodlar oluşturmaktı. Algoritmanın devamında Sezar Şifrelemesi , Tersine Çevirme , Parçalayıp Tekrar Birleştirme gibi ekstra yöntemler eklenebilir ya da oluşturulan şifrenin uzunluğu arttırılabilir.
Sorunlar
Digispark’ın resmi kütüphaneleri klavye üzerinde yer alan capslock , numlock , scroll lock gibi tuşların statelerinin donanım tarafından okunmasına müsaade etmiyor. Bu yüzden öncelikle bu konuya çözüm üretmem gerekiyordu. Çok şükür ki bu konu üzerinde çok fazla çalışmama gerek kalmadı hackaday.io forumlarında danjovic isimli bir geliştirici kütüphanelerde gerekli düzenlemeleri yapmış ve kullanıma sunmuştu. Bu durumda lokal bilgisayarımda ilgili dosyaları danjovic’in kodu ile değiştirerek eklemiş olduğu fonksiyonları kullanmaya başlayabilirdim.
Etkilenen dosyalar ,
1 2 3 |
DigiKeyboard.h usbconfig.h hidkeys.h |
hidkeys.h -> Bu dosya resmi kütüphanede bulunmadığı için oluşturmamız gerekiyor.
Etkilenen dosyaların Windows üzerindeki yolu aşağıdaki şekilde
1 |
c:\Users\__name_of_your_user___0\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.6.7\libraries\DigisparkKeyboard\ |
Etkilenen dosyaların içeriklerini de aşağıdaki kod blokları içerisinde görebilirsiniz. Böylece sizi github’da dosyalar arası sörf yapmak zorunda bırakmamış olacağım.
DigiKeyboard.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
/* * Based on Obdev's AVRUSB code and under the same license. * * TODO: Make a proper file header. :-) * Modified for Digispark by Digistump * Added full Keyboard usage values by Danjovic, February 2016 * Report Buffer extended up to 6 keytrokes simultaneous by Danjovic, March 2016 * Added LED control by Danjovic, January 2019 */ #ifndef __DigiKeyboard_h__ #define __DigiKeyboard_h__ #include <Arduino.h> #include <avr/pgmspace.h> #include <avr/interrupt.h> #include <avr/delay.h> #include <string.h> #include "usbdrv.h" #include "hidkeys.h" #include "scancode-ascii-table.h" // TODO: Work around Arduino 12 issues better. //#include <WConstants.h> //#undef int() typedef uint8_t byte; typedef struct { uint8_t modifier; uint8_t reserved; uint8_t keycode[6]; } keyboard_report_t; // static keyboard_report_t keyboard_report; // sent to PC static volatile uchar ledState = 0xff; // received from PC static uchar idleRate; // repeat rate for keyboards in 4 ms units #define NUM_LOCK (1<<0) #define CAPS_LOCK (1<<1) #define SCROLL_LOCK (1<<2) // From Frank Zhao's USB Business Card project // http://www.frank-zhao.com/cache/usbbusinesscard_details.php const PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x06, // USAGE (Keyboard) 0xa1, 0x01, // COLLECTION (Application) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x08, // REPORT_COUNT (8) 0x05, 0x07, // USAGE_PAGE (Keyboard)(Key Codes) 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)(224) 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)(231) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x81, 0x02, // INPUT (Data,Var,Abs) ; Modifier byte 0x95, 0x01, // REPORT_COUNT (1) 0x75, 0x08, // REPORT_SIZE (8) 0x81, 0x03, // INPUT (Cnst,Var,Abs) ; Reserved byte 0x95, 0x05, // REPORT_COUNT (5) 0x75, 0x01, // REPORT_SIZE (1) 0x05, 0x08, // USAGE_PAGE (LEDs) 0x19, 0x01, // USAGE_MINIMUM (Num Lock) 0x29, 0x05, // USAGE_MAXIMUM (Kana) 0x91, 0x02, // OUTPUT (Data,Var,Abs) ; LED report 0x95, 0x01, // REPORT_COUNT (1) 0x75, 0x03, // REPORT_SIZE (3) 0x91, 0x03, // OUTPUT (Cnst,Var,Abs) ; LED report padding 0x95, 0x06, // REPORT_COUNT (6) 0x75, 0x08, // REPORT_SIZE (8) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x65, // LOGICAL_MAXIMUM (101) 0x05, 0x07, // USAGE_PAGE (Keyboard)(Key Codes) 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))(0) 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)(101) 0x81, 0x00, // INPUT (Data,Ary,Abs) 0xc0 // END_COLLECTION }; class DigiKeyboardDevice : public Print { public: DigiKeyboardDevice () { cli(); usbDeviceDisconnect(); _delay_ms(250); usbDeviceConnect(); usbInit(); sei(); // TODO: Remove the next two lines once we fix // missing first keystroke bug properly. memset((void *)&keyboard_report,0,sizeof(keyboard_report)); usbSetInterrupt((unsigned char*)&keyboard_report, sizeof(keyboard_report)); } void update() { usbPoll(); } // delay while updating until we are finished delaying void delay(long milli) { unsigned long last = millis(); while (milli > 0) { unsigned long now = millis(); milli -= now - last; last = now; update(); } } // get LED State uchar getLEDs (void) { return ledState; } //sendKeyStroke: sends a key press AND release void sendKeyStroke(byte keyStroke) { sendKeyStroke(keyStroke, 0); } //sendKeyStroke: sends a key press AND release with modifiers void sendKeyStroke(byte keyStroke, byte modifiers) { sendKeyPress(keyStroke, modifiers); // This stops endlessly repeating keystrokes: sendKeyPress(0,0); } //sendKeyPress: sends a key press only - no release //to release the key, send again with keyPress=0 void sendKeyPress(byte keyPress) { sendKeyPress(keyPress, 0); } //sendKeyPress: sends a key press only, with modifiers - no release //to release the key, send again with keyPress=0 void sendKeyPress(byte keyPress, byte modifiers) { while (!usbInterruptIsReady()) { // Note: We wait until we can send keyPress // so we know the previous keyPress was // sent. usbPoll(); _delay_ms(5); } memset((void *)&keyboard_report,0,sizeof(keyboard_report)); // memset(reportBuffer, 0, sizeof(reportBuffer)); keyboard_report.modifier = modifiers; // reportBuffer[0] = modifiers; keyboard_report.keycode[1] = keyPress; // reportBuffer[1] = keyPress; usbSetInterrupt((unsigned char*)&keyboard_report, sizeof(keyboard_report)); // usbSetInterrupt(reportBuffer, sizeof(reportBuffer)); } size_t write(uint8_t chr) { uint8_t data = pgm_read_byte_near(ascii_to_scan_code_table + (chr - 8)); sendKeyStroke(data & 0b01111111, data >> 7 ? MOD_SHIFT_RIGHT : 0); return 1; } //private: TODO: Make friend? // maximum 6 keystrokes, defined in HID report keyboard_report_t keyboard_report; // buffer for HID reports [ 1 modifier byte + (len-1) key strokes] using Print::write; }; DigiKeyboardDevice DigiKeyboard = DigiKeyboardDevice(); #ifdef __cplusplus extern "C"{ #endif // USB_PUBLIC uchar usbFunctionSetup uchar usbFunctionSetup(uchar data[8]) { usbRequest_t *rq = (usbRequest_t *)((void *)data); // usbMsgPtr = (unsigned char*)&DigiKeyboard.keyboard_report ;//usbMsgPtr = DigiKeyboard.reportBuffer; // if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { switch(rq->bRequest) { case USBRQ_HID_GET_REPORT: // send "no keys pressed" if asked here // wValue: ReportType (highbyte), ReportID (lowbyte) usbMsgPtr = (unsigned char*)&DigiKeyboard.keyboard_report ;//usbMsgPtr = DigiKeyboard.reportBuffer; // DigiKeyboard.keyboard_report.modifier = 0; DigiKeyboard.keyboard_report.keycode[0] = 0; return sizeof(DigiKeyboard.keyboard_report); case USBRQ_HID_SET_REPORT: // if wLength == 1, should be LED state return (rq->wLength.word == 1) ? USB_NO_MSG : 0; case USBRQ_HID_GET_IDLE: // send idle rate to PC as required by spec usbMsgPtr = &idleRate; return 1; case USBRQ_HID_SET_IDLE: // save idle rate as required by spec idleRate = rq->wValue.bytes[1]; return 0; } } return 0; } #ifdef __cplusplus } // extern "C" #endif #ifdef __cplusplus extern "C"{ #endif // update LED state usbMsgLen_t usbFunctionWrite(uint8_t * data, uchar len) { if (data[0] == ledState) return 1; else ledState = data[0]; return 1; // Data read, not expecting more } #ifdef __cplusplus } // extern "C" #endif #endif // __DigiKeyboard_h__ |
usbconfig.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
/* Name: usbconfig.h * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers * Author: Christian Starkjohann * Creation Date: 2005-04-01 * Tabsize: 4 * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) * This Revision: $Id: usbconfig-prototype.h 767 2009-08-22 11:39:22Z cs $ */ #ifndef __usbconfig_h_included__ #define __usbconfig_h_included__ /* General Description: This file is an example configuration (with inline documentation) for the USB driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may wire the lines to any other port, as long as D+ is also wired to INT0 (or any other hardware interrupt, as long as it is the highest level interrupt, see section at the end of this file). + To create your own usbconfig.h file, copy this file to your project's + firmware source directory) and rename it to "usbconfig.h". + Then edit it accordingly. */ /* ---------------------------- Hardware Config ---------------------------- */ #if defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) #define USB_CFG_IOPORTNAME B #define USB_CFG_DMINUS_BIT 1 #define USB_CFG_DPLUS_BIT 2 #elif defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) #define USB_CFG_IOPORTNAME B #define USB_CFG_DMINUS_BIT 3 #define USB_CFG_DPLUS_BIT 4 #elif defined (__AVR_ATtiny87__) || defined (__AVR_ATtiny167__) #define USB_CFG_IOPORTNAME B #define USB_CFG_DMINUS_BIT 3 #define USB_CFG_DPLUS_BIT 6 #elif defined (__AVR_ATtiny461__) || defined (__AVR_ATtiny861__) #define USB_CFG_IOPORTNAME B #define USB_CFG_DMINUS_BIT 5 #define USB_CFG_DPLUS_BIT 6 #else /* ATtiny2313, ATmega8/48/88/168 */ #define USB_CFG_IOPORTNAME D #define USB_CFG_DMINUS_BIT 3 #define USB_CFG_DPLUS_BIT 2 #endif /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. * This may be any bit in the port. Please note that D+ must also be connected * to interrupt pin INT0! [You can also use other interrupts, see section * "Optional MCU Description" below, or you can connect D- to the interrupt, as * it is required if you use the USB_COUNT_SOF feature. If you use D- for the * interrupt, the USB interrupt will also be triggered at Start-Of-Frame * markers every millisecond.] */ #define USB_CFG_CLOCK_KHZ (F_CPU/1000) /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, * 16500 and 20000. The 12.8 MHz and 16.5 MHz versions of the code require no * crystal, they tolerate +/- 1% deviation from the nominal frequency. All * other rates require a precision of 2000 ppm and thus a crystal! * Default if not specified: 12 MHz */ #define USB_CFG_CHECK_CRC 0 /* Define this to 1 if you want that the driver checks integrity of incoming * data packets (CRC checks). CRC checks cost quite a bit of code size and are * currently only available for 18 MHz crystal clock. You must choose * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. */ /* ----------------------- Optional Hardware Config ------------------------ */ //#define USB_CFG_PULLUP_IOPORTNAME D /* If you connect the 1.5k pullup resistor from D- to a port pin instead of * V+, you can connect and disconnect the device from firmware by calling * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). * This constant defines the port on which the pullup resistor is connected. */ //#define USB_CFG_PULLUP_BIT 5 /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined * above) where the 1.5k pullup resistor is connected. See description * above for details. */ /* --------------------------- Functional Range ---------------------------- */ #define USB_CFG_HAVE_INTRIN_ENDPOINT 1 /* Define this to 1 if you want to compile a version with two endpoints: The * default control endpoint 0 and an interrupt-in endpoint (any other endpoint * number). */ #define USB_CFG_HAVE_INTRIN_ENDPOINT3 0 /* Define this to 1 if you want to compile a version with three endpoints: The * default control endpoint 0, an interrupt-in endpoint 3 (or the number * configured below) and a catch-all default interrupt-in endpoint as above. * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. */ #define USB_CFG_EP3_NUMBER 3 /* If the so-called endpoint 3 is used, it can now be configured to any other * endpoint number (except 0) with this macro. Default if undefined is 3. */ /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ /* The above macro defines the startup condition for data toggling on the * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. * Since the token is toggled BEFORE sending any data, the first packet is * sent with the oposite value of this configuration! */ #define USB_CFG_IMPLEMENT_HALT 0 /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature * for endpoint 1 (interrupt endpoint). Although you may not need this feature, * it is required by the standard. We have made it a config option because it * bloats the code considerably. */ #define USB_CFG_SUPPRESS_INTR_CODE 0 /* Define this to 1 if you want to declare interrupt-in endpoints, but don't * want to send any data over them. If this macro is defined to 1, functions * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if * you need the interrupt-in endpoints in order to comply to an interface * (e.g. HID), but never want to send any data. This option saves a couple * of bytes in flash memory and the transmit buffers in RAM. */ #define USB_CFG_INTR_POLL_INTERVAL 10 /* If you compile a version with endpoint 1 (interrupt-in), this is the poll * interval. The value is in milliseconds and must not be less than 10 ms for * low speed devices. */ #define USB_CFG_IS_SELF_POWERED 0 /* Define this to 1 if the device has its own power supply. Set it to 0 if the * device is powered from the USB bus. */ #define USB_CFG_MAX_BUS_POWER 100 /* Set this variable to the maximum USB bus power consumption of your device. * The value is in milliamperes. [It will be divided by two since USB * communicates power requirements in units of 2 mA.] */ #define USB_CFG_IMPLEMENT_FN_WRITE 1 /* Set this to 1 if you want usbFunctionWrite() to be called for control-out * transfers. Set it to 0 if you don't need it and want to save a couple of * bytes. */ #define USB_CFG_IMPLEMENT_FN_READ 0 /* Set this to 1 if you need to send control replies which are generated * "on the fly" when usbFunctionRead() is called. If you only want to send * data from a static buffer, set it to 0 and return the data from * usbFunctionSetup(). This saves a couple of bytes. */ #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. * You must implement the function usbFunctionWriteOut() which receives all * interrupt/bulk data sent to any endpoint other than 0. The endpoint number * can be found in 'usbRxToken'. */ #define USB_CFG_HAVE_FLOWCONTROL 0 /* Define this to 1 if you want flowcontrol over USB data. See the definition * of the macros usbDisableAllRequests() and usbEnableAllRequests() in * usbdrv.h. */ #define USB_CFG_LONG_TRANSFERS 0 /* Define this to 1 if you want to send/receive blocks of more than 254 bytes * in a single control-in or control-out transfer. Note that the capability * for long transfers increases the driver size. */ /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ /* This macro is a hook if you want to do unconventional things. If it is * defined, it's inserted at the beginning of received message processing. * If you eat the received message and don't want default processing to * proceed, do a return after doing your things. One possible application * (besides debugging) is to flash a status LED on each packet. */ /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ /* This macro is a hook if you need to know when an USB RESET occurs. It has * one parameter which distinguishes between the start of RESET state and its * end. */ /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ /* This macro (if defined) is executed when a USB SET_ADDRESS request was * received. */ #define USB_COUNT_SOF 0 /* define this macro to 1 if you need the global variable "usbSofCount" which * counts SOF packets. This feature requires that the hardware interrupt is * connected to D- instead of D+. */ /* #ifdef __ASSEMBLER__ * macro myAssemblerMacro * in YL, TCNT0 * sts timer0Snapshot, YL * endm * #endif * #define USB_SOF_HOOK myAssemblerMacro * This macro (if defined) is executed in the assembler module when a * Start Of Frame condition is detected. It is recommended to define it to * the name of an assembler macro which is defined here as well so that more * than one assembler instruction can be used. The macro may use the register * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages * immediately after an SOF pulse may be lost and must be retried by the host. * What can you do with this hook? Since the SOF signal occurs exactly every * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in * designs running on the internal RC oscillator. * Please note that Start Of Frame detection works only if D- is wired to the * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! */ #define USB_CFG_CHECK_DATA_TOGGLING 0 /* define this macro to 1 if you want to filter out duplicate data packets * sent by the host. Duplicates occur only as a consequence of communication * errors, when the host does not receive an ACK. Please note that you need to * implement the filtering yourself in usbFunctionWriteOut() and * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable * for each control- and out-endpoint to check for duplicate packets. */ #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 1 #include "osccal.h" /* define this macro to 1 if you want the function usbMeasureFrameLength() * compiled in. This function can be used to calibrate the AVR's RC oscillator. */ #define USB_USE_FAST_CRC 0 /* The assembler module has two implementations for the CRC algorithm. One is * faster, the other is smaller. This CRC routine is only used for transmitted * messages where timing is not critical. The faster routine needs 31 cycles * per byte while the smaller one needs 61 to 69 cycles. The faster routine * may be worth the 32 bytes bigger code size if you transmit lots of data and * run the AVR close to its limit. */ /* -------------------------- Device Description --------------------------- */ #define USB_CFG_VENDOR_ID 0xc0, 0x16 /* USB vendor ID for the device, low byte first. If you have registered your * own Vendor ID, define it here. Otherwise you may use one of obdev's free * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! * *** IMPORTANT NOTE *** * This template uses obdev's shared VID/PID pair for Vendor Class devices * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand * the implications! */ #define USB_CFG_DEVICE_ID 0xdb, 0x27 /* This is the ID of the product, low byte first. It is interpreted in the * scope of the vendor ID. If you have registered your own VID with usb.org * or if you have licensed a PID from somebody else, define it here. Otherwise * you may use one of obdev's free shared VID/PID pairs. See the file * USB-IDs-for-free.txt for details! * *** IMPORTANT NOTE *** * This template uses obdev's shared VID/PID pair for Vendor Class devices * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand * the implications! */ #define USB_CFG_DEVICE_VERSION 0x00, 0x01 /* Version number of the device: Minor number first, then major number. */ #define USB_CFG_VENDOR_NAME 'd','i','g','i','s','t','u','m','p','.','c','o','m' #define USB_CFG_VENDOR_NAME_LEN 13 /* These two values define the vendor name returned by the USB device. The name * must be given as a list of characters under single quotes. The characters * are interpreted as Unicode (UTF-16) entities. * If you don't want a vendor name string, undefine these macros. * ALWAYS define a vendor name containing your Internet domain name if you use * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for * details. */ #define USB_CFG_DEVICE_NAME 'D','i','g','i','K','e','y' #define USB_CFG_DEVICE_NAME_LEN 7 /* Same as above for the device name. If you don't want a device name, undefine * the macros. See the file USB-IDs-for-free.txt before you assign a name if * you use a shared VID/PID. */ /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ /* Same as above for the serial number. If you don't want a serial number, * undefine the macros. * It may be useful to provide the serial number through other means than at * compile time. See the section about descriptor properties below for how * to fine tune control over USB descriptors such as the string descriptor * for the serial number. */ #define USB_CFG_DEVICE_CLASS 0 /* set to 0 if deferred to interface */ #define USB_CFG_DEVICE_SUBCLASS 0 /* See USB specification if you want to conform to an existing device class. * Class 0xff is "vendor specific". */ #define USB_CFG_INTERFACE_CLASS 0x03 /* HID */ /* define class here if not at device level */ #define USB_CFG_INTERFACE_SUBCLASS 0x01 #define USB_CFG_INTERFACE_PROTOCOL 0x01 /* See USB specification if you want to conform to an existing device class or * protocol. The following classes must be set at interface level: * HID class is 3, no subclass and protocol required (but may be useful!) * CDC class is 2, use subclass 2 and protocol 1 for ACM */ #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 63 // 35 /* Define this to the length of the HID report descriptor, if you implement * an HID device. Otherwise don't define it or define it to 0. * If you use this define, you must add a PROGMEM character array named * "usbHidReportDescriptor" to your code which contains the report descriptor. * Don't forget to keep the array and this define in sync! */ /* #define USB_PUBLIC static */ /* Use the define above if you #include usbdrv.c instead of linking against it. * This technique saves a couple of bytes in flash memory. */ /* ------------------- Fine Control over USB Descriptors ------------------- */ /* If you don't want to use the driver's default USB descriptors, you can * provide our own. These can be provided as (1) fixed length static data in * flash memory, (2) fixed length static data in RAM or (3) dynamically at * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more * information about this function. * Descriptor handling is configured through the descriptor's properties. If * no properties are defined or if they are 0, the default descriptor is used. * Possible properties are: * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if * you want RAM pointers. * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found * in static memory is in RAM, not in flash memory. * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), * the driver must know the descriptor's length. The descriptor itself is * found at the address of a well known identifier (see below). * List of static descriptor names (must be declared PROGMEM if in flash): * char usbDescriptorDevice[]; * char usbDescriptorConfiguration[]; * char usbDescriptorHidReport[]; * char usbDescriptorString0[]; * int usbDescriptorStringVendor[]; * int usbDescriptorStringDevice[]; * int usbDescriptorStringSerialNumber[]; * Other descriptors can't be provided statically, they must be provided * dynamically at runtime. * * Descriptor properties are or-ed or added together, e.g.: * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) * * The following descriptors are defined: * USB_CFG_DESCR_PROPS_DEVICE * USB_CFG_DESCR_PROPS_CONFIGURATION * USB_CFG_DESCR_PROPS_STRINGS * USB_CFG_DESCR_PROPS_STRING_0 * USB_CFG_DESCR_PROPS_STRING_VENDOR * USB_CFG_DESCR_PROPS_STRING_PRODUCT * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER * USB_CFG_DESCR_PROPS_HID * USB_CFG_DESCR_PROPS_HID_REPORT * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) * * Note about string descriptors: String descriptors are not just strings, they * are Unicode strings prefixed with a 2 byte header. Example: * int serialNumberDescriptor[] = { * USB_STRING_DESCRIPTOR_HEADER(6), * 'S', 'e', 'r', 'i', 'a', 'l' * }; */ #define USB_CFG_DESCR_PROPS_DEVICE 0 #define USB_CFG_DESCR_PROPS_CONFIGURATION 0 #define USB_CFG_DESCR_PROPS_STRINGS 0 #define USB_CFG_DESCR_PROPS_STRING_0 0 #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 #define USB_CFG_DESCR_PROPS_HID 0 #define USB_CFG_DESCR_PROPS_HID_REPORT 0 #define USB_CFG_DESCR_PROPS_UNKNOWN 0 /* ----------------------- Optional MCU Description ------------------------ */ /* The following configurations have working defaults in usbdrv.h. You * usually don't need to set them explicitly. Only if you want to run * the driver on a device which is not yet supported or with a compiler * which is not fully supported (such as IAR C) or if you use a differnt * interrupt than INT0, you may have to define some of these. */ /* #define USB_INTR_CFG MCUCR */ /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ /* #define USB_INTR_CFG_CLR 0 */ /* #define USB_INTR_ENABLE GIMSK */ /* #define USB_INTR_ENABLE_BIT INT0 */ /* #define USB_INTR_PENDING GIFR */ /* #define USB_INTR_PENDING_BIT INTF0 */ /* #define USB_INTR_VECTOR SIG_INTERRUPT0 */ #ifndef SIG_INTERRUPT0 #define SIG_INTERRUPT0 _VECTOR(1) #endif #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) #define USB_INTR_CFG PCMSK #define USB_INTR_CFG_SET (1<<USB_CFG_DPLUS_BIT) #define USB_INTR_ENABLE_BIT PCIE #define USB_INTR_PENDING_BIT PCIF #define USB_INTR_VECTOR SIG_PIN_CHANGE #endif #if defined (__AVR_ATtiny87__) || defined (__AVR_ATtiny167__) #define USB_INTR_CFG PCMSK1 #define USB_INTR_CFG_SET (1 << USB_CFG_DPLUS_BIT) #define USB_INTR_CFG_CLR 0 #define USB_INTR_ENABLE PCICR #define USB_INTR_ENABLE_BIT PCIE1 #define USB_INTR_PENDING PCIFR #define USB_INTR_PENDING_BIT PCIF1 #define USB_INTR_VECTOR PCINT1_vect #endif #endif /* __usbconfig_h_included__ */ |
hidkeys.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
#ifndef __hidkeys_h_included__ #define __hidkeys_h_included__ /* Keyboard usage values, see usb.org's HID-usage-tables document, chapter * 10 Keyboard/Keypad Page for more codes. */ #define MOD_CONTROL_LEFT (1<<0) #define MOD_SHIFT_LEFT (1<<1) #define MOD_ALT_LEFT (1<<2) #define MOD_GUI_LEFT (1<<3) #define MOD_CONTROL_RIGHT (1<<4) #define MOD_SHIFT_RIGHT (1<<5) #define MOD_ALT_RIGHT (1<<6) #define MOD_GUI_RIGHT (1<<7) #define KEY_NOKEY 0x00 // Reserved (no event indicated) #define KEY_ERR_ROLLOVER 0x01 // Keyboard ErrorRollOver #define KEY_POSTFAIL 0x02 // Keyboard POSTFail #define KEY_ERR_UNDEFINED 0x03 // Keyboard ErrorUndefined #define KEY_A 0x04 // Keyboard a and A #define KEY_B 0x05 // Keyboard b and B #define KEY_C 0x06 // Keyboard c and C #define KEY_D 0x07 // Keyboard d and D #define KEY_E 0x08 // Keyboard e and E #define KEY_F 0x09 // Keyboard f and F #define KEY_G 0x0A // Keyboard g and G #define KEY_H 0x0B // Keyboard h and H #define KEY_I 0x0C // Keyboard i and I #define KEY_J 0x0D // Keyboard j and J #define KEY_K 0x0E // Keyboard k and K #define KEY_L 0x0F // Keyboard l and L #define KEY_M 0x10 // Keyboard m and M #define KEY_N 0x11 // Keyboard n and N #define KEY_O 0x12 // Keyboard o and O #define KEY_P 0x13 // Keyboard p and P #define KEY_Q 0x14 // Keyboard q and Q #define KEY_R 0x15 // Keyboard r and R #define KEY_S 0x16 // Keyboard s and S #define KEY_T 0x17 // Keyboard t and T #define KEY_U 0x18 // Keyboard u and U #define KEY_V 0x19 // Keyboard v and V #define KEY_W 0x1A // Keyboard w and W #define KEY_X 0x1B // Keyboard x and X #define KEY_Y 0x1C // Keyboard y and Y #define KEY_Z 0x1D // Keyboard z and Z #define KEY_1 0x1E // Keyboard 1 and ! #define KEY_2 0x1F // Keyboard 2 and #define KEY_3 0x20 // Keyboard 3 and # #define KEY_4 0x21 // Keyboard 4 and $ #define KEY_5 0x22 // Keyboard 5 and % #define KEY_6 0x23 // Keyboard 6 and ^ #define KEY_7 0x24 // Keyboard 7 and & #define KEY_8 0x25 // Keyboard 8 and * #define KEY_9 0x26 // Keyboard 9 and ( #define KEY_0 0x27 // Keyboard 0 and ) #define KEY_ENTER 0x28 // Keyboard Return (ENTER) #define KEY_ESCAPE 0x29 // Keyboard ESCAPE #define KEY_BACKSP 0x2A // Keyboard Backspace #define KEY_TAB 0x2B // Keyboard Tab #define KEY_SPACE 0x2C // Keyboard Spacebar #define KEY_MINUS 0x2D // Keyboard - and (underscore) #define KEY_EQUAL 0x2E // Keyboard = and + #define KEY_L_BRACKET 0x2F // Keyboard [ and { #define KEY_R_BRACKET 0x30 // Keyboard ] and } #define KEY_BACKSLASH 0x31 // Keyboard \ and | #define KEY_HASH 0x32 // Keyboard Non-US # and ~ #define KEY_SEMICOLON 0x33 // Keyboard ; and : #define KEY_APOSTROPHE 0x34 // Keyboard ‘ and “ #define KEY_GRAVE 0x35 // Keyboard Grave Accent and Tilde #define KEY_COMMA 0x36 // Keyboard , and < #define KEY_DOT 0x37 // Keyboard . and > #define KEY_SLASH 0x38 // Keyboard / and ? #define KEY_CAPS_LOCK 0x39 // Keyboard Caps Lock #define KEY_F1 0x3A // Keyboard F1 #define KEY_F2 0x3B // Keyboard F2 #define KEY_F3 0x3C // Keyboard F3 #define KEY_F4 0x3D // Keyboard F4 #define KEY_F5 0x3E // Keyboard F5 #define KEY_F6 0x3F // Keyboard F6 #define KEY_F7 0x40 // Keyboard F7 #define KEY_F8 0x41 // Keyboard F8 #define KEY_F9 0x42 // Keyboard F9 #define KEY_F10 0x43 // Keyboard F10 #define KEY_F11 0x44 // Keyboard F11 #define KEY_F12 0x45 // Keyboard F12 #define KEY_PRTSCN 0x46 // Keyboard PrintScreen #define KEY_SCR_LOCK 0x47 // Keyboard Scroll Lock #define KEY_PAUSE 0x48 // Keyboard Pause #define KEY_INSERT 0x49 // Keyboard Insert #define KEY_HOME 0x4A // Keyboard Home #define KEY_PAGE_UP 0x4B // Keyboard PageUp #define KEY_DELETE 0x4C // Keyboard Delete Forward #define KEY_END 0x4D // Keyboard End #define KEY_PAGE_DOWN 0x4E // Keyboard PageDown #define KEY_ARROW_RIGHT 0x4F // Keyboard RightArrow #define KEY_ARROW_LEFT 0x50 // Keyboard LeftArrow #define KEY_ARROW_DOWN 0x51 // Keyboard DownArrow #define KEY_ARROW_UP 0x52 // Keyboard UpArrow #define KEY_RIGHT_ARROW 0x4F // Keyboard RightArrow -> Alternative arrow keys names #define KEY_LEFT_ARROW 0x50 // Keyboard LeftArrow #define KEY_DOWN_ARROW 0x51 // Keyboard DownArrow #define KEY_UP_ARROW 0x52 // Keyboard UpArrow #define KEY_NUM_LOCK 0x53 // Keypad Num Lock and Clear #define KEY_KPAD_SLASH 0x54 // Keypad / #define KEY_KPAD_TIMES 0x55 // Keypad * #define KEY_KPAD_MINUS 0x56 // Keypad - #define KEY_KPAD_PLUS 0x57 // Keypad + #define KEY_KPAD_ENTER 0x58 // Keypad ENTER #define KEY_KPAD_1 0x59 // Keypad 1 and End #define KEY_KPAD_2 0x5A // Keypad 2 and Down Arrow #define KEY_KPAD_3 0x5B // Keypad 3 and PageDn #define KEY_KPAD_4 0x5C // Keypad 4 and Left Arrow #define KEY_KPAD_5 0x5D // Keypad 5 #define KEY_KPAD_6 0x5E // Keypad 6 and Right Arrow #define KEY_KPAD_7 0x5F // Keypad 7 and Home #define KEY_KPAD_8 0x60 // Keypad 8 and Up Arrow #define KEY_KPAD_9 0x61 // Keypad 9 and PageUp #define KEY_KPAD_0 0x62 // Keypad 0 and Insert #define KEY_KPAD_DOT 0x63 // Keypad . and Delete #define KEY_INTL_BACKSLASH 0x64 // Keyboard Non-US \ and | #define KEY_APPLICATION 0x65 // Keyboard Application #define KEY_POWER 0x66 // Keyboard Power #define KEY_KPAD_EQUAL 0x67 // Keypad = #define KEY_F13 0x68 // Keyboard F13 #define KEY_F14 0x69 // Keyboard F14 #define KEY_F15 0x6A // Keyboard F15 #define KEY_F16 0x6B // Keyboard F16 #define KEY_F17 0x6C // Keyboard F17 #define KEY_F18 0x6D // Keyboard F18 #define KEY_F19 0x6E // Keyboard F19 #define KEY_F20 0x6F // Keyboard F20 #define KEY_F21 0x70 // Keyboard F21 #define KEY_F22 0x71 // Keyboard F22 #define KEY_F23 0x72 // Keyboard F23 #define KEY_F24 0x73 // Keyboard F24 #define KEY_EXECUTE 0x74 // Keyboard Execute #define KEY_HELP 0x75 // Keyboard Help #define KEY_MENU 0x76 // Keyboard Menu #define KEY_SELECT 0x77 // Keyboard Select #define KEY_STOP 0x78 // Keyboard Stop #define KEY_AGAIN 0x79 // Keyboard Again #define KEY_UNDO 0x7A // Keyboard Undo #define KEY_CUT 0x7B // Keyboard Cut #define KEY_COPY 0x7C // Keyboard Copy #define KEY_PASTE 0x7D // Keyboard Paste #define KEY_FIND 0x7E // Keyboard Find #define KEY_MUTE 0x7F // Keyboard Mute #define KEY_VOLUME_UP 0x80 // Keyboard Volume Up #define KEY_VOLUME_DOWN 0x81 // Keyboard Volume Down #define KEY_LOCK_CAPS_LOCK 0x82 // Keyboard Locking Caps Lock #define KEY_LOCK_NUM_LOCK 0x83 // Keyboard Locking Num Lock #define KEY_LOCK_SCR_LOCK 0x84 // Keyboard Locking Scroll Lock #define KEY_KPAD_COMMA 0x85 // Keypad Comma #define KEY_EQUAL_SIGN 0x86 // Keypad Equal Sign #define KEY_INTL1 0x87 // Keyboard International1 #define KEY_INTL2 0x88 // Keyboard International2 #define KEY_INTL3 0x89 // Keyboard International3 #define KEY_INTL4 0x8A // Keyboard International4 #define KEY_INTL5 0x8B // Keyboard International5 #define KEY_INTL6 0x8C // Keyboard International6 #define KEY_INTL7 0x8D // Keyboard International7 #define KEY_INTL8 0x8E // Keyboard International8 #define KEY_INTL9 0x8F // Keyboard International9 #define KEY_LANG1 0x90 // Keyboard LANG1 #define KEY_LANG2 0x91 // Keyboard LANG2 #define KEY_LANG3 0x92 // Keyboard LANG3 #define KEY_LANG4 0x93 // Keyboard LANG4 #define KEY_LANG5 0x94 // Keyboard LANG5 #define KEY_LANG6 0x95 // Keyboard LANG6 #define KEY_LANG7 0x96 // Keyboard LANG7 #define KEY_LANG8 0x97 // Keyboard LANG8 #define KEY_LANG9 0x98 // Keyboard LANG9 #define KEY_ALT_ERASE 0x99 // Keyboard Alternate Erase #define KEY_SYSREQ 0x9A // Keyboard SysReq/Attention #define KEY_CANCEL 0x9B // Keyboard Cancel #define KEY_CLEAR 0x9C // Keyboard Clear #define KEY_PRIOR 0x9D // Keyboard Prior #define KEY_RETURN 0x9E // Keyboard Return #define KEY_SEPARATOR 0x9F // Keyboard Separator #define KEY_OUT 0xA0 // Keyboard Out #define KEY_OPER 0xA1 // Keyboard Oper #define KEY_CLEAR 0xA2 // Keyboard Clear/Again #define KEY_CRSEL 0xA3 // Keyboard CrSel/Props #define KEY_EXSEL 0xA4 // Keyboard ExSel // Keys 0xA5 to 0xAF reserved #define KEY_KPAD_00 0xB0 // Keypad 00 #define KEY_KPAD_000 0xB1 // Keypad 000 #define KEY_THOUSANDS_SEP 0xB2 // Thousands Separator #define KEY_DECIMAL_SEP 0xB3 // Decimal Separator #define KEY_CURRENCY 0xB4 // Currency Unit #define KEY_SUB_CURRENCY 0xB5 // Currency Sub-unit #define KEY_KPAD_LEFT_PAREN 0xB6 // Keypad ( #define KEY_KPAD_RIGHT_PAREN 0xB7 // Keypad ) #define KEY_KPAD_LEFT_BRACE 0xB8 // Keypad { #define KEY_KPAD_RIGHT_BRACE 0xB9 // Keypad } #define KEY_KPAD_TAB 0xBA // Keypad Tab #define KEY_KPAD_BACKSPACE 0xBB // Keypad Backspace #define KEY_KPAD_A 0xBC // Keypad A #define KEY_KPAD_B 0xBD // Keypad B #define KEY_KPAD_C 0xBE // Keypad C #define KEY_KPAD_D 0xBF // Keypad D #define KEY_KPAD_E 0xC0 // Keypad E #define KEY_KPAD_F 0xC1 // Keypad F #define KEY_KPAD_XOR 0xC2 // Keypad XOR #define KEY_KPAD_CARET 0xC3 // Keypad ^ #define KEY_KPAD_PERCENT 0xC4 // Keypad % #define KEY_KPAD_LESS_THAN 0xC5 // Keypad < #define KEY_KPAD_GREAT_THAN 0xC6 // Keypad > #define KEY_KPAD_AND 0xC7 // Keypad & #define KEY_KPAD_DBL_AND 0xC8 // Keypad && #define KEY_KPAD_OR 0xC9 // Keypad | #define KEY_KPAD_DBL_OR 0xCA // Keypad || #define KEY_KPAD_COLON 0xCB // Keypad : #define KEY_KPAD_HASH 0xCC // Keypad # #define KEY_KPAD_SPACE 0xCD // Keypad Space #define KEY_KPAD_AT 0xCE // Keypad @ #define KEY_KPAD_EXCLAMATION 0xCF // Keypad ! #define KEY_KPAD_MEM_STORE 0xD0 // Keypad Memory Store #define KEY_KPAD_MEM_RECALL 0xD1 // Keypad Memory Recall #define KEY_KPAD_MEM_CLEAR 0xD2 // Keypad Memory Clear #define KEY_KPAD_MEM_ADD 0xD3 // Keypad Memory Add #define KEY_KPAD_MEM_SUB 0xD4 // Keypad Memory Subtract #define KEY_KPAD_MEM_MULTIPLY 0xD5 // Keypad Memory Multiply #define KEY_KPAD_MEM_DIVIDE 0xD6 // Keypad Memory Divide #define KEY_PLUS_MINUS 0xD7 // Keypad +/- #define KEY_CLEAR 0xD8 // Keypad Clear #define KEY_CLEAR_ENTRY 0xD9 // Keypad Clear Entry #define KEY_BINARY 0xDA // Keypad Binary #define KEY_OCTAL 0xDB // Keypad Octal #define KEY_DECIMAL 0xDC // Keypad Decimal #define KEY_HEXADECIMAL 0xDD // Keypad Hexadecimal // Keys 0xDE to 0xDF reserved #define KEY_L_CONTROL 0xE0 // Keyboard LeftControl #define KEY_L_SHIFT 0xE1 // Keyboard LeftShift #define KEY_L_ALT 0xE2 // Keyboard LeftAlt #define KEY_L_GUI 0xE3 // Keyboard Left GUI #define KEY_R_CONTROL 0xE4 // Keyboard RightControl #define KEY_R_SHIFT 0xE5 // Keyboard RightShift #define KEY_R_ALT 0xE6 // Keyboard RightAlt #define KEY_R_GUI 0xE7 // Keyboard Right GUI #endif |
Dosyalarda değişiklikleri gerçekleştirdikten sonra digispark kartımız üzerinde bulunan led yardımı ile capslock/numlock/scroll lock durumlarını gösteren aşağıdaki gibi bir örnek kod yükleyelim.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include "DigiKeyboard.h" void setup() { pinMode(1,OUTPUT); } void loop() { if (DigiKeyboard.getLEDs() & CAPS_LOCK) digitalWrite(1, HIGH); else digitalWrite(1, LOW); DigiKeyboard.delay(10); } |
Burada dikkat edilmesi gereken husus hangi tuşu takip etmek istiyorsak CAPS_LOCK yerinde onun bulunması gerektiği.
Kullanılabilecek sabitler digikeyboard.h dosyasında görülebilir.
1 2 3 |
#define NUM_LOCK (1<<0) #define CAPS_LOCK (1<<1) #define SCROLL_LOCK (1<<2) |
Gerekli düzenlemeleri yaptık ve buraya kadar konuyu netleştirdiysek Arduino üzerindeki kodu yazma aşamasına geçiş yapabiliriz.
Arduino kullanan arkadaşlarımızın bilirler kodumuzu bir loop bloğu arasına yazarız ve kartta elektrik olduğu müddetçe bu loop bloğu çalışmaya devam eder. Bu durumda capslock’un basılı bırakılması halinde donanım sürekli capslock’un basılı olduğunu düşünerek parola üretmeye devam edecek. Kodumuzu tasarlarken bu detaya dikkat etmemiz çok önemli.
Yüklememiz gereken kod bloğu ,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
#include "DigiKeyboard.h" String upperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String lowerCaseLetters = "abcdefghijklmnopqrstuvwxyz"; String numbers = "0123456789"; String specialLetters = "!é.@#$+*&?_-"; byte passwordLength = 8; byte capslockCounter = 0; /* Rnd 0 = special Rnd 1 = lower Rnd 2 = number Rnd 3 = upper */ void setup() { // put your setup code here, to run once: pinMode(1, OUTPUT); // Digistump BuiltIn LED as output } bool capsUp = false; void loop() { if (DigiKeyboard.getLEDs() & CAPS_LOCK) { capslockCounter++; } else { if (capslockCounter >= 1) capsUp = true; } if (capslockCounter >= 2 && capsUp == true) { // put your main code here, to run repeatedly: String password = ""; for (byte len = 0 ; len < passwordLength; len++) { byte charSet = random(0, 4); if (charSet == 0) { //SpecialChar byte specialCharRandom = random(0, 12); password += specialLetters[specialCharRandom]; } else if (charSet == 1) { //lowerChar byte lowerCharRandom = random(0, 25); password += lowerCaseLetters[lowerCharRandom]; } else if (charSet == 2) { //number byte numberCharRandom = random(0, 10); password += numbers[numberCharRandom]; } else { //upperChar byte upperCharRandom = random(0, 25); password += upperCaseLetters[upperCharRandom]; } } DigiKeyboard.println(password); capslockCounter = 0; password = ""; capsUp = false; } DigiKeyboard.delay(10); } |
Aşağıdaki animasyonda parola üretme sürecini ve sağ alttaki bildirimlerden de capslock statusunu görebilirsiniz.