Skip to content

Commit

Permalink
Merge pull request PlummersSoftwareLLC#642 from davepl/main
Browse files Browse the repository at this point in the history
Add M5 Unified support (M5 Stick C Plus 2, M5 Stack Core 2)
  • Loading branch information
rbergen authored Jul 16, 2024
2 parents 7c9c08b + 58a58ea commit a96ab44
Show file tree
Hide file tree
Showing 35 changed files with 733 additions and 304 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ _Davepl, 9/19/2021_
## Table of Contents <!-- omit in toc -->

- [What NightDriverStrip is](#what-nightdriverstrip-is)
- [Project Overview](#project-overview)
- [Key Features](#key-features)
- [Using the Web Installer](#using-the-web-installer)
- [Introduction](#introduction)
- [(Re)flashing your device with the Web Installer](#reflashing-your-device-with-the-web-installer)
Expand Down Expand Up @@ -49,6 +51,24 @@ NightDriver can drive both WS2812B style strips and HUB75 style matrices.

More recently, a web installer has been added to the project with which most of the NightDriver projects can be flashed on supported devices, using nothing but a web browser. Please refer to the next section if this is how you'd like to get started.

## Project Overview

- It's an open-source project for controlling LED strips/matrices and doing cool effects on them
- Uses WiFi for remote control and data reception.
- Supports audio reactive effects.
- Includes a web server and telnet debug server.

## Key Features

- Multiple LED control methods (WS2812B, HUB75, etc.)
- WiFi connectivity for remote control and data
- Audio analysis for sound-reactive effects
- OTA (Over-The-Air) updates
- Debug console accessible via telnet and serial
- Display support (OLED, TFT, LCD) for status information
- NTP time synchronization so effects can span multiple ESP32s in sync
- Configurable via web interface that runs on the ESP32

## Using the Web Installer

### Introduction
Expand Down
31 changes: 27 additions & 4 deletions config/web_projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"chipfamily": "ESP32",
"name": "ESP32",
"projects": [
{
"tag": "atomlight",
"name": "Atom Light"
},
{
"tag": "demo",
"name":"Demo"
Expand Down Expand Up @@ -61,10 +65,6 @@
"chipfamily": "ESP32",
"name": "Heltec Wifi Kit 32",
"projects": [
{
"tag": "atomlight",
"name": "Atom Light"
},
{
"tag": "heltecdemo",
"name":"Demo"
Expand Down Expand Up @@ -144,6 +144,10 @@
"tag": "fanset",
"name": "Fan Set"
},
{
"tag": "helmet",
"name": "Helmet"
},
{
"tag": "insulators",
"name": "Insulators"
Expand All @@ -156,12 +160,31 @@
"tag": "spectrum",
"name": "Spectrum"
},
{
"tag": "spirallamp",
"name": "Spiral Lamp"
},
{
"tag": "xmastrees",
"name": "X-mas Trees"
}
]
},
{
"tag": "m5stick-c-plus2",
"chipfamily": "ESP32",
"name": "M5StickC Plus2",
"projects": [
{
"tag": "pdpgrid",
"name": "PDP Grid"
},
{
"tag": "spectrum2",
"name": "Spectrum"
}
]
},
{
"tag": "mesmerizer",
"chipfamily": "ESP32",
Expand Down
2 changes: 1 addition & 1 deletion include/deviceconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
#define NTP_SERVER_DEFAULT "0.pool.ntp.org"
#define BRIGHTNESS_MIN uint8_t(10)
#define BRIGHTNESS_MAX uint8_t(255)
#define POWER_LIMIT_MIN 2000
#define POWER_LIMIT_MIN 1000
#define POWER_LIMIT_DEFAULT 4500

// DeviceConfig holds, persists and loads device-wide configuration settings. Effect-specific settings should
Expand Down
2 changes: 1 addition & 1 deletion include/effectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EffectManager : public IJSONSerializable
bool _bPlayAll;
bool _bShowVU = true;
bool _clearTempEffectWhenExpired = false;
bool _newFrameAvailable = false;
std::atomic_bool _newFrameAvailable = false;
int _effectSetVersion = 1;

std::vector<std::shared_ptr<GFXBase>> _gfx;
Expand Down
2 changes: 2 additions & 0 deletions include/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
#define EFFECT_MATRIX_SMWALKING_MACHINE 157
#define EFFECT_MATRIX_ANIMATEDGIF 158
#define EFFECT_MATRIX_STOCKS 159
#define EFFECT_MATRIX_SILON 160
#define EFFECT_MATRIX_PDPGRID 161

// Hexagon Effects
#define EFFECT_HEXAGON_OUTER_RING 201
Expand Down
5 changes: 2 additions & 3 deletions include/effects/matrix/PatternLife.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class PatternLife : public LEDStripEffect
//
// Example: Seed: 92465, Generations: 1626

static constexpr long bakedInSeeds[] =
static constexpr std::array<unsigned long, 19> bakedInSeeds =
{
130908, // 3253
1576, // 3125
Expand All @@ -185,7 +185,6 @@ class PatternLife : public LEDStripEffect
555109764, // 4470
};


void randomFillWorld()
{
// Some fraction of the time we pick a pre-baked seed that we know lasts for a lot
Expand All @@ -194,7 +193,7 @@ class PatternLife : public LEDStripEffect
srand(millis());
if (random(0, 4) == 0)
{
seed = bakedInSeeds[random(ARRAYSIZE(bakedInSeeds))];
seed = bakedInSeeds[random(std::size(bakedInSeeds))];
debugV("Prebaked Seed: %lu", seed);
}
else
Expand Down
6 changes: 4 additions & 2 deletions include/effects/matrix/PatternSMGamma.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class PatternSMGamma : public LEDStripEffect

void Draw() override
{
static const uint8_t exp_gamma[256] = {
static constexpr std::array<uint8_t, 256> exp_gamma =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 7, 7,
Expand All @@ -37,7 +38,8 @@ class PatternSMGamma : public LEDStripEffect
109, 111, 112, 114, 115, 117, 118, 120, 121, 123, 125, 126, 128, 130, 131, 133, 135, 136, 138, 140,
142, 143, 145, 147, 149, 151, 152, 154, 156, 158, 160, 162, 164, 165, 167, 169, 171, 173, 175, 177,
179, 181, 183, 185, 187, 190, 192, 194, 196, 198, 200, 202, 204, 207, 209, 211, 213, 216, 218, 220,
222, 225, 227, 229, 232, 234, 236, 239, 241, 244, 246, 249, 251, 253, 254, 255};
222, 225, 227, 229, 232, 234, 236, 239, 241, 244, 246, 249, 251, 253, 254, 255
};

int a = millis() / 8;
for (uint x = 0; x < MATRIX_WIDTH; x++)
Expand Down
24 changes: 9 additions & 15 deletions include/effects/matrix/PatternStocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ using namespace std;
using namespace std::chrono;
using namespace std::chrono_literals;

#define STOCKS_UPDATE_INTERVAL_SECONDS 10s
#define STOCKS_UPDATE_INTERVAL_SECONDS 6s
#define STOCKS_FETCH_INTERVAL_SECONDS 60s

#define DEFAULT_STOCK_SERVER "davepl.com:8888"
Expand Down Expand Up @@ -416,7 +416,8 @@ class PatternStocks : public LEDStripEffect
auto changetext = String(data.close - data.open, 2);
auto changelen = changetext.length();

auto voltext = String(data.volume, 0);
constexpr auto formatVolumeLargerThan = 1000000;
auto voltext = formatSize(data.volume, formatVolumeLargerThan);
auto vollen = voltext.length();

textSymbol = AnimatedText(data.symbol, CRGB::White, &Apple5x7, 0.50f, -MATRIX_WIDTH, 8, 0, 8);
Expand All @@ -425,6 +426,7 @@ class PatternStocks : public LEDStripEffect
textVolume = AnimatedText(voltext, CRGB::LightGrey, &Apple5x7, 1.0f, -MATRIX_WIDTH * 2, 22, MATRIX_WIDTH - vollen * textwidth, 22);
}


// UpdateQuoteDisplay
//
// Updates the position of the text and draws it on the screen, then draws
Expand Down Expand Up @@ -459,23 +461,15 @@ class PatternStocks : public LEDStripEffect

if (n > 0)
{
float max = 0.0f;
float min = numeric_limits<float>::max();

// We have the high and low data in the stock, but let's not trust it and calculate it ourselves
// If this works, Davepl wrote it. If not, Robert made me do it!

for (int i = 0; i < n; i++)
{
max = std::max(max, currentStock.points[i].val);
min = std::min(min, currentStock.points[i].val);
}

// Now draw each vertical line segment
auto [minpoint, maxpoint] = std::minmax_element(currentStock.points.begin(), currentStock.points.end(), [](const StockPoint& a, const StockPoint& b) { return a.val < b.val; });
float min = minpoint->val, max = maxpoint->val, range = max - min;

float range = max - min;
if (range > 0.0f)
{
float scale = h / range;
float scale = range > 0.0f ? h / range : 0.0f;
float breakeven = currentStock.open;
float breakevenY = y + h - (breakeven - min) * scale;

Expand Down Expand Up @@ -511,7 +505,7 @@ class PatternStocks : public LEDStripEffect

if (WiFi.isConnected())
{
if (system_clock::now() > nextFetch)
if (system_clock::now() >= nextFetch)
{
nextFetch = system_clock::now() + STOCKS_FETCH_INTERVAL_SECONDS;
// Trigger the stock data reader.
Expand Down
5 changes: 3 additions & 2 deletions include/effects/matrix/PatternWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <ArduinoJson.h>
#include "systemcontainer.h"
#include <FontGfx_apple5x7.h>
#include <array>
#include <chrono>
#include <thread>
#include <map>
Expand Down Expand Up @@ -92,9 +93,9 @@ extern const uint8_t thunderstorm_end[] asm("_binary_assets_bmp_thun
extern const uint8_t thunderstorm_night_start[] asm("_binary_assets_bmp_thunderstormnight_jpg_start");
extern const uint8_t thunderstorm_night_end[] asm("_binary_assets_bmp_thunderstormnight_jpg_end");

static const char * pszDaysOfWeek[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
static constexpr auto pszDaysOfWeek = to_array( { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" } );

static std::map<String, EmbeddedFile, std::less<String>, psram_allocator<std::pair<String, EmbeddedFile>>> weatherIcons =
static std::map<const String, EmbeddedFile, std::less<const String>, psram_allocator<std::pair<const String, EmbeddedFile>>> weatherIcons =
{
{ "01d", EmbeddedFile(clearsky_start, clearsky_end) },
{ "02d", EmbeddedFile(fewclouds_start, fewclouds_end) },
Expand Down
Loading

0 comments on commit a96ab44

Please sign in to comment.