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.
Diff: sensors/sensors.cpp
- Revision:
- 39:7f3cc8f47710
- Parent:
- 36:e1398ff45b12
- Child:
- 42:b00cdc97f492
--- a/sensors/sensors.cpp	Wed May 15 09:57:11 2019 +0000
+++ b/sensors/sensors.cpp	Wed May 15 12:53:14 2019 +0000
@@ -53,6 +53,7 @@
 LocalFileSystem local("local");
 const char kFileName[] = "/local/sensors.csv";
 Timer filetimer;
+void FileCloseFiltered();
 
 int FileOpen() //1:異常終了
 {
@@ -66,10 +67,10 @@
     filetimer.start();
     if(RightOrLeft) {
         //rightなら
-        switch_LR.fall(FileClose);//left(0)にしたらclose
+        switch_LR.fall(FileCloseFiltered);//left(0)にしたらclose
     } else {
         //left
-        switch_LR.rise(FileClose);//left(0)にしたらclose
+        switch_LR.rise(FileCloseFiltered);//left(0)にしたらclose
     }
     return 0;
 }
@@ -96,6 +97,23 @@
     if(fp != NULL)
         fclose(fp);
 };
+void FileCloseFiltered()
+{
+    //チャタリング防止
+    int is_ok = 0;
+    wait(0.1);
+    if(RightOrLeft) {
+        //rightなら
+        is_ok = (switch_LR == 0);
+    } else {
+        //left
+        is_ok = (switch_LR == 1);
+    }
+    if(is_ok != 1) {
+        return;
+    }
+    FileClose();
+}
 
 
 
@@ -111,7 +129,7 @@
 }
 float GetFilteredDist_cm(HCSR04 & sensor, LowPassFilter & filter)
 {
-    wait_ms(90);//60
+    wait_ms(60);//60
     sensor.start();
     wait_ms(30);
     float raw_data = sensor.get_dist_cm();
@@ -167,8 +185,8 @@
 
     hcsr04_val[1] = GetFilteredDist_cm(sensor_back,lowpassfilter[1]);
     FileWrite();
-    int is_ok = checkUW(hcsr04_val[1], degree0*kDeg2Rad, ec_li.getCount());//ECは内側を選んだ.適当
-    if(is_ok != 1) {
+    int is_out = checkUW(hcsr04_val[1], degree0*kDeg2Rad, ec_li.getCount());//ECは内側を選んだ.適当
+    if(is_out == 1) {
         //もう一度とる
         sensor_back.start();
         wait_ms(50);