Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem USBHost_SAMPLE mbed
Fork of Production_ver1_0 by
main.cpp
- Committer:
- SampleProgram
- Date:
- 2017-11-07
- Revision:
- 2:c34453addfec
- Parent:
- 0:e91bd159d16f
- Child:
- 3:df84dd8c122c
File content as of revision 2:c34453addfec:
#include "mbed.h"
#include "USBHostKeyboard.h"
#include "SDFileSystem.h"
DigitalOut led(LED1);
SDFileSystem sd(p5, p6, p7, p8, "sd");
int i=0;
void onKey(uint8_t key) {
printf("Key: 0x%x : %c\r\n", key, key);
++i;
FILE *fp;
fp = fopen("/sd/keylog/keylog.csv", "a");
fprintf(fp, "Keydata[%d], :,0x%x,:,%c\r\n", 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/keylog.csv","w");
fclose(fp);
Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
while(1) {
led=!led;
Thread::wait(500);
}
}
