Updated version of the library to deal with the constructor without onUpdate callback function.

Fork of HC_SR04_Ultrasonic_Library by EJ Teb

Revision:
5:abbb418bf10f
Parent:
4:e0f9c9fb4cf3
diff -r e0f9c9fb4cf3 -r abbb418bf10f ultrasonic.cpp
--- a/ultrasonic.cpp	Mon Nov 24 20:23:07 2014 +0000
+++ b/ultrasonic.cpp	Mon Apr 02 15:16:16 2018 +0000
@@ -2,8 +2,10 @@
     
     ultrasonic::ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout):_trig(trigPin), _echo(echoPin)
     {
+        _onUpdateMethod=NULL;
         _updateSpeed = updateSpeed;
         _timeout = timeout;
+        _t.start ();
     }
     
     ultrasonic::ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int))
@@ -81,6 +83,6 @@
     {
         if(isUpdated())
         {
-            (*_onUpdateMethod)(_distance);
+            if (_onUpdateMethod) (*_onUpdateMethod)(_distance);
         }
     }