Library for the LidarLite, gets distance in cm using the pwm output

Dependents:   LidarLite_test

Fork of MaxbotixDriver by Daniel Casner

Files at this revision

API Documentation at this revision

Comitter:
joe4465
Date:
Wed Mar 18 09:17:13 2015 +0000
Parent:
1:32f0a592b9e5
Child:
3:0b1f4404cb21
Commit message:
V1.1 Internal timer

Changed in this revision

LidarLitePwm.cpp Show annotated file Show diff for this revision Revisions of this file
LidarLitePwm.h Show annotated file Show diff for this revision Revisions of this file
--- a/LidarLitePwm.cpp	Wed Mar 18 08:55:54 2015 +0000
+++ b/LidarLitePwm.cpp	Wed Mar 18 09:17:13 2015 +0000
@@ -1,11 +1,16 @@
 #include "LidarLitePwm.h"
 
-LidarLitePwm::LidarLitePwm(PinName pin, Timer& timer) : _interrupt(pin), _timer(timer), _pulseStartTime(0), _range(0)
+LidarLitePwm::LidarLitePwm(PinName pin) : _interrupt(pin)
 {
+    _pulseStartTime = 0;
+    _range = 0;
+    _timer.start();
     _interrupt.rise(this, &LidarLitePwm::pulseStart);
     _interrupt.fall(this, &LidarLitePwm::pulseStop);
 }
 
+LidarLitePwm::~LidarLitePwm(){}
+
 int LidarLitePwm::read()
 {
     return _range;
--- a/LidarLitePwm.h	Wed Mar 18 08:55:54 2015 +0000
+++ b/LidarLitePwm.h	Wed Mar 18 09:17:13 2015 +0000
@@ -6,7 +6,8 @@
 class LidarLitePwm
 {
   public:
-    LidarLitePwm(PinName input, Timer& timer);
+    LidarLitePwm(PinName input);
+    ~LidarLitePwm();
     
     /// Returns range in cm as int
     int read();
@@ -15,6 +16,7 @@
     operator int();
     
   private:
+
     /// Inturrupt at start of pulse
     void pulseStart();
     /// Interrupt at end of pulse
@@ -22,8 +24,8 @@
     
     /// Interrupt driver for the input pin
     InterruptIn _interrupt;
-    /// Reference to global timer instance
-    Timer& _timer;
+    /// Timer
+    Timer _timer;
     /// Time of the start of the current pulse
     int _pulseStartTime;
     /// The most recent sample