GY-63_MS5611/libraries/HeartBeat/HeartBeat.h

116 lines
2.5 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: HeartBeat.h
// AUTHOR: Rob Tillaart
2022-11-09 04:31:43 -05:00
// VERSION: 0.3.2
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library for HeartBeat with frequency and dutyCycle
// DATE: 2019-06-12
// URL: https://github.com/RobTillaart/HeartBeat
#include "Arduino.h"
2022-11-09 04:31:43 -05:00
#define HEARTBEAT_LIB_VERSION (F("0.3.2"))
2021-11-02 12:26:51 -04:00
2021-01-29 06:31:58 -05:00
class HeartBeat
{
public:
2022-07-27 06:53:36 -04:00
// CONSTRUCTOR
2021-01-29 06:31:58 -05:00
HeartBeat();
2021-11-02 12:26:51 -04:00
void begin(const uint8_t pin, float frequency = 1.0);
2022-02-05 10:53:02 -05:00
2022-07-27 06:53:36 -04:00
// CONFIGURATION
2021-11-02 12:26:51 -04:00
void setFrequency(float frequency = 1.0);
void setDutyCycle(float dutyCycle = 50);
2022-07-27 06:53:36 -04:00
float getFrequency();
float getDutyCycle();
2021-01-29 06:31:58 -05:00
2022-07-27 06:53:36 -04:00
// START STOP interface
void enable();
void disable();
bool isEnabled();
2021-01-29 06:31:58 -05:00
2022-07-27 06:53:36 -04:00
// WORKER
2021-11-02 12:26:51 -04:00
void beat();
2022-07-27 06:53:36 -04:00
uint8_t getState();
2021-01-29 06:31:58 -05:00
protected:
void _setFreqDuty();
2021-11-02 12:26:51 -04:00
float _frequency = 1.0;
float _dutyCycle = 50;
uint32_t _lastHeartBeat = 0;
uint32_t _dutyCycleHigh = 500;
uint32_t _dutyCycleLow = 500;
bool _running = false;
uint8_t _pin = 255;
uint8_t _state = LOW;
2021-01-29 06:31:58 -05:00
};
2021-05-28 07:30:27 -04:00
2022-02-05 10:53:02 -05:00
/////////////////////////////////////////////////////////////////////////////
//
// HEARTBEATDIAG
//
class HeartBeatDiag : public HeartBeat
{
public:
2022-07-27 06:53:36 -04:00
// CONSTRUCTOR
2022-02-05 10:53:02 -05:00
HeartBeatDiag();
2022-07-27 06:53:36 -04:00
// WORKER
2022-02-05 10:53:02 -05:00
void beat();
2022-07-27 06:53:36 -04:00
// CONFIGURATION PATTERN
2022-02-05 10:53:02 -05:00
// pattern = up to 9 digits, indicating the relative length of the pulses
// of the error or diagnostic code
2022-07-27 06:53:36 -04:00
bool code(uint32_t pattern); // executes ONE time
void codeOff(); // explicit stop.
2022-02-05 10:53:02 -05:00
protected:
uint32_t _code = 0; // up to 9 digits
uint32_t _codeMask = 0; // to extract the bit value from code
uint8_t _codeStart = 0; // force starting with LOW
uint8_t _pulseLength = 0; // to track length of current pulse
};
/////////////////////////////////////////////////////////////////////////////
//
// HEARTBEATSL (simpler, has a smaller footprint as HeartBeatDiag
//
class HeartBeatSL : public HeartBeat
{
public:
2022-07-27 06:53:36 -04:00
// CONSTRUCTOR
2022-02-05 10:53:02 -05:00
HeartBeatSL();
2022-07-27 06:53:36 -04:00
// WORKER
2022-02-05 10:53:02 -05:00
void beat();
2022-07-27 06:53:36 -04:00
// CONFIGURATION PATTERN
2022-02-05 10:53:02 -05:00
// str = string of L (long) and S or non-L (short) characters.
// L is a pulse of 3 units, S is a pulse of 1 unit.
2022-07-27 06:53:36 -04:00
bool code(const char * str); // executes ONE time
void codeOff(); // explicit stop.
2022-02-05 10:53:02 -05:00
protected:
uint8_t _code = 0; // up to 7 bits
uint8_t _codeMask = 0; // to extract the bit value from code
uint8_t _codeStart = 0; // force starting with LOW
uint8_t _pulseLength = 0; // to track length of current pulse
};
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2022-02-05 10:53:02 -05:00