Comment already described

Dependencies:   SDFileSystem USBHost_SAMPLE mbed

Fork of USBHost_Test5 by USER PASS

Files at this revision

API Documentation at this revision

Comitter:
overover
Date:
Mon Nov 20 05:16:42 2017 +0000
Parent:
0:15908ba91581
Commit message:
????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 15908ba91581 -r 923fec2da9d4 main.cpp
--- a/main.cpp	Mon Nov 20 05:04:08 2017 +0000
+++ b/main.cpp	Mon Nov 20 05:16:42 2017 +0000
@@ -35,7 +35,56 @@
             Thread::wait(500);
     }
 }
+#include "mbed.h"
+#include "USBHostKeyboard.h"
+#include "SDFileSystem.h"
 
+DigitalOut led(LED1);
+int i=0;
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+Serial pc1(p13, p14);////シリアルポートのtx,rx
+
+void onKey(uint8_t key) {
+  pc1.printf("%c", key);
+
+    ++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);
+    }
+}
+
+int main() {
+  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);
+  }
+}
 int main() {
     mkdir("/sd/keylog", 0777);
     FILE *fp;