65 lines
1.3 KiB
C++
65 lines
1.3 KiB
C++
/*****************************************************************************
|
|
|
|
source::worx libPiGPio
|
|
Copyright © 2022 c.holzheuer
|
|
chris@sourceworx.org
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
Uses:
|
|
|
|
pigpiod_if2 by joan2937, pigpio @ abyz.me.uk
|
|
https://abyz.me.uk/rpi/pigpio
|
|
|
|
sigslot by 2017 Pierre-Antoine Lacaze
|
|
https://github.com/palacaze/sigslot
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
#ifndef PIGSONAR_H
|
|
#define PIGSONAR_H
|
|
|
|
#include <pignode.h>
|
|
#include <pigvalue.h>
|
|
#include <pigpin.h>
|
|
#include <pigchrono.h>
|
|
#include <pigvalue.h>
|
|
|
|
|
|
class LIBPIGPIO_EXPORT pigSonar : public pigNode, public pigValue<double>
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
pigSonar();
|
|
pigSonar( pigpio::bcm_t trigger, pigpio::bcm_t echo );
|
|
virtual ~pigSonar();
|
|
|
|
void init( pigpio::bcm_t trigger, pigpio::bcm_t echo );
|
|
|
|
void stop();
|
|
void start( double thresh = 50000 );
|
|
|
|
double distance( int timeout=10 );
|
|
|
|
protected:
|
|
|
|
pigPinOut _pinTrig;
|
|
pigPinIn _pinEcho;
|
|
|
|
pigChrono _timer;
|
|
double _dist;
|
|
uint32_t _now, _lst;
|
|
bool _active = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PIGSONAR_H
|