2020-12-01 19:40:58 -05:00
|
|
|
/*
|
|
|
|
strobe_esp32.h
|
|
|
|
|
2020-12-04 14:57:57 -05:00
|
|
|
Part of WiFlash_esp32
|
|
|
|
|
|
|
|
Copyright (c) 2020 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
2020-12-01 19:40:58 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef STROBE_ESP32_H_
|
|
|
|
#define STROBE_ESP32_H_
|
|
|
|
|
2020-12-07 08:45:40 -05:00
|
|
|
#include "dmx_universe.h"
|
2020-12-01 19:40:58 -05:00
|
|
|
|
|
|
|
inline uint32_t hz_to_micros(uint8_t dmx) __attribute__((always_inline));
|
|
|
|
inline uint32_t dr_to_micros(uint8_t dmx) __attribute__((always_inline));
|
|
|
|
|
2020-12-07 08:45:40 -05:00
|
|
|
typedef union {
|
|
|
|
uint8_t dmx[4];
|
|
|
|
struct {
|
|
|
|
uint16_t intensity;
|
|
|
|
uint8_t duration;
|
|
|
|
uint8_t rate;
|
|
|
|
} __attribute__((packed));
|
|
|
|
} profile_t;
|
|
|
|
|
2020-12-01 19:40:58 -05:00
|
|
|
typedef enum {
|
|
|
|
STROBE_INACTIVE,
|
|
|
|
STROBE_ACTIVE_ON,
|
|
|
|
STROBE_ACTIVE_OFF
|
|
|
|
} strState;
|
|
|
|
|
|
|
|
|
|
|
|
class Strobe {
|
|
|
|
public:
|
2020-12-06 11:07:30 -05:00
|
|
|
Strobe(uint16_t address = 1);
|
2020-12-04 14:57:57 -05:00
|
|
|
|
2020-12-07 08:45:40 -05:00
|
|
|
bool begin(uint8_t pin, uint8_t pwm); // call in setup()
|
|
|
|
static void update(void * param); // update task
|
2020-12-04 14:57:57 -05:00
|
|
|
|
2020-12-07 08:45:40 -05:00
|
|
|
void recvData(Universe *); // data recieved callback
|
2020-12-01 19:40:58 -05:00
|
|
|
|
|
|
|
private:
|
2020-12-07 08:45:40 -05:00
|
|
|
uint16_t address_; // DMX address
|
|
|
|
profile_t profile_; // DMX data
|
2020-12-04 14:57:57 -05:00
|
|
|
|
2020-12-07 08:45:40 -05:00
|
|
|
strState state_; // state machine cycle state
|
|
|
|
uint8_t pwm_; // LEDc PWM channel
|
2020-12-04 14:57:57 -05:00
|
|
|
|
2020-12-01 19:40:58 -05:00
|
|
|
inline void setLevel(uint16_t level) __attribute__((always_inline));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // STROBE_ESP32_H_
|