forked from jgillick/arduino-LEDFader
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDMXFader.h
86 lines (65 loc) · 2.19 KB
/
DMXFader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* DMXFader.h
*
* Created on: Sep 24, 2013
* Author: jeremy
* Modified by PsikoBlock on 2017-07-23
*/
#include "Arduino.h"
#include <ESPDMX.h>
#ifndef DMXFader_H_
#define DMXFader_H_
// The minimum time (milliseconds) the program will wait between channel adjustments
// adjust this to modify performance.
// max DMX frequency is 44 Hz ~ 23 ms
#define MIN_INTERVAL 50
class DMXFader {
public:
// Who likes dealing with function pointers? (Ok, I do, but no one else does)
typedef uint8_t (*curve_function)(uint8_t);
private:
DMXESPSerial *universe;
uint16_t channel;
unsigned long last_step_time;
unsigned int interval;
uint8_t value;
uint8_t to_value;
unsigned int duration;
float percent_done;
curve_function curve;
public:
// Create a new DMX Fader for a channel
DMXFader(DMXESPSerial &dmx_universe, uint16_t dmx_channel = 1);
// Set the DMX universe (instance of ESPDMX)
void set_universe(DMXESPSerial &dmx_universe);
DMXESPSerial& get_universe();
// Set the DMX channel
void set_channel(uint16_t dmx_channel);
uint16_t get_channel();
// Set an channel to an absolute value
void set_value(uint8_t value);
// Get the current channel value
uint8_t get_value();
// Get the value we're fading to
uint8_t get_target_value();
// Set curve to transform output
void set_curve(curve_function);
// Get the current curve function pointer
curve_function get_curve();
// Fade an channel to a value over a duration of time (milliseconds)
void fade(uint8_t newValue, unsigned int time);
// Returns TRUE if there is an active fade process
bool is_fading();
// Stop the current fade where it's at
void stop_fade();
// Update the channels along the fade
// Returns TRUE if a fade is still in process
bool update();
// Decrease the current fading speed by a number of milliseconds
void slower(int by_seconds);
// Increase the current fading speed by a number of milliseconds
void faster(int by_seconds);
// Returns how much of the fade is complete in a percentage between 0 - 100
uint8_t get_progress();
};
#endif /* DMXFader_H_ */