beta 1
This commit is contained in:
parent
e5335720bf
commit
5c577897b2
@ -54,7 +54,7 @@ BreakConstructorInitializersBeforeComma: false
|
|||||||
BreakConstructorInitializers: BeforeColon
|
BreakConstructorInitializers: BeforeColon
|
||||||
BreakAfterJavaFieldAnnotations: false
|
BreakAfterJavaFieldAnnotations: false
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 120
|
ColumnLimit: 100
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
@ -16,7 +16,7 @@ monitor_speed = 115200
|
|||||||
build_flags = -Wall
|
build_flags = -Wall
|
||||||
lib_deps =
|
lib_deps =
|
||||||
fastled/FastLED
|
fastled/FastLED
|
||||||
; ArtnetWifi
|
ArtnetWifi
|
||||||
; tzapu/WiFiManager#master
|
; tzapu/WiFiManager#master
|
||||||
|
|
||||||
[env:nodemcu-32s]
|
[env:nodemcu-32s]
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
// #include <ArduinoOTA.h>
|
// #include <ArduinoOTA.h>
|
||||||
// #include <ArtnetWifi.h>
|
#include <ArtnetWifi.h>
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
#include <WiFiManager.h>
|
#include <WiFi.h>
|
||||||
|
// #include <WiFiManager.h>
|
||||||
|
|
||||||
|
/* Types and Constants */
|
||||||
|
/*------------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#define LED_TYPE WS2812B
|
#define LED_TYPE WS2812B
|
||||||
#define COLOR_ORDER GRB
|
#define COLOR_ORDER GRB
|
||||||
@ -20,120 +24,103 @@ ledBar_t ledBarArray[MAX_BAR_NUMBER] = {{.numLeds = 15, .pin = 22}, {.numLeds =
|
|||||||
#define FOREACH_BARS(FUNC) FUNC(22) FUNC(23)
|
#define FOREACH_BARS(FUNC) FUNC(22) FUNC(23)
|
||||||
|
|
||||||
// LED settings
|
// LED settings
|
||||||
const int numLeds{8 * 30};
|
const int numLeds{165};
|
||||||
// Total number of channels you want to receive (1 led = 3 channels)
|
// Total number of channels you want to receive (1 led = 3 channels)
|
||||||
CRGB leds[numLeds];
|
CRGB leds[numLeds];
|
||||||
CRGB leds2[15];
|
CRGB leds2[15];
|
||||||
CRGB leds3[10];
|
CRGB leds3[10];
|
||||||
|
|
||||||
// Art-Net settings
|
// Art-Net settings
|
||||||
// ArtnetWifi artnet;
|
ArtnetWifi artnet;
|
||||||
|
|
||||||
// most software this is 1, some software send out artnet first universe as 0.
|
|
||||||
const int startUniverse = 0;
|
|
||||||
|
|
||||||
|
/* Global variables */
|
||||||
|
/*------------------------------------------------------------------------------------------------*/
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
/* Private function declarations */
|
||||||
|
/*------------------------------------------------------------------------------------------------*/
|
||||||
|
void init_wifi();
|
||||||
void pride();
|
void pride();
|
||||||
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *data);
|
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *data);
|
||||||
// void setupOTA();
|
// void setupOTA();
|
||||||
|
|
||||||
void initTest(CRGB *leds, int numLeds);
|
void initTest(CRGB *leds, int numLeds);
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
/* Pulic function definitions */
|
||||||
|
/*------------------------------------------------------------------------------------------------*/
|
||||||
void setup() {
|
void setup() {
|
||||||
delay(3000); // 3 second delay for recovery
|
delay(3000); // 3 second delay for recovery
|
||||||
|
|
||||||
|
// initialize serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Init");
|
Serial.println("Init");
|
||||||
|
|
||||||
#define ADD_LEDS_BARS(PIN) \
|
// initialize wifi
|
||||||
FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, 60).setCorrection(TypicalLEDStrip).setDither(BRIGHTNESS < 255);
|
init_wifi();
|
||||||
|
|
||||||
|
// #define ADD_LEDS_BARS(PIN) \
|
||||||
|
// FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, 60) \
|
||||||
|
// .setCorrection(TypicalLEDStrip) \
|
||||||
|
// .setDither(BRIGHTNESS < 255);
|
||||||
// FOREACH_BARS(ADD_LEDS_BARS)
|
// FOREACH_BARS(ADD_LEDS_BARS)
|
||||||
|
|
||||||
FastLED.addLeds<LED_TYPE, 23, COLOR_ORDER>(leds, numLeds).setCorrection(TypicalLEDStrip).setDither(0);
|
FastLED.addLeds<LED_TYPE, 5, COLOR_ORDER>(leds, numLeds)
|
||||||
|
.setCorrection(TypicalLEDStrip)
|
||||||
|
.setDither(0);
|
||||||
// set master brightness control
|
// set master brightness control
|
||||||
FastLED.setBrightness(BRIGHTNESS);
|
FastLED.setBrightness(BRIGHTNESS);
|
||||||
initTest(leds, numLeds);
|
initTest(leds, numLeds);
|
||||||
|
|
||||||
IPAddress _ip = IPAddress(192, 168, 1, 78);
|
|
||||||
IPAddress _gw = IPAddress(192, 168, 1, 1);
|
|
||||||
IPAddress _sn = IPAddress(255, 255, 255, 0);
|
|
||||||
// end-block2
|
|
||||||
|
|
||||||
wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn);
|
|
||||||
if (!wifiManager.autoConnect()) {
|
|
||||||
Serial.println("failed to connect, we should reset as see if it connects");
|
|
||||||
delay(3000);
|
|
||||||
ESP.restart();
|
|
||||||
delay(5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setupOTA();
|
// setupOTA();
|
||||||
|
|
||||||
// this will be called for each packet received
|
// this will be called for each packet received
|
||||||
// artnet.begin();
|
artnet.begin();
|
||||||
// artnet.setArtDmxCallback(onDmxFrame);
|
artnet.setArtDmxCallback(onDmxFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// ArduinoOTA.handle();
|
// ArduinoOTA.handle();
|
||||||
|
|
||||||
// artnet.read();
|
artnet.read();
|
||||||
|
|
||||||
static uint16_t sLastMillis = 0;
|
static uint16_t sLastMillis = millis();
|
||||||
uint16_t ms = millis();
|
uint16_t ms = millis();
|
||||||
uint16_t deltams = ms - sLastMillis;
|
uint16_t deltams = ms - sLastMillis;
|
||||||
|
|
||||||
if (deltams >= 1000) {
|
if (deltams >= 5000) {
|
||||||
Serial.print("FPS : ");
|
Serial.print("FPS : ");
|
||||||
Serial.println(count);
|
Serial.println(count / 5);
|
||||||
count = 0;
|
count = 0;
|
||||||
sLastMillis = ms;
|
sLastMillis = ms;
|
||||||
}
|
}
|
||||||
++count;
|
++count;
|
||||||
pride();
|
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we got all universes
|
/* Private function definitions */
|
||||||
const int numberOfChannels = (numLeds)*3;
|
/*------------------------------------------------------------------------------------------------*/
|
||||||
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
|
|
||||||
bool universesReceived[maxUniverses];
|
|
||||||
bool sendFrame = 1;
|
|
||||||
int previousDataLength = 0;
|
|
||||||
|
|
||||||
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *data) {
|
/* Initialize wifi connection */
|
||||||
Serial.println("Frame received");
|
void init_wifi() {
|
||||||
sendFrame = 1;
|
IPAddress localIp = IPAddress(192, 168, 1, 78);
|
||||||
|
IPAddress gateway = IPAddress(192, 168, 1, 1);
|
||||||
|
IPAddress subnet = IPAddress(255, 255, 255, 0);
|
||||||
|
// end-block2
|
||||||
|
if (!WiFi.config(localIp, gateway, subnet)) {
|
||||||
|
Serial.println("STA Failed to configure");
|
||||||
|
}
|
||||||
|
WiFi.begin("BertheBox", "3615BertheBerthelot");
|
||||||
|
|
||||||
// Store which universe has got in
|
Serial.print("Connecting");
|
||||||
if ((universe - startUniverse) < maxUniverses) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
universesReceived[universe - startUniverse] = 1;
|
delay(500);
|
||||||
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
for (int i = 0; i < maxUniverses; i++) {
|
Serial.print("Connected, IP address: ");
|
||||||
if (universesReceived[i] == 0) {
|
Serial.println(WiFi.localIP());
|
||||||
// Serial.println("Broke");
|
|
||||||
sendFrame = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// read universe and put into the right part of the display buffer
|
|
||||||
for (int i = 0; i < length / 3; i++) {
|
|
||||||
int led = i * (previousDataLength / 3);
|
|
||||||
if (led < numLeds)
|
|
||||||
leds[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
|
|
||||||
}
|
|
||||||
previousDataLength = length;
|
|
||||||
|
|
||||||
if (sendFrame) {
|
|
||||||
FastLED.show();
|
|
||||||
// Reset universeReceived to 0
|
|
||||||
memset(universesReceived, 0, maxUniverses);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void setupOTA() {
|
// void setupOTA() {
|
||||||
@ -144,7 +131,7 @@ void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *d
|
|||||||
// type = "sketch";
|
// type = "sketch";
|
||||||
// else // U_SPIFFS
|
// else // U_SPIFFS
|
||||||
// type = "filesystem";
|
// type = "filesystem";
|
||||||
|
//
|
||||||
// // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
// // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||||
// Serial.println("Start updating " + type);
|
// Serial.println("Start updating " + type);
|
||||||
// })
|
// })
|
||||||
@ -165,14 +152,63 @@ void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *d
|
|||||||
// else if (error == OTA_END_ERROR)
|
// else if (error == OTA_END_ERROR)
|
||||||
// Serial.println("End Failed");
|
// Serial.println("End Failed");
|
||||||
// });
|
// });
|
||||||
|
//
|
||||||
// ArduinoOTA.begin();
|
// ArduinoOTA.begin();
|
||||||
|
//
|
||||||
// Serial.println("Ready");
|
// Serial.println("Ready");
|
||||||
// Serial.print("IP address: ");
|
// Serial.print("IP address: ");
|
||||||
// Serial.println(WiFi.localIP());
|
// Serial.println(WiFi.localIP());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/* initialize led bars */
|
||||||
|
void setup_ledbars() {}
|
||||||
|
|
||||||
|
const int numberOfChannels = numLeds * 3;
|
||||||
|
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send
|
||||||
|
// out artnet first universe as 0.
|
||||||
|
|
||||||
|
// Check if we got all universes
|
||||||
|
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
|
||||||
|
bool universesReceived[maxUniverses];
|
||||||
|
bool sendFrame = 1;
|
||||||
|
int previousDataLength = 0;
|
||||||
|
|
||||||
|
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *data) {
|
||||||
|
sendFrame = 1;
|
||||||
|
// set brightness of the whole strip
|
||||||
|
if (universe == 15) {
|
||||||
|
FastLED.setBrightness(data[0]);
|
||||||
|
FastLED.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store which universe has got in
|
||||||
|
if ((universe - startUniverse) < maxUniverses) {
|
||||||
|
universesReceived[universe - startUniverse] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < maxUniverses; i++) {
|
||||||
|
if (universesReceived[i] == 0) {
|
||||||
|
// Serial.println("Broke");
|
||||||
|
sendFrame = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read universe and put into the right part of the display buffer
|
||||||
|
for (int i = 0; i < length / 3; i++) {
|
||||||
|
int led = i + (universe - startUniverse) * (previousDataLength / 3);
|
||||||
|
if (led < numLeds)
|
||||||
|
leds[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
|
||||||
|
}
|
||||||
|
previousDataLength = length;
|
||||||
|
|
||||||
|
if (sendFrame) {
|
||||||
|
FastLED.show();
|
||||||
|
// Reset universeReceived to 0
|
||||||
|
memset(universesReceived, 0, maxUniverses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void initTest(CRGB *leds, int numLeds) {
|
void initTest(CRGB *leds, int numLeds) {
|
||||||
Serial.println("Green");
|
Serial.println("Green");
|
||||||
for (int i = 0; i < numLeds; i++) {
|
for (int i = 0; i < numLeds; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user