starting esp32 project : OTA, WifiManager, FastLes / NeoPixelBus
This commit is contained in:
parent
6ffc307da8
commit
e5335720bf
149
ESP32LedBars/.clang-format
Normal file
149
ESP32LedBars/.clang-format
Normal file
@ -0,0 +1,149 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: false
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveBitFields: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentCaseLabels: false
|
||||
IndentCaseBlocks: false
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertTrailingCommas: None
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
SpaceBeforeSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TabWidth: 8
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
- BOOST_PP_STRINGIZE
|
||||
...
|
||||
|
5
ESP32LedBars/.gitignore
vendored
Normal file
5
ESP32LedBars/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
7
ESP32LedBars/.vscode/extensions.json
vendored
Normal file
7
ESP32LedBars/.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
39
ESP32LedBars/include/README
Normal file
39
ESP32LedBars/include/README
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
35
ESP32LedBars/platformio.ini
Normal file
35
ESP32LedBars/platformio.ini
Normal file
@ -0,0 +1,35 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[platformio]
|
||||
default_envs = nodemcu-32s_debug
|
||||
|
||||
[env]
|
||||
monitor_speed = 115200
|
||||
build_flags = -Wall
|
||||
lib_deps =
|
||||
fastled/FastLED
|
||||
; ArtnetWifi
|
||||
; tzapu/WiFiManager#master
|
||||
|
||||
[env:nodemcu-32s]
|
||||
platform = espressif32
|
||||
board = nodemcu-32s
|
||||
framework = arduino
|
||||
|
||||
[env:nodemcu-32s_debug]
|
||||
build_type = debug
|
||||
extends = env:nodemcu-32s
|
||||
|
||||
[env:nodemcu-32s_ota]
|
||||
build_type = debug
|
||||
extends = env:nodemcu-32s
|
||||
upload_protocol = espota
|
||||
upload_port = 192.168.1.78
|
240
ESP32LedBars/src/main.cpp
Normal file
240
ESP32LedBars/src/main.cpp
Normal file
@ -0,0 +1,240 @@
|
||||
#include <Arduino.h>
|
||||
// #include <ArduinoOTA.h>
|
||||
// #include <ArtnetWifi.h>
|
||||
#include <FastLED.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
#define LED_TYPE WS2812B
|
||||
#define COLOR_ORDER GRB
|
||||
#define BRIGHTNESS 15
|
||||
|
||||
#define MAX_BAR_NUMBER 2
|
||||
|
||||
typedef struct {
|
||||
int numLeds;
|
||||
uint8_t pin;
|
||||
} ledBar_t;
|
||||
|
||||
ledBar_t ledBarArray[MAX_BAR_NUMBER] = {{.numLeds = 15, .pin = 22}, {.numLeds = 10, .pin = 23}};
|
||||
|
||||
#define FOREACH_BARS(FUNC) FUNC(22) FUNC(23)
|
||||
|
||||
// LED settings
|
||||
const int numLeds{8 * 30};
|
||||
// Total number of channels you want to receive (1 led = 3 channels)
|
||||
CRGB leds[numLeds];
|
||||
CRGB leds2[15];
|
||||
CRGB leds3[10];
|
||||
|
||||
// Art-Net settings
|
||||
// ArtnetWifi artnet;
|
||||
|
||||
// most software this is 1, some software send out artnet first universe as 0.
|
||||
const int startUniverse = 0;
|
||||
|
||||
int count = 0;
|
||||
|
||||
void pride();
|
||||
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *data);
|
||||
// void setupOTA();
|
||||
|
||||
void initTest(CRGB *leds, int numLeds);
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
void setup() {
|
||||
delay(3000); // 3 second delay for recovery
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Init");
|
||||
|
||||
#define ADD_LEDS_BARS(PIN) \
|
||||
FastLED.addLeds<LED_TYPE, PIN, COLOR_ORDER>(leds, 60).setCorrection(TypicalLEDStrip).setDither(BRIGHTNESS < 255);
|
||||
// FOREACH_BARS(ADD_LEDS_BARS)
|
||||
|
||||
FastLED.addLeds<LED_TYPE, 23, COLOR_ORDER>(leds, numLeds).setCorrection(TypicalLEDStrip).setDither(0);
|
||||
// set master brightness control
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
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();
|
||||
|
||||
// this will be called for each packet received
|
||||
// artnet.begin();
|
||||
// artnet.setArtDmxCallback(onDmxFrame);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ArduinoOTA.handle();
|
||||
|
||||
// artnet.read();
|
||||
|
||||
static uint16_t sLastMillis = 0;
|
||||
uint16_t ms = millis();
|
||||
uint16_t deltams = ms - sLastMillis;
|
||||
|
||||
if (deltams >= 1000) {
|
||||
Serial.print("FPS : ");
|
||||
Serial.println(count);
|
||||
count = 0;
|
||||
sLastMillis = ms;
|
||||
}
|
||||
++count;
|
||||
pride();
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
// Check if we got all universes
|
||||
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) {
|
||||
Serial.println("Frame received");
|
||||
sendFrame = 1;
|
||||
|
||||
// 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 * (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() {
|
||||
// ArduinoOTA
|
||||
// .onStart([]() {
|
||||
// String type;
|
||||
// if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
// type = "sketch";
|
||||
// else // U_SPIFFS
|
||||
// type = "filesystem";
|
||||
|
||||
// // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
|
||||
// Serial.println("Start updating " + type);
|
||||
// })
|
||||
// .onEnd([]() { Serial.println("\nEnd"); })
|
||||
// .onProgress([](unsigned int progress, unsigned int total) {
|
||||
// Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
// })
|
||||
// .onError([](ota_error_t error) {
|
||||
// Serial.printf("Error[%u]: ", error);
|
||||
// if (error == OTA_AUTH_ERROR)
|
||||
// Serial.println("Auth Failed");
|
||||
// else if (error == OTA_BEGIN_ERROR)
|
||||
// Serial.println("Begin Failed");
|
||||
// else if (error == OTA_CONNECT_ERROR)
|
||||
// Serial.println("Connect Failed");
|
||||
// else if (error == OTA_RECEIVE_ERROR)
|
||||
// Serial.println("Receive Failed");
|
||||
// else if (error == OTA_END_ERROR)
|
||||
// Serial.println("End Failed");
|
||||
// });
|
||||
|
||||
// ArduinoOTA.begin();
|
||||
|
||||
// Serial.println("Ready");
|
||||
// Serial.print("IP address: ");
|
||||
// Serial.println(WiFi.localIP());
|
||||
// }
|
||||
|
||||
void initTest(CRGB *leds, int numLeds) {
|
||||
Serial.println("Green");
|
||||
for (int i = 0; i < numLeds; i++) {
|
||||
leds[i] = CRGB(127, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
Serial.println("Red");
|
||||
for (int i = 0; i < numLeds; i++) {
|
||||
leds[i] = CRGB(0, 127, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
Serial.println("Blue");
|
||||
for (int i = 0; i < numLeds; i++) {
|
||||
leds[i] = CRGB(0, 0, 127);
|
||||
}
|
||||
FastLED.show();
|
||||
delay(500);
|
||||
Serial.println("Done");
|
||||
for (int i = 0; i < numLeds; i++) {
|
||||
leds[i] = CRGB(0, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
void pride() {
|
||||
static uint16_t sPseudotime = 0;
|
||||
static uint16_t sLastMillis = 0;
|
||||
static uint16_t sHue16 = 0;
|
||||
|
||||
uint8_t sat8 = beatsin88(87, 220, 250);
|
||||
uint8_t brightdepth = beatsin88(341, 96, 224);
|
||||
uint16_t brightnessthetainc16 = beatsin88(203, (25 * 256), (40 * 256));
|
||||
uint8_t msmultiplier = beatsin88(147, 23, 60);
|
||||
|
||||
uint16_t hue16 = sHue16; // gHue * 256;
|
||||
uint16_t hueinc16 = beatsin88(113, 1, 3000);
|
||||
|
||||
uint16_t ms = millis();
|
||||
uint16_t deltams = ms - sLastMillis;
|
||||
sLastMillis = ms;
|
||||
sPseudotime += deltams * msmultiplier;
|
||||
sHue16 += deltams * beatsin88(400, 5, 9);
|
||||
uint16_t brightnesstheta16 = sPseudotime;
|
||||
|
||||
for (uint16_t i = 0; i < numLeds; i++) {
|
||||
hue16 += hueinc16;
|
||||
uint8_t hue8 = hue16 / 256;
|
||||
|
||||
brightnesstheta16 += brightnessthetainc16;
|
||||
uint16_t b16 = sin16(brightnesstheta16) + 32768;
|
||||
|
||||
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
|
||||
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
|
||||
bri8 += (255 - brightdepth);
|
||||
|
||||
CRGB newcolor = CHSV(hue8, sat8, bri8);
|
||||
|
||||
uint16_t pixelnumber = i;
|
||||
pixelnumber = (numLeds - 1) - pixelnumber;
|
||||
|
||||
nblend(leds[pixelnumber], newcolor, 64);
|
||||
}
|
||||
}
|
11
ESP32LedBars/test/README
Normal file
11
ESP32LedBars/test/README
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
Loading…
Reference in New Issue
Block a user