GY-63_MS5611/libraries/Radar/radar.h

80 lines
2.1 KiB
C
Raw Normal View History

2020-11-27 05:33:55 -05:00
#pragma once
2013-09-30 12:46:09 -04:00
//
// FILE: radar.h
// AUTHOR: Rob Tillaart
2021-12-27 14:23:58 -05:00
// VERSION: 0.1.6
2020-11-27 05:33:55 -05:00
// PURPOSE: Arduino library for a pan tilt radar.
// URL: https://github.com/RobTillaart/RADAR
2013-09-30 12:46:09 -04:00
2021-01-29 06:31:58 -05:00
2020-11-27 05:33:55 -05:00
#include "Arduino.h"
2013-09-30 12:46:09 -04:00
2021-12-27 14:23:58 -05:00
#define RADAR_LIB_VERSION (F("0.1.6"))
2021-05-28 07:42:27 -04:00
2021-01-29 06:31:58 -05:00
// TODO # positions in a begin() or constructor?
2020-11-27 05:33:55 -05:00
#ifndef RADAR_POSITIONS
2021-01-29 06:31:58 -05:00
#define RADAR_POSITIONS 10
2020-11-27 05:33:55 -05:00
#endif
2013-09-30 12:46:09 -04:00
2021-05-28 07:42:27 -04:00
2013-09-30 12:46:09 -04:00
class RADAR
{
2020-11-27 05:33:55 -05:00
public:
2021-01-29 06:31:58 -05:00
RADAR(const uint8_t pinPan, const uint8_t pinTilt);
2020-11-27 05:33:55 -05:00
// no valid range checking or negative value check.
2021-01-29 06:31:58 -05:00
void setPanPerSecond(float pps) { _panPerSecond = pps; };
float getPanPerSecond() { return _panPerSecond; };
2020-11-27 05:33:55 -05:00
void setTiltPerSecond(float tps) { _tiltPerSecond = tps; };
2021-01-29 06:31:58 -05:00
float getTiltPerSecond() { return _tiltPerSecond; };
2013-09-30 12:46:09 -04:00
2020-11-27 05:33:55 -05:00
// basic moves
void gotoPan(const int16_t pan);
int16_t getPan();
void gotoTilt(const int16_t tilt);
int16_t getTilt();
void gotoPanTilt(const int16_t pan, const int16_t tilt);
2013-09-30 12:46:09 -04:00
2020-11-27 05:33:55 -05:00
// memory positions - store / recall?
2021-01-29 06:31:58 -05:00
uint8_t getMaxPositions() { return RADAR_POSITIONS; };
2021-12-27 14:23:58 -05:00
bool setPosition(const uint8_t index, const int16_t pan, const int16_t tilt);
bool getPosition(const uint8_t index, int16_t & pan, int16_t & tilt);
bool gotoPosition(const uint8_t index);
2020-11-27 05:33:55 -05:00
void setHomePosition(const int16_t pan, const int16_t tilt);
void gotoHomePosition();
2013-09-30 12:46:09 -04:00
2020-11-27 05:33:55 -05:00
// feedback on positions.
2021-01-29 06:31:58 -05:00
bool isMoving() { return isPanMoving() || isTiltMoving(); };
bool isPanMoving() { return getPan() != _pan; };
2020-11-27 05:33:55 -05:00
bool isTiltMoving() { return getTilt() != _tilt; };
2013-09-30 12:46:09 -04:00
2021-01-29 06:31:58 -05:00
// TODO NIY
2020-11-27 05:33:55 -05:00
uint32_t ping();
uint32_t ping(const int16_t pan, const int16_t tilt);
2021-12-27 14:23:58 -05:00
2020-11-27 05:33:55 -05:00
private:
2021-01-29 06:31:58 -05:00
int16_t _pinPan;
int16_t _pinTilt;
2021-12-27 14:23:58 -05:00
2021-01-29 06:31:58 -05:00
int16_t _prevPan;
int16_t _pan;
int16_t _homePan;
uint32_t _lastPanTime;
2021-12-27 14:23:58 -05:00
2021-01-29 06:31:58 -05:00
int16_t _prevTilt;
int16_t _tilt;
int16_t _homeTilt;
uint32_t _lastTiltTime;
2021-12-27 14:23:58 -05:00
2021-01-29 06:31:58 -05:00
int16_t _panArray[RADAR_POSITIONS];
int16_t _tiltArray[RADAR_POSITIONS];
2020-11-27 05:33:55 -05:00
2021-01-29 06:31:58 -05:00
float _panPerSecond = 15;
float _tiltPerSecond = 15;
2013-09-30 12:46:09 -04:00
};
2021-05-28 07:42:27 -04:00
// -- END OF FILE --