test

Dependencies:   SDFileSystem USBHost_SAMPLE mbed

Committer:
USER10
Date:
Mon Nov 20 06:58:42 2017 +0000
Revision:
1:8ee1e5bda8ec
Parent:
0:dcbe65196984
Child:
2:15011081d5a3
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
USER10 0:dcbe65196984 1 #include "mbed.h"
USER10 0:dcbe65196984 2 #include "USBHostKeyboard.h"
USER10 0:dcbe65196984 3 #include "SDFileSystem.h"
USER10 0:dcbe65196984 4
USER10 0:dcbe65196984 5 DigitalOut led(LED1);
USER10 1:8ee1e5bda8ec 6 int i=0;
USER10 0:dcbe65196984 7 SDFileSystem sd(p5, p6, p7, p8, "sd");
USER10 0:dcbe65196984 8
USER10 0:dcbe65196984 9 Serial pc1(p13, p14);//tx1, rx1
USER10 0:dcbe65196984 10
USER10 0:dcbe65196984 11 void onKey(uint8_t key) {
USER10 1:8ee1e5bda8ec 12 pc1.printf("%c", key);
USER10 1:8ee1e5bda8ec 13
USER10 0:dcbe65196984 14
USER10 0:dcbe65196984 15 ++i;
USER10 0:dcbe65196984 16 FILE *fp;
USER10 0:dcbe65196984 17 fp = fopen("/sd/keylog/log.csv", "a");
USER10 0:dcbe65196984 18 fprintf(fp, "Key[%d], :,0x%x,:,%c\r\n", i, key, key);
USER10 0:dcbe65196984 19 fclose(fp);
USER10 1:8ee1e5bda8ec 20
USER10 0:dcbe65196984 21 }
USER10 0:dcbe65196984 22
USER10 0:dcbe65196984 23 void keyboard_task(void const *) {
USER10 0:dcbe65196984 24
USER10 0:dcbe65196984 25 USBHostKeyboard keyboard;
USER10 0:dcbe65196984 26
USER10 0:dcbe65196984 27 while(1) {
USER10 0:dcbe65196984 28 // try to connect a USB keyboard
USER10 0:dcbe65196984 29 while(!keyboard.connect())
USER10 0:dcbe65196984 30 Thread::wait(500);
USER10 0:dcbe65196984 31
USER10 0:dcbe65196984 32 // when connected, attach handler called on keyboard event
USER10 0:dcbe65196984 33 keyboard.attach(onKey);
USER10 0:dcbe65196984 34
USER10 0:dcbe65196984 35 // wait until the keyboard is disconnected
USER10 0:dcbe65196984 36 while(keyboard.connected())
USER10 0:dcbe65196984 37 Thread::wait(500);
USER10 0:dcbe65196984 38 }
USER10 0:dcbe65196984 39 }
USER10 0:dcbe65196984 40
USER10 0:dcbe65196984 41 int main() {
USER10 1:8ee1e5bda8ec 42
USER10 0:dcbe65196984 43 mkdir("/sd/keylog", 0777);
USER10 0:dcbe65196984 44 FILE *fp;
USER10 0:dcbe65196984 45 fp = fopen("/sd/keylog/log.csv","w");
USER10 0:dcbe65196984 46 fclose(fp);
USER10 0:dcbe65196984 47
USER10 1:8ee1e5bda8ec 48
USER10 0:dcbe65196984 49 Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
USER10 0:dcbe65196984 50 while(1) {
USER10 0:dcbe65196984 51 led=!led;
USER10 0:dcbe65196984 52 Thread::wait(500);
USER10 0:dcbe65196984 53 }
USER10 0:dcbe65196984 54 }