2020-11-27 05:28:57 -05:00
|
|
|
#pragma once
|
2017-07-16 10:01:09 -04:00
|
|
|
//
|
2013-09-30 12:38:54 -04:00
|
|
|
// FILE: PulsePattern.h
|
2017-07-16 10:01:09 -04:00
|
|
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
2022-11-22 11:20:26 -05:00
|
|
|
// VERSION: 0.1.6
|
2020-11-27 05:28:57 -05:00
|
|
|
// DATE: 2012-11-23
|
|
|
|
// PURPOSE: Arduino Library to generate repeating pulse patterns
|
2013-09-30 12:31:40 -04:00
|
|
|
// sends a pulse pattern to a digital pin (continuously)
|
2013-09-30 12:38:54 -04:00
|
|
|
// HISTORY: See PulsePattern.cpp
|
2013-09-30 12:29:52 -04:00
|
|
|
//
|
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
#if !defined(__AVR__)
|
|
|
|
#error "Only support for AVR boards"
|
|
|
|
#endif
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2013-09-30 12:29:52 -04:00
|
|
|
|
2022-11-22 11:20:26 -05:00
|
|
|
#define PULSEPATTERN_LIB_VERSION (F("0.1.6"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2022-03-11 04:36:49 -05:00
|
|
|
// RUNNING STATES
|
2021-12-24 09:10:06 -05:00
|
|
|
#define NOTINIT -1
|
|
|
|
#define STOPPED 0
|
|
|
|
#define RUNNING 1
|
2013-09-30 12:29:52 -04:00
|
|
|
|
2022-03-11 04:36:49 -05:00
|
|
|
// PRESCALER CONSTANTS
|
2022-11-22 11:20:26 -05:00
|
|
|
#define NO_CLOCK 0 // timer off
|
2021-12-24 09:10:06 -05:00
|
|
|
#define PRESCALE_1 1
|
|
|
|
#define PRESCALE_8 2
|
|
|
|
#define PRESCALE_64 3
|
|
|
|
#define PRESCALE_256 4
|
|
|
|
#define PRESCALE_1024 5
|
2022-11-22 11:20:26 -05:00
|
|
|
#define EXT_T1_FALLING 6 // external clock
|
|
|
|
#define EXT_T2_RISING 7 // external clock
|
2020-11-27 05:28:57 -05:00
|
|
|
|
2022-03-11 04:36:49 -05:00
|
|
|
// RUNNING MODE
|
|
|
|
#define PP_ONCE 1
|
|
|
|
#define PP_CONTINUOUS 0xFFFFFFFF
|
|
|
|
|
2013-09-30 12:34:23 -04:00
|
|
|
|
|
|
|
class PulsePattern
|
2013-09-30 12:29:52 -04:00
|
|
|
{
|
2013-09-30 12:34:23 -04:00
|
|
|
public:
|
2017-07-16 10:01:09 -04:00
|
|
|
PulsePattern();
|
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
void init(const uint8_t pin,
|
|
|
|
const uint16_t * ar, const uint8_t size,
|
|
|
|
const uint8_t level, const uint8_t prescaler);
|
|
|
|
|
|
|
|
void setFactor(float perc) { _factor = round(4096 * (1 + perc)); };
|
|
|
|
float getFactor() { return _factor / 4096.0 - 1; };
|
2022-03-11 04:36:49 -05:00
|
|
|
void start(uint32_t times = PP_CONTINUOUS);
|
2020-11-27 05:28:57 -05:00
|
|
|
void cont();
|
|
|
|
void stop();
|
|
|
|
bool isRunning() const { return _state == RUNNING; };
|
2017-07-16 10:01:09 -04:00
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
void worker();
|
2013-09-30 12:34:23 -04:00
|
|
|
|
|
|
|
private:
|
2020-11-27 05:28:57 -05:00
|
|
|
void stopTimer();
|
|
|
|
void setTimer(const uint16_t cc) const;
|
|
|
|
|
|
|
|
uint32_t _factor = 4096;
|
2017-07-16 10:01:09 -04:00
|
|
|
uint16_t * _ar;
|
2020-11-27 05:28:57 -05:00
|
|
|
uint8_t _size;
|
|
|
|
uint8_t _pin;
|
|
|
|
uint8_t _pinbit;
|
|
|
|
volatile uint8_t * _pinout;
|
|
|
|
uint8_t _prescaler;
|
|
|
|
volatile uint8_t _level;
|
|
|
|
volatile int8_t _state;
|
|
|
|
volatile uint8_t _cnt;
|
2022-03-11 04:36:49 -05:00
|
|
|
|
|
|
|
uint32_t _times = PP_CONTINUOUS;
|
2013-09-30 12:29:52 -04:00
|
|
|
};
|
|
|
|
|
2013-09-30 12:38:54 -04:00
|
|
|
extern PulsePattern PPGenerator;
|
2013-09-30 12:31:40 -04:00
|
|
|
|
2021-12-24 09:10:06 -05:00
|
|
|
|
2022-11-22 11:20:26 -05:00
|
|
|
// -- END OF FILE --
|