forked from forkineye/ESPixelStick
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ESPixelStick.h
198 lines (174 loc) · 6.68 KB
/
ESPixelStick.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* ESPixelStick.h
*
* Project: ESPixelStick - An ESP8266 and E1.31 based pixel driver
* Copyright (c) 2016 Shelby Merrick
* http://www.forkineye.com
*
* This program is provided free for you to use in any way that you wish,
* subject to the laws and regulations where you are using it. Due diligence
* is strongly suggested before using this code. Please give credit where due.
*
* The Author makes no warranty of any kind, express or implied, with regard
* to this program or the documentation contained in this document. The
* Author shall not be liable in any event for incidental or consequential
* damages in connection with, or arising out of, the furnishing, performance
* or use of these programs.
*
*/
#ifndef ESPIXELSTICK_H_
#define ESPIXELSTICK_H_
const char VERSION[] = "3.1-dev";
const char BUILD_DATE[] = __DATE__;
// Mode configuration moved to Mode.h to ease things with Travis
#include "Mode.h"
#include <ESP8266WiFi.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <ESP8266mDNS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncUDP.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>
#if defined(ESPS_MODE_PIXEL)
#include "PixelDriver.h"
#elif defined(ESPS_MODE_SERIAL)
#include "SerialDriver.h"
#endif
#include "EffectEngine.h"
#define HTTP_PORT 80 /* Default web server port */
#define MQTT_PORT 1883 /* Default MQTT port */
#define DATA_PIN 2 /* Pixel output - GPIO2 (D4 on NodeMCU) */
#define UNIVERSE_MAX 512 /* Max channels in a DMX Universe */
#define PIXEL_LIMIT 1360 /* Total pixel limit - 40.85ms for 8 universes */
#define RENARD_LIMIT 2048 /* Channel limit for serial outputs */
#define E131_TIMEOUT 1000 /* Force refresh every second an E1.31 packet is not seen */
#define CLIENT_TIMEOUT 15 /* In station/client mode try to connection for 15 seconds */
#define AP_TIMEOUT 60 /* In AP mode, wait 60 seconds for a connection or reboot */
#define REBOOT_DELAY 100 /* Delay for rebooting once reboot flag is set */
#define LOG_PORT Serial /* Serial port for console logging */
// E1.33 / RDMnet stuff - to be moved to library
#define RDMNET_DNSSD_SRV_TYPE "draft-e133.tcp"
#define RDMNET_DEFAULT_SCOPE "default"
#define RDMNET_DEFAULT_DOMAIN "local"
#define RDMNET_DNSSD_TXTVERS 1
#define RDMNET_DNSSD_E133VERS 1
// Configuration file params
#define CONFIG_MAX_SIZE 4096 /* Sanity limit for config file */
// Pixel Types
class DevCap {
public:
bool MPIXEL : 1;
bool MSERIAL : 1;
bool MPWM : 1;
uint8_t toInt() {
return (MPWM << 2 | MSERIAL << 1 | MPIXEL);
}
};
// Data Source to use
enum class DataSource : uint8_t {
E131,
MQTT,
WEB,
IDLEWEB
};
// Configuration structure
typedef struct {
/* Device */
String id; /* Device ID */
DevCap devmode; /* Used for reporting device mode, not stored */
DataSource ds; /* Used to track current data source, not stored */
/* Network */
String ssid;
String passphrase;
String hostname;
uint8_t ip[4];
uint8_t netmask[4];
uint8_t gateway[4];
bool dhcp; /* Use DHCP? */
bool ap_fallback; /* Fallback to AP if fail to associate? */
uint32_t sta_timeout; /* Timeout when connection as client (station) */
uint32_t ap_timeout; /* How long to wait in AP mode with no connection before rebooting */
/* UDP raw protocol */
bool udp_enabled;
uint16_t udp_port;
/* Effects */
String effect_name;
CRGB effect_color;
float effect_brightness;
uint16_t effect_speed; /* 1..10 for web UI and MQTT */
bool effect_reverse;
bool effect_mirror;
bool effect_allleds;
bool effect_startenabled;
bool effect_idleenabled;
uint16_t effect_idletimeout;
/* Effect engine send over network */
int effect_sendprotocol;
String effect_sendhost;
IPAddress effect_sendIP;
uint16_t effect_sendport;
float effect_sendspeed;
bool effect_sendmulticast;
/* MQTT */
bool mqtt; /* Use MQTT? */
String mqtt_ip = " ";
uint16_t mqtt_port;
String mqtt_user = " ";
String mqtt_password = " ";
String mqtt_topic;
bool mqtt_clean;
bool mqtt_hadisco;
String mqtt_haprefix;
/* E131 */
uint16_t universe; /* Universe to listen for */
uint16_t universe_limit; /* Universe boundary limit */
uint16_t channel_start; /* Channel to start listening at - 1 based */
uint16_t channel_count; /* Number of channels */
bool multicast; /* Enable multicast listener */
#if defined(ESPS_MODE_PIXEL)
/* Pixels */
PixelType pixel_type; /* Pixel type */
PixelColor pixel_color; /* Pixel color order */
uint16_t zigSize; /* Zigsize count - 0 = no zigzag */
uint16_t groupSize; /* Group size - 1 = no grouping */
float gammaVal; /* gamma value to use */
float briteVal; /* brightness lto use */
#elif defined(ESPS_MODE_SERIAL)
/* Serial */
SerialType serial_type; /* Serial type */
BaudRate baudrate; /* Baudrate */
#endif
#if defined(ESPS_SUPPORT_PWM)
bool pwm_global_enabled; /* is pwm runtime enabled? */
int pwm_freq; /* pwm frequency */
bool pwm_gamma; /* is pwm gamma enabled? */
uint16_t pwm_gpio_dmx[17]; /* which dmx channel is gpio[n] mapped to? */
uint32_t pwm_gpio_enabled; /* is gpio[n] enabled? */
uint32_t pwm_gpio_invert; /* is gpio[n] active high or active low? */
uint32_t pwm_gpio_digital; /* is gpio[n] digital or "analog"? */
String pwm_gpio_comment[17]; /* Free text description */
#endif
} config_t;
// Forward Declarations
void serializeConfig(String &jsonString, bool pretty = false, bool creds = false);
void dsNetworkConfig(JsonObject &json);
void dsDeviceConfig(JsonObject &json);
void dsEffectConfig(JsonObject &json);
void saveConfig();
void dsGammaConfig(JsonObject &json);
void connectWifi();
void onWifiConnect(const WiFiEventStationModeGotIP &event);
void onWiFiDisconnect(const WiFiEventStationModeDisconnected &event);
void connectToMqtt();
void onMqttConnect(bool sessionPresent);
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
void onMqttMessage(char* topic, char* p_payload,
AsyncMqttClientMessageProperties properties, size_t len,size_t index, size_t total);
void publishState();
void publishRGBState();
void publishRGBBrightness();
void publishRGBColor();
void setStatic(uint8_t r, uint8_t g, uint8_t b);
void idleTimeout();
#endif // ESPIXELSTICK_H_