diff --git a/lib/Bad_Usb_Lib/KeyboardLayout_en_UK.cpp b/lib/Bad_Usb_Lib/KeyboardLayout_en_UK.cpp new file mode 100644 index 000000000..ba60fd730 --- /dev/null +++ b/lib/Bad_Usb_Lib/KeyboardLayout_en_UK.cpp @@ -0,0 +1,138 @@ +/* + * Standard US keyboard layout. + */ + +#include "Keyboard_en_UK.h" + +extern const uint8_t KeyboardLayout_en_UK[128] PROGMEM = +{ + 0x00, // NUL + 0x00, // SOH + 0x00, // STX + 0x00, // ETX + 0x00, // EOT + 0x00, // ENQ + 0x00, // ACK + 0x00, // BEL + 0x2a, // BS Backspace + 0x2b, // TAB Tab + 0x28, // LF Enter + 0x00, // VT + 0x00, // FF + 0x00, // CR + 0x00, // SO + 0x00, // SI + 0x00, // DEL + 0x00, // DC1 + 0x00, // DC2 + 0x00, // DC3 + 0x00, // DC4 + 0x00, // NAK + 0x00, // SYN + 0x00, // ETB + 0x00, // CAN + 0x00, // EM + 0x00, // SUB + 0x00, // ESC + 0x00, // FS + 0x00, // GS + 0x00, // RS + 0x00, // US + + 0x2c, // ' ' + 0x1e|SHIFT, // ! + 0x1f|SHIFT, // " ok + 0x31, // # ok + 0x21|SHIFT, // $ + 0x22|SHIFT, // % + 0x24|SHIFT, // & + 0x34, // ' ok + 0x26|SHIFT, // ( + 0x27|SHIFT, // ) + 0x25|SHIFT, // * + 0x2e|SHIFT, // + + 0x36, // , + 0x2d, // - + 0x37, // . + 0x38, // / + 0x27, // 0 + 0x1e, // 1 + 0x1f, // 2 + 0x20, // 3 + 0x21, // 4 + 0x22, // 5 + 0x23, // 6 + 0x24, // 7 + 0x25, // 8 + 0x26, // 9 + 0x33|SHIFT, // : + 0x33, // ; + 0x36|SHIFT, // < + 0x2e, // = + 0x37|SHIFT, // > + 0x38|SHIFT, // ? + 0x34|SHIFT, // @ ok + 0x04|SHIFT, // A + 0x05|SHIFT, // B + 0x06|SHIFT, // C + 0x07|SHIFT, // D + 0x08|SHIFT, // E + 0x09|SHIFT, // F + 0x0a|SHIFT, // G + 0x0b|SHIFT, // H + 0x0c|SHIFT, // I + 0x0d|SHIFT, // J + 0x0e|SHIFT, // K + 0x0f|SHIFT, // L + 0x10|SHIFT, // M + 0x11|SHIFT, // N + 0x12|SHIFT, // O + 0x13|SHIFT, // P + 0x14|SHIFT, // Q + 0x15|SHIFT, // R + 0x16|SHIFT, // S + 0x17|SHIFT, // T + 0x18|SHIFT, // U + 0x19|SHIFT, // V + 0x1a|SHIFT, // W + 0x1b|SHIFT, // X + 0x1c|SHIFT, // Y + 0x1d|SHIFT, // Z + 0x2f, // [ + 0x64, // bslash ok + 0x30, // ] + 0x23|SHIFT, // ^ + 0x2d|SHIFT, // _ + 0x35, // ` + 0x04, // a + 0x05, // b + 0x06, // c + 0x07, // d + 0x08, // e + 0x09, // f + 0x0a, // g + 0x0b, // h + 0x0c, // i + 0x0d, // j + 0x0e, // k + 0x0f, // l + 0x10, // m + 0x11, // n + 0x12, // o + 0x13, // p + 0x14, // q + 0x15, // r + 0x16, // s + 0x17, // t + 0x18, // u + 0x19, // v + 0x1a, // w + 0x1b, // x + 0x1c, // y + 0x1d, // z + 0x2f|SHIFT, // { + 0x35, // | ok + 0x30|SHIFT, // } + 0x31|SHIFT, // ~ ok + 0x00 // DEL +}; diff --git a/lib/Bad_Usb_Lib/Keyboard_en_UK.h b/lib/Bad_Usb_Lib/Keyboard_en_UK.h new file mode 100644 index 000000000..a01cdec81 --- /dev/null +++ b/lib/Bad_Usb_Lib/Keyboard_en_UK.h @@ -0,0 +1,67 @@ +/* + KeyboardLayout.h + + This file is not part of the public API. It is meant to be included + only in Keyboard.cpp and the keyboard layout files. Layout files map + ASCII character codes to keyboard scan codes (technically, to USB HID + Usage codes), possibly altered by the SHIFT or ALT_GR modifiers. + Non-ACSII characters (anything outside the 7-bit range NUL..DEL) are + not supported. + + == Creating your own layout == + + In order to create your own layout file, copy an existing layout that + is similar to yours, then modify it to use the correct keys. The + layout is an array in ASCII order. Each entry contains a scan code, + possibly modified by "|SHIFT" or "|ALT_GR", as in this excerpt from + the Italian layout: + + 0x35, // bslash + 0x30|ALT_GR, // ] + 0x2e|SHIFT, // ^ + + Do not change the control characters (those before scan code 0x2c, + corresponding to space). Do not attempt to grow the table past DEL. Do + not use both SHIFT and ALT_GR on the same character: this is not + supported. Unsupported characters should have 0x00 as scan code. + + For a keyboard with an ISO physical layout, use the scan codes below: + + +---+---+---+---+---+---+---+---+---+---+---+---+---+-------+ + |35 |1e |1f |20 |21 |22 |23 |24 |25 |26 |27 |2d |2e |BackSp | + +---+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-----+ + | Tab |14 |1a |08 |15 |17 |1c |18 |0c |12 |13 |2f |30 | Ret | + +-----++--++--++--++--++--++--++--++--++--++--++--++--++ | + |CapsL |04 |16 |07 |09 |0a |0b |0d |0e |0f |33 |34 |31 | | + +----+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+---+----+ + |Shi.|32 |1d |1b |06 |19 |05 |11 |10 |36 |37 |38 | Shift | + +----+---++--+-+-+---+---+---+---+---+--++---+---++----+----+ + |Ctrl|Win |Alt | |AlGr|Win |Menu|Ctrl| + +----+----+----+------------------------+----+----+----+----+ + + The ANSI layout is identical except that key 0x31 is above (rather + than next to) Return, and there is not key 0x32. + + Give a unique name to the layout array, then declare it in Keyboard.h + with a line of the form: + + extern const uint8_t KeyboardLayout_xx_YY[]; + + == Encoding details == + + All scan codes are less than 0x80, which makes bit 7 available to + signal that a modifier (Shift or AltGr) is needed to generate the + character. With only one exception, keys that are used with modifiers + have scan codes that are less than 0x40. This makes bit 6 available + to signal whether the modifier is Shift or AltGr. The exception is + 0x64, the key next next to Left Shift on the ISO layout (and absent + from the ANSI layout). We handle it by replacing its value by 0x32 in + the layout arrays. +*/ + +#include + +#define SHIFT 0x80 +#define ALT_GR 0xc0 +#define ISO_KEY 0x64 +#define ISO_REPLACEMENT 0x32 diff --git a/lib/Bad_Usb_Lib/USBHIDKeyboard.h b/lib/Bad_Usb_Lib/USBHIDKeyboard.h index 330d763e7..ce9bf5f27 100644 --- a/lib/Bad_Usb_Lib/USBHIDKeyboard.h +++ b/lib/Bad_Usb_Lib/USBHIDKeyboard.h @@ -113,6 +113,7 @@ typedef union { // Supported keyboard layouts extern const uint8_t KeyboardLayout_de_DE[]; extern const uint8_t KeyboardLayout_en_US[]; +extern const uint8_t KeyboardLayout_en_UK[]; extern const uint8_t KeyboardLayout_es_ES[]; extern const uint8_t KeyboardLayout_fr_FR[]; extern const uint8_t KeyboardLayout_it_IT[]; diff --git a/src/modules/others/bad_usb.cpp b/src/modules/others/bad_usb.cpp index 1bd4b5cc4..cbfdafb89 100644 --- a/src/modules/others/bad_usb.cpp +++ b/src/modules/others/bad_usb.cpp @@ -241,17 +241,17 @@ void usb_setup() { drawMainMenu(4); options = { - {"US Inter", [=]() { chooseKb(KeyboardLayout_en_US); }}, - {"PT-BR ABNT2", [=]() { chooseKb(KeyboardLayout_pt_BR); }}, - {"PT-PT", [=]() { chooseKb(KeyboardLayout_pt_PT); }}, - {"AZERTY FR", [=]() { chooseKb(KeyboardLayout_fr_FR); }}, - {"es-Espñol", [=]() { chooseKb(KeyboardLayout_es_ES); }}, - {"it-Italiano", [=]() { chooseKb(KeyboardLayout_it_IT); }}, - {"de-DE", [=]() { chooseKb(KeyboardLayout_de_DE); }}, - {"sv-SE", [=]() { chooseKb(KeyboardLayout_sv_SE); }}, - {"da-DK", [=]() { chooseKb(KeyboardLayout_da_DK); }}, - {"hu-HU", [=]() { chooseKb(KeyboardLayout_hu_HU); }}, - + {"US Inter", [=]() { chooseKb(KeyboardLayout_en_US); }}, + {"PT-BR ABNT2", [=]() { chooseKb(KeyboardLayout_pt_BR); }}, + {"PT-Portugal", [=]() { chooseKb(KeyboardLayout_pt_PT); }}, + {"AZERTY FR", [=]() { chooseKb(KeyboardLayout_fr_FR); }}, + {"es-Espanol", [=]() { chooseKb(KeyboardLayout_es_ES); }}, + {"it-Italiano", [=]() { chooseKb(KeyboardLayout_it_IT); }}, + {"en-UK", [=]() { chooseKb(KeyboardLayout_en_UK); }}, + {"de-DE", [=]() { chooseKb(KeyboardLayout_de_DE); }}, + {"sv-SE", [=]() { chooseKb(KeyboardLayout_sv_SE); }}, + {"da-DK", [=]() { chooseKb(KeyboardLayout_da_DK); }}, + {"hu-HU", [=]() { chooseKb(KeyboardLayout_hu_HU); }}, }; delay(200); loopOptions(options,false,true,"Keyboard Layout"); diff --git a/src/modules/rf/rf.cpp b/src/modules/rf/rf.cpp index bb447b99a..6fdb2dfdf 100644 --- a/src/modules/rf/rf.cpp +++ b/src/modules/rf/rf.cpp @@ -160,6 +160,7 @@ struct RfCodes { int te = 0; String filepath = ""; int Bit=0; + int BitRAW=0; }; @@ -256,6 +257,43 @@ void decimalToHexString(uint64_t decimal, char* output) { output[outputIndex] = '\0'; } +String hexStrToBinStr(const String& hexStr) { + String binStr = ""; + String hexByte = ""; + + // Variables for decimal value + int value; + + for (int i = 0; i < hexStr.length(); i++) { + char c = hexStr.charAt(i); + + // Check if the character is a hexadecimal digit + if (c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f') { + hexByte += c; + if (hexByte.length() == 2) { + // Convert the hexadecimal pair to a decimal value + value = strtol(hexByte.c_str(), NULL, 16); + + // Convert the decimal value to binary and add to the binary string + for (int j = 7; j >= 0; j--) { + binStr += (value & (1 << j)) ? '1' : '0'; + } + //binStr += ' '; + + // Clear the hexByte string for the next byte + hexByte = ""; + } + } + } + + // Remove the extra trailing space, if any + if (binStr.length() > 0 && binStr.charAt(binStr.length() - 1) == ' ') { + binStr.remove(binStr.length() - 1); + } + + return binStr; +} + static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) { static char bin[64]; unsigned int i=0; @@ -393,7 +431,40 @@ void RCSwitch_Read_Raw() { // ported from https://github.com/sui77/rc-switch/blob/3a536a172ab752f3c7a58d831c5075ca24fd920b/RCSwitch.cpp +void RCSwitch_RAW_Bit_send(int nTransmitterPin, RfCodes data) { + if (nTransmitterPin == -1) + return; + if (data.data == "") + return; + bool currentlogiclevel = false; + int nRepeatTransmit = 1; + for (int nRepeat = 0; nRepeat < nRepeatTransmit; nRepeat++) { + int currentBit = data.data.length(); + while(currentBit >= 0) { // Starts from the end of the string until the max number of bits to send + char c = data.data[currentBit]; + if(c=='1') { + currentlogiclevel = true; + } else if(c=='0') { + currentlogiclevel = false; + } else { + Serial.println("Invalid data"); + currentBit--; + continue; + //return; + } + digitalWrite(nTransmitterPin, currentlogiclevel ? HIGH : LOW); + delayMicroseconds(data.te); + + Serial.print(currentBit); + Serial.print("="); + Serial.println(currentlogiclevel); + + currentBit--; + } + digitalWrite(nTransmitterPin, LOW); + } +} void RCSwitch_RAW_send(int nTransmitterPin, int * ptrtransmittimings, struct Protocol protocol) { if (nTransmitterPin == -1) return; @@ -499,35 +570,43 @@ void sendRfCommand(struct RfCodes rfcode) { pinMode(RfTx, OUTPUT); if(protocol == "RAW") { + // count the number of elements of RAW_Data + int buff_size=0; + int index=0; + while(index>=0) { + index=data.indexOf(' ', index+1); + buff_size++; + } // alloc buffer for transmittimings - int* transmittimings = (int *) calloc(sizeof(int), data.length()); // should be smaller the data.length() + int* transmittimings = (int *) calloc(sizeof(int), buff_size+1); // should be smaller the data.length() size_t transmittimings_idx = 0; // split data into words, convert to int, and store them in transmittimings - String curr_word = ""; - int curr_val = 0; - for(int i=0; i