back up of work during May 2019

Dependencies:   microbit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bitboard.cpp Source File

bitboard.cpp

00001 #include "bitboard.h"
00002 
00003 bitboard::bitboard(/**MicroBit &_uBit,**/ BLE &_ble, KeyboardService* _kbdServicePtr, const char* _DEVICE_NAME, const char* _SHORT_DEVICE_NAME): /**uBit(_uBit),**/ ble(_ble), kbdServicePtr(_kbdServicePtr), DEVICE_NAME(_DEVICE_NAME), SHORT_DEVICE_NAME(_SHORT_DEVICE_NAME){
00004     Buffer = 0; //might change data type to allow for multi keypress
00005     }
00006 
00007 bitboard::~bitboard(){
00008     delete DEVICE_NAME;
00009     delete SHORT_DEVICE_NAME;
00010     }
00011 
00012 void bitboard::init(){
00013 //    uBit.init();
00014 //    uBit.serial.send("uBit init...\r\n");
00015 //    uBit.serial.send("BLE init...\r\n");
00016     ble.init();
00017     
00018     ble.gap().onDisconnection(this, &bitboard::onDisconnect);
00019     ble.gap().onConnection(this, &bitboard::onConnect);
00020 //    uBit.serial.send("Security init...\r\n");
00021     initializeSecurity(ble);
00022     
00023     KeyboardService kbdService(ble);
00024     kbdServicePtr = &kbdService;
00025 //    uBit.serial.send("HOGP init...\r\n");
00026     initializeHOGP(ble);
00027     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::KEYBOARD);
00028     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
00029     ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (uint8_t *)SHORT_DEVICE_NAME, sizeof(SHORT_DEVICE_NAME));
00030     ble.gap().setDeviceName((const uint8_t *)DEVICE_NAME);
00031 //    uBit.serial.send("advertising...\r\n");
00032     ble.gap().startAdvertising();
00033     }
00034 
00035 void bitboard::onDisconnect(const Gap::DisconnectionCallbackParams_t *params){
00036     ble.gap().startAdvertising(); // restart advertising
00037 //    uBit.serial.send("Disconnected, advertising...\r\n");
00038     }
00039 
00040 void bitboard::onConnect(const Gap::ConnectionCallbackParams_t *params){
00041 //    uBit.serial.send("Connected...\r\n");
00042     }
00043 
00044 void bitboard::onButtonA(MicroBitEvent e){
00045 //    uBit.display.print("A");
00046 //    uBit.serial.send("Button A pressed");
00047 //    uBit.serial.send(e.value);
00048     }
00049 
00050 void bitboard::send_keypress(){
00051     inputReportData[0] = 0;
00052     inputReportData[2] = Buffer;
00053     kbdServicePtr->send(inputReportData);
00054     kbdServicePtr->send(emptyInputReportData);
00055     wait(0.1);
00056     }
00057 uint8_t bitboard::get_keycode(char c){
00058       switch (c){
00059         case 'A':
00060         case 'a':
00061             return 0x04;
00062         case 'B':
00063         case 'b':
00064             return 0x05;
00065         case 'C':
00066         case 'c':
00067             return 0x06;
00068         case 'D':
00069         case 'd':
00070             return 0x07;
00071         case 'E':
00072         case 'e':
00073             return 0x08;
00074         case 'F':
00075         case 'f':
00076             return 0x09;
00077         case 'G':
00078         case 'g':
00079             return 0x0a;
00080         case 'H':
00081         case 'h':
00082             return 0x0b;
00083         case 'I':
00084         case 'i':
00085             return 0x0c;
00086         case 'J':
00087         case 'j':
00088             return 0x0d;
00089         case 'K':
00090         case 'k':
00091             return 0x0e;
00092         case 'L':
00093         case 'l':
00094             return 0x0f;
00095         case 'M':
00096         case 'm':
00097             return 0x10;
00098         case 'N':
00099         case 'n':
00100             return 0x11;
00101         case 'O':
00102         case 'o':
00103             return 0x12;
00104         case 'P':
00105         case 'p':
00106             return 0x13;
00107         case 'Q':
00108         case 'q':
00109             return 0x14;
00110         case 'R':
00111         case 'r':
00112             return 0x15;
00113         case 'S':
00114         case 's':
00115             return 0x16;
00116         case 'T':
00117         case 't':
00118             return 0x17;
00119         case 'U':
00120         case 'u':
00121             return 0x18;
00122         case 'V':
00123         case 'v':
00124             return 0x19;
00125         case 'W':
00126         case 'w':
00127             return 0x1a;
00128         case 'X':
00129         case 'x':
00130             return 0x1b;
00131         case 'Y':
00132         case 'y':
00133             return 0x1c;
00134         case 'Z':
00135         case 'z':
00136             return 0x1d;
00137         case '!':
00138         case '1':
00139             return 0x1e;
00140         case '@':
00141         case '2':
00142             return 0x1f;
00143         case '#':
00144         case '3':
00145             return 0x20;
00146         case '$':
00147         case '4':
00148             return 0x21;
00149         case '%':
00150         case '5':
00151             return 0x22;
00152         case '^':
00153         case '6':
00154             return 0x23;
00155         case '&':
00156         case '7':
00157             return 0x24;
00158         case '*':
00159         case '8':
00160             return 0x25;
00161         case '(':
00162         case '9':
00163             return 0x26;
00164         case ')':
00165         case '0':
00166             return 0x27;
00167         case '\n': // LF
00168             return 0x28;
00169         case '\b': // BS
00170             return 0x2a;
00171         case '\t': // TAB
00172             return 0x2b;
00173         case ' ':
00174             return 0x2c;
00175         case '_':
00176         case '-':
00177             return 0x2d;
00178         case '+':
00179         case '=':
00180             return 0x2e;
00181         case '{':
00182         case '[':
00183             return 0x2f;
00184         case '}':
00185         case ']':
00186             return 0x30;
00187         case '|':
00188         case '\\':
00189             return 0x31;
00190         case ':':
00191         case ';':
00192             return 0x33;
00193         case '"':
00194         case '\'':
00195             return 0x34;
00196         case '~':
00197         case '`':
00198             return 0x35;
00199         case '<':
00200         case ',':
00201             return 0x36;
00202         case '>':
00203         case '.':
00204             return 0x37;
00205         case '?':
00206         case '/':
00207             return 0x38;
00208         default:
00209             return 0;
00210     }
00211 }