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: BLE_API mbed nRF51822
Fork of MCS_LRF by
Diff: laser.cpp
- Revision:
- 10:d37cd13dd529
- Parent:
- 8:ed66e7ef8243
- Child:
- 11:0dafbbb3a686
diff -r afd6bd6e88bd -r d37cd13dd529 laser.cpp
--- a/laser.cpp	Thu Dec 17 01:12:17 2015 +0000
+++ b/laser.cpp	Tue Dec 22 03:46:12 2015 +0000
@@ -7,93 +7,6 @@
 {
 }
 
-//float Laser::getDistance()
-//{
-//    float distance = -1.0;
-//    const int bufSize = 50;
-//    char data[bufSize];
-//    int i = 0;
-//    //char cmd[] = ";\n";
-//    char cmd[] = "0 -1 10 doMeasDistExt\n";   // single reading averaged over 10 measurements
-//    //char cmd[] = "0 -1 -1 doMeasDistExt\n";     // single reading of single measurement
-//
-//    if (sendCommand(cmd) == true) {
-//        // Note: Need to actually read from the serial to clear the RX interrupt
-//        char c = 0;
-//        uint16_t count = 0;
-//        do {
-//            if(serial.readable()) {
-//                c = serial.getc();
-//                data[i++] = c;
-//            }
-//            else{wait_us(100);}
-//        } while (c != '\n' && i < bufSize && count++ < 5000);  // timeout after about 500ms and ensure no overflow
-//
-//        if (count >= 5000 || i >= bufSize) return -2.0;  // timeout or overflow
-//
-//        // now that we have the reply parse it
-//        data[i - 1] = 0;        // null terminate the string
-//
-//        //reply is in this form '2 0 1844364 324 Reply'. 2nd number is error code, 3rd number is distance in um, 4th number is measurement signal
-//        vector<char*> v;
-//        split(data, ' ', v);
-//
-//        if (v.size() != 6 || atoi(v[1]) != 0 || strcmp(v[5], "Reply") != 0) {
-//            // there is an error
-//            distance = -1.0;
-//        } else {
-//            distance = atoi(v[2]) / 1000000.0; // distance in m
-//        }
-//    }
-//
-//    return distance;
-//}
-
-float Laser::getDistance()
-{
-    // enableMeasurement(true);
-
-    float distance = -4.0;
-    const int bufSize = 50;
-    char data[bufSize];
-    int i = 0;
-    //char cmd[] = ";\n";
-    char cmd[] = "0 -1 10 doMeasDistExt\n";   // single reading averaged over 10 measurements
-    //char cmd[] = "0 -1 -1 doMeasDistExt\n";     // single reading of single measurement
-
-    if (sendCommand(cmd) == true) {
-        // Note: Need to actually read from the serial to clear the RX interrupt
-        char c = 0;
-        uint16_t count = 0;
-        do {
-            if(serial.readable()) {
-                c = serial.getc();
-                data[i++] = c;
-            } else {
-                wait_us(100);
-            }
-        } while (c != '\n' && i < bufSize && count++ < 5000);  // timeout after about 500ms and ensure no overflow
-
-        if (count >= 5000 || i >= bufSize) return -2.0;  // timeout or overflow
-
-        // now that we have the reply parse it
-        data[i - 1] = 0;        // null terminate the string
-
-        //reply is in this form '2 0 1844364 324 Reply'. 2nd number is error code, 3rd number is distance in um, 4th number is measurement signal
-        vector<char*> v;
-        split(data, ' ', v);
-
-        if (v.size() != 6 || atoi(v[1]) != 0 || strcmp(v[5], "Reply") != 0) {
-            // there is an error
-            distance = -3.0;
-        } else {
-            distance = atoi(v[2]) / 1000000.0; // distance in m
-        }
-    }
-
-    return distance;
-}
-
 void Laser::triggerDistanceMeasurement()
 {
     char cmd[] = "0 -1 10 doMeasDistExt\n";   // single reading averaged over 10 measurements
@@ -163,7 +76,16 @@
     if (enable)
         sendCommand(";\n");
     else
-        sendCommand("switchMeasOff");
+        sendCommand("switchMeasOff\n");
+}
+
+void Laser::setRedDot(bool on)
+{
+    if(on) {
+        char cmd[] = "0 -1 10 doMeasDistExt\n";     // doing a measurement turns the redDot on
+        sendCommand(cmd);
+    } else
+        sendCommand("switchMeasOff\n");
 }
 
 bool Laser::sendCommand(char cmd[])
@@ -287,3 +209,49 @@
 {
     enableMeasurement(false);
 }
+
+
+
+//float Laser::getDistance()
+//{
+//    float distance = -4.0;
+//    const int bufSize = 50;
+//    char data[bufSize];
+//    int i = 0;
+//    //char cmd[] = ";\n";
+//    char cmd[] = "0 -1 10 doMeasDistExt\n";   // single reading averaged over 10 measurements
+//    //char cmd[] = "0 -1 -1 doMeasDistExt\n";     // single reading of single measurement
+//
+//    if (sendCommand(cmd) == true) {
+//        // Note: Need to actually read from the serial to clear the RX interrupt
+//        char c = 0;
+//        uint16_t count = 0;
+//        do {
+//            if(serial.readable()) {
+//                c = serial.getc();
+//                data[i++] = c;
+//            } else {
+//                wait_us(100);
+//            }
+//        } while (c != '\n' && i < bufSize && count++ < 5000);  // timeout after about 500ms and ensure no overflow
+//
+//        if (count >= 5000 || i >= bufSize) return -2.0;  // timeout or overflow
+//
+//        // now that we have the reply parse it
+//        data[i - 1] = 0;        // null terminate the string
+//
+//        //reply is in this form '2 0 1844364 324 Reply'. 2nd number is error code, 3rd number is distance in um, 4th number is measurement signal
+//        vector<char*> v;
+//        split(data, ' ', v);
+//
+//        if (v.size() != 6 || atoi(v[1]) != 0 || strcmp(v[5], "Reply") != 0) {
+//            // there is an error
+//            distance = -3.0;
+//        } else {
+//            distance = atoi(v[2]) / 1000000.0; // distance in m
+//        }
+//    }
+//
+//    return distance;
+//}
+
    