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:
- 12:cf8af0b4e0d2
- Parent:
- 11:0dafbbb3a686
- Child:
- 15:bc4f8c597c26
--- a/laser.cpp Tue Dec 22 04:22:12 2015 +0000
+++ b/laser.cpp Mon Oct 17 04:50:33 2016 +0000
@@ -7,6 +7,15 @@
{
}
+void Laser::discardResponse()
+{
+ // char c = 0;
+ wait_ms(20); // wait for the response
+ while(serial.readable()) {
+ serial.getc();
+ }
+}
+
void Laser::triggerDistanceMeasurement()
{
char cmd[] = "0 -1 10 doMeasDistExt\n"; // single reading averaged over 10 measurements
@@ -75,19 +84,28 @@
void Laser::enableMeasurement(bool enable)
{
- if (enable)
+ if (enable) {
sendCommand(";\n");
- else
+ discardResponse();
+
+ } else {
sendCommand("switchMeasOff\n");
+ discardResponse();
+ }
}
void Laser::setRedDot(bool on)
{
if(on) {
- char cmd[] = "0 -1 10 doMeasDistExt\n"; // doing a measurement turns the redDot on
+ char cmd[] = "0 -1 5 doMeasDistExt\n"; // doing a measurement turns the redDot on
sendCommand(cmd);
- } else
+ wait_ms(120); // take a while for a response for to measurement command
+ discardResponse();
+ // triggerDistanceMeasurement();
+ } else {
sendCommand("switchMeasOff\n");
+ discardResponse();
+ }
}
void Laser::split(char str[], char c, std::vector<char*>& v)
