팁 & 테크
안녕하세요.
제가 사용하는 Code에 대한 설명입니다.여기 저기서 찾은 것들을 섞어서 만든 것이라 원본이 어디였는지 모르겠네요.
링크된 Code가 rev2로 되어 있는 것으로 봐서는 많이 바뀐 것 같은데...
//-------------------------------------------------------------------
int scancodes[128] = {
0, // 0x00
120, // STOP
129, // 0x02 VOLUME DOWN
121, // AGAIN
128, // 0x04 VOLUME UP
...
이부분은 SUN 키보드에서 들어오는 Data를 ASC코드로 변환하는 Table입니다.
//-------------------------------------------------------------------#define KEYDOWN 0
#define KEYUP 1
int FN = 0;
int LED_state = 0;
int modifier_value = 0x00;
int keystate = KEYUP;
각종 define, 변수들
//-------------------------------------------------------------------
void toggle_LED_state(int bit) {
if(LED_state&(1<<bit)) {
LED_state &= ~(1<<bit);
} else {
LED_state |= (1<<bit);
}
Serial1.write(0x0e);
Serial1.write(LED_state);
}
CAPSLOCK, NUMLOCK, SCROLLLOCK 키에 대한 LED on/off
//-------------------------------------------------------------------
void setup() {
Serial1.begin(1200);
while (!Serial1) {
; // wait for serial port to connect. Needed for Leonardo only
}
Keyboard.begin();
}
Keyboard와 연결된 serial port 시작
usb keyboard 시작
//-------------------------------------------------------------------
void loop() {
// if there's any serial available, read it:
while (Serial1.available() > 0) {
unsigned char sun_code = Serial1.read();
keystate = (sun_code > 0x7f) ? KEYUP : KEYDOWN;
sun_code &= 0x7f;
int asc_code = scancodes[sun_code];
if (asc_code <= 119) {
asc_code +=136;
}
if(sun_code == 0x7f) {
Keyboard.releaseAll();
} else {
if(keystate == KEYDOWN) {
Keyboard.press(asc_code);
} else {
Keyboard.release(asc_code);
}
}
시리얼 포트로 data가 올때 마다 분석하고, USB Keyboar data로 변환.
입력 Data가 127 이하이면 키가 눌린 것이고 128이상이면 반대.
입력 Data가 127이면 아무키도 안 눌림.
HHKB Pro2
Poker II
Poker X
Minila Air
Noppoo Choc mini
B.thumb 커스텀
G84-4100
와우, 귀한 소스인듯. 그런데 어렵습니다. 아두이노에 넣는 코드 맞지요? 선키보드에 대한 관심이 증폭되길 바랄께요^^