Last active
November 21, 2021 06:35
-
-
Save shikarunochi/f5e0256732a04ff94243b3016d9373d8 to your computer and use it in GitHub Desktop.
AtomLite + AtomDisplay + Bluetooth Keyboard TEST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5Atom.h> | |
#include <M5AtomDisplay.h> | |
#include "hid_server/hid_server.h" | |
M5AtomDisplay display; | |
void setup() { | |
M5.begin(); | |
display.init(); | |
// Set the display orientation | |
display.setRotation(0); | |
display.setCursor(0,0); | |
display.setTextSize(2); | |
display.setFont(&fonts::lgfxJapanGothic_32); | |
Serial.println("hidStart"); | |
hid_init("emu32"); | |
Serial.println("hidStart:OK"); | |
} | |
void gui_msg(const char* msg) | |
{ | |
Serial.println(msg); | |
} | |
void sys_msg(const char* msg) { | |
Serial.println(msg); | |
display.print(msg); | |
} | |
void loop(){ | |
hid_update(); | |
uint8_t buf[64]; | |
int n = hid_get(buf,sizeof(buf)); | |
if (n > 0){ | |
gui_hid(buf,n); | |
} | |
delay(10); | |
} | |
void gui_hid(const uint8_t* hid, int len) // Parse HID event | |
{ | |
if (hid[0] != 0xA1) | |
return; | |
switch (hid[1]) { | |
case 0x01: keyboard(hid+1,len-1); break; // parse keyboard and maintain 1 key state | |
// case 0x32: wii(); break; // parse wii stuff: generic? | |
// case 0x42: ir(hid+2,len); break; // ir joy | |
} | |
} | |
String stringData[] = { | |
" "," "," "," ", | |
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z", | |
"1","2","3","4","5","6","7","8","9","0" | |
}; | |
String stringShiftData[] = { | |
" "," "," "," ", | |
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z", | |
"!","\"","#","$","%","&","'","(",")"," " | |
}; | |
static int _last_key = 0; | |
//https://wiki.onakasuita.org/pukiwiki/?HID%2F%E3%82%AD%E3%83%BC%E3%82%B3%E3%83%BC%E3%83%89 | |
static void keyboard(const uint8_t* d, int len) | |
{ | |
int mods = d[1]; | |
int key_code = d[3]; // only care about first key | |
if (key_code != _last_key) { | |
if (key_code) { | |
_last_key = key_code; | |
} else { | |
_last_key = 0; | |
} | |
Serial.printf("mods:%d keyCode:%d\n",mods,key_code); | |
if(key_code > 0 && key_code <=39){ | |
if(mods == 0){ | |
display.print(stringData[key_code]); | |
}else{ | |
display.print(stringShiftData[key_code]); | |
} | |
}else if(key_code==40){ //改行 | |
display.println(); | |
}else if(key_code==44){ //スペース | |
display.println(" "); | |
}else if(key_code==42){ //DELETEで全部消す | |
display.clearDisplay(); | |
display.setCursor(0,0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment