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 mbed
Revision 1:16af9125437f, committed 2018-01-24
- Comitter:
- USER10
- Date:
- Wed Jan 24 09:54:28 2018 +0000
- Parent:
- 0:c6745d5554d1
- Commit message:
- mbed_HOST; ;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jan 19 00:31:45 2018 +0000
+++ b/main.cpp Wed Jan 24 09:54:28 2018 +0000
@@ -1,6 +1,6 @@
#include "mbed.h"
#include "USBHostKeyboard.h"
-//#include "SDFileSystem.h"
+#include "SDFileSystem.h"
//キーボード取得データをTX1、RX1からシリアル通信で送信させる
//SDカードに入力したデータを保存
@@ -11,27 +11,23 @@
DigitalOut led2(LED2);
DigitalOut led3(LED3);
-int i=0;
-
Timer t; //タイマー宣言(繰り返しタイマー割り込み)
-LocalFileSystem local("keylog"); //mbed自体に保存
-//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SDファイル用通信ポートの指定
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SDファイル用通信ポートの指定
Serial pc1(p13, p14); //シリアル通信ポートの指定(tx1, rx1の順)
-//Serial pc(USBTX, USBRX);
void onKey(uint8_t key) {
pc1.printf("%c", key); //1文字PCへ送信(TX1、RX1のシリアル通信)
- //pc.printf("%c", key);
- i++;
+
t.stop(); //キーを押すごとにタイマーストップ
//リセットしていないのでラップタイム計測状態となる
FILE *fp;
- fp = fopen("/keylog/keylog/log.csv", "a"); //「log.csv」ファイルを書き込み形式で開く
- fprintf(fp, "Key[%d], :,0x%x,:,%c,:,%0.2f\r\n", i, key, key, t.read()); //左から 入力順番:アスキーコード:入力した文字:経過時間 となる
+ fp = fopen("/sd/keylog/log.csv", "a"); //「keylog」ディレクトリ内の「log.csv」ファイルを書き込み形式で開く
+ fprintf(fp, "Key,:,0x%x,:,%c,:,%0.2f\r\n", key, key, t.read()); //左から 入力順番:アスキーコード:入力した文字:経過時間 となる
fclose(fp);
t.start(); //タイマースタート(一周後からはリスタート)
+
}
void keyboard_task(void const *) {
@@ -49,11 +45,12 @@
}
}
-int main(){
-
- mkdir("/keylog/keylog", 0777); //「keylog」ディレクトリ作成
- FILE *fp;
- fp = fopen("/keylog/keylog/log.csv","w"); //「log.csv」ファイルを読込形式で開く
+int main(){
+ mkdir("/sd/keylog", 0777); //「keylog」ディレクトリ作成
+ FILE *fp = fopen("/sd/keylog/log.csv","w"); //「log.csv」ファイルを読込形式で開く
+ if(fp == NULL) {
+ error("Could not open file for write\n"); //この行がないと不具合が発生
+ }
fclose(fp);
Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);