Updated version of the library to deal with the constructor without onUpdate callback function.
Fork of HC_SR04_Ultrasonic_Library by
Revision 5:abbb418bf10f, committed 2018-04-02
- Comitter:
- akabla
- Date:
- Mon Apr 02 15:16:16 2018 +0000
- Parent:
- 4:e0f9c9fb4cf3
- Commit message:
- Changes to allow the library to run without the updateMethod callback function specified in the constructor.
Changed in this revision
ultrasonic.cpp | Show annotated file Show diff for this revision Revisions of this file |
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); } }