t
Dependencies: SDFileSystem USBHost_SAMPLE mbed
Fork of USBHost_TEST by
Diff: main.cpp
- Revision:
- 4:418f1273cf02
- Parent:
- 3:df84dd8c122c
- Child:
- 5:cafe4eec6398
diff -r df84dd8c122c -r 418f1273cf02 main.cpp --- a/main.cpp Thu Nov 16 00:20:03 2017 +0000 +++ b/main.cpp Mon Nov 20 06:08:18 2017 +0000 @@ -4,48 +4,56 @@ DigitalOut led(LED1); SDFileSystem sd(p5, p6, p7, p8, "sd"); + int i=0; +float Ktime_val=0; -Serial pc2(p13, p14);//tx1, rx1 +Timer k_time; //初期化 + +Serial pc1(p13, p14);////シリアルポートのtx,rx void onKey(uint8_t key) { - pc2.printf("%c", key); + pc1.printf("%c", key); + + if(i!=0){ + k_time.stop(); + Ktime_val=k_time.read_ms(); + } - ++i; - FILE *fp; - fp = fopen("/sd/keylog/log.csv", "a"); - fprintf(fp, "Key[%d], :,0x%x,:,%c\r\n", i, key, key); - fclose(fp); - + ++i; + FILE *fp; + fp = fopen("/sd/keylog/log.csv", "a"); //SDカード内のkeylogフォルダの中にcsvファイルを追記形式で開く(新規作成) + fprintf(fp, "Key[%d], :,0x%x,:,%c\r\n", i, key, key); //押した順番(i):押したキーのキーコード(key):押したキーの文字(key) + fclose(fp); //ファイルを閉じる } - void keyboard_task(void const *) { - - USBHostKeyboard keyboard; - - while(1) { - // try to connect a USB keyboard - while(!keyboard.connect()) - Thread::wait(500); - - // when connected, attach handler called on keyboard event - keyboard.attach(onKey); - - // wait until the keyboard is disconnected - while(keyboard.connected()) - Thread::wait(500); - } + + USBHostKeyboard keyboard; + + while(1) { + // try to connect a USB keyboard + while(!keyboard.connect()) + Thread::wait(500); + + // when connected, attach handler called on keyboard event + keyboard.attach(onKey); + + // wait until the keyboard is disconnected + while(keyboard.connected()) + Thread::wait(500); + } } int main() { - mkdir("/sd/keylog", 0777); - FILE *fp; - fp = fopen("/sd/keylog/log.csv","w"); - fclose(fp); - - Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4); - while(1) { - led=!led; - Thread::wait(500); - } -} + mkdir("/sd/keylog", 0777); + FILE *fp; + fp = fopen("/sd/keylog/log.csv","w"); //csvを書き込み形式で開く + fclose(fp); //ファイルを閉じる + + Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4); + + while(1) { + led=!led; + Thread::wait(500); + } +} \ No newline at end of file