Implemented basic ledstrip
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -52,3 +52,6 @@
|
|||||||
[submodule "components/espasynchttpreq"]
|
[submodule "components/espasynchttpreq"]
|
||||||
path = components/espasynchttpreq
|
path = components/espasynchttpreq
|
||||||
url = git@github.com:0xFEEDC0DE64/espasynchttpreq.git
|
url = git@github.com:0xFEEDC0DE64/espasynchttpreq.git
|
||||||
|
[submodule "components/FastLED-idf"]
|
||||||
|
path = components/FastLED-idf
|
||||||
|
url = git@github.com:0xFEEDC0DE64/FastLED-idf.git
|
||||||
|
1
components/FastLED-idf
Submodule
1
components/FastLED-idf
Submodule
Submodule components/FastLED-idf added at 151565bee4
@@ -84,4 +84,6 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
# -DFEATURE_GARAGE
|
# -DFEATURE_GARAGE
|
||||||
# -DFEATURE_NTP
|
# -DFEATURE_NTP
|
||||||
-DFEATURE_WIRELESS_CONFIG
|
-DFEATURE_WIRELESS_CONFIG
|
||||||
|
# -DFEATURE_LEDSTRIP
|
||||||
|
# -DPINS_LEDSTRIP=26
|
||||||
)
|
)
|
||||||
|
@@ -84,4 +84,7 @@ set(BOBBYCAR_BUILDFLAGS
|
|||||||
-DFEATURE_GARAGE
|
-DFEATURE_GARAGE
|
||||||
-DFEATURE_NTP
|
-DFEATURE_NTP
|
||||||
# -DFEATURE_WIRELESS_CONFIG
|
# -DFEATURE_WIRELESS_CONFIG
|
||||||
|
-DFEATURE_LEDSTRIP
|
||||||
|
-DPINS_LEDSTRIP=26
|
||||||
|
-DLEDSTRIP_LENGTH=95
|
||||||
)
|
)
|
||||||
|
@@ -126,6 +126,7 @@ set(headers
|
|||||||
icons/unchecked.h
|
icons/unchecked.h
|
||||||
icons/update.h
|
icons/update.h
|
||||||
icons/wifi.h
|
icons/wifi.h
|
||||||
|
ledstrip.h
|
||||||
menudisplay.h
|
menudisplay.h
|
||||||
menuitem.h
|
menuitem.h
|
||||||
modes/defaultmode.h
|
modes/defaultmode.h
|
||||||
@@ -185,9 +186,9 @@ set(sources
|
|||||||
|
|
||||||
set(dependencies
|
set(dependencies
|
||||||
libsodium freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver
|
libsodium freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver
|
||||||
arduino-esp32 ArduinoJson esp-nimble-cpp
|
arduino-esp32 ArduinoJson esp-nimble-cpp FastLED-idf TFT_eSPI
|
||||||
bobbycar-protocol cpputils cxx-ring-buffer date
|
bobbycar-protocol cpputils cxx-ring-buffer date
|
||||||
espasynchttpreq espasyncota espchrono espcpputils esphttpdutils espwifistack expected fmt TFT_eSPI
|
espasynchttpreq espasyncota espchrono espcpputils esphttpdutils espwifistack expected fmt
|
||||||
)
|
)
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
|
51
main/ledstrip.h
Normal file
51
main/ledstrip.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <FastLED.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::array<CRGB, LEDSTRIP_LENGTH> leds;
|
||||||
|
uint8_t gHue = 0;
|
||||||
|
|
||||||
|
void initLedStrip()
|
||||||
|
{
|
||||||
|
FastLED.addLeds<NEOPIXEL, PINS_LEDSTRIP>(std::begin(leds), leds.size())
|
||||||
|
.setCorrection(TypicalSMD5050);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateLedStrip()
|
||||||
|
{
|
||||||
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; }
|
||||||
|
|
||||||
|
if (brems && *brems > 50.f)
|
||||||
|
{
|
||||||
|
auto color = avgSpeedKmh < -0.1f ? CRGB{255, 255, 255} : CRGB{255, 0, 0};
|
||||||
|
constexpr auto kleinerOffset = 4;
|
||||||
|
constexpr auto grosserOffset = 10;
|
||||||
|
|
||||||
|
const auto center = std::begin(leds) + (leds.size() / 2) + 1;
|
||||||
|
|
||||||
|
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
|
||||||
|
std::fill(center - grosserOffset, center - kleinerOffset, color);
|
||||||
|
std::fill(center + kleinerOffset, center + grosserOffset, color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fadeToBlackBy(std::begin(leds), leds.size(), 20);
|
||||||
|
|
||||||
|
uint8_t dothue = 0;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
leds[beatsin16(i + 7, 0, leds.size())] |= CHSV(dothue, 200, 255);
|
||||||
|
dothue += 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FastLED.show();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
#endif
|
@@ -134,6 +134,9 @@ using namespace std::chrono_literals;
|
|||||||
#endif
|
#endif
|
||||||
#include "wifi_bobbycar.h"
|
#include "wifi_bobbycar.h"
|
||||||
#include "time_bobbycar.h"
|
#include "time_bobbycar.h"
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
#include "ledstrip.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::optional<espchrono::millis_clock::time_point> lastWifiUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastWifiUpdate;
|
||||||
@@ -154,6 +157,9 @@ std::optional<espchrono::millis_clock::time_point> lastCloudUpdate;
|
|||||||
#ifdef FEATURE_NTP
|
#ifdef FEATURE_NTP
|
||||||
std::optional<espchrono::millis_clock::time_point> lastNtpUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastNtpUpdate;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
std::optional<espchrono::millis_clock::time_point> lastLedstripUpdate;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void app_main()
|
extern "C" void app_main()
|
||||||
@@ -173,6 +179,32 @@ extern "C" void app_main()
|
|||||||
|
|
||||||
initScreen();
|
initScreen();
|
||||||
|
|
||||||
|
bootLabel.redraw("settings");
|
||||||
|
settings = presets::defaultSettings;
|
||||||
|
stringSettings = presets::makeDefaultStringSettings();
|
||||||
|
|
||||||
|
if (settingsPersister.init())
|
||||||
|
{
|
||||||
|
if (!settingsPersister.openCommon())
|
||||||
|
ESP_LOGE("BOBBY", "openCommon() failed");
|
||||||
|
|
||||||
|
if (!settingsPersister.openProfile(0))
|
||||||
|
ESP_LOGE("BOBBY", "openProfile(0) failed");
|
||||||
|
|
||||||
|
loadSettings();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ESP_LOGE("BOBBY", "init() failed");
|
||||||
|
|
||||||
|
bootLabel.redraw("deviceName");
|
||||||
|
if (const auto result = wifi_stack::get_default_mac_addr())
|
||||||
|
std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", result->at(3), result->at(4), result->at(5));
|
||||||
|
else
|
||||||
|
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
||||||
|
|
||||||
|
bootLabel.redraw("wifi");
|
||||||
|
wifi_begin();
|
||||||
|
|
||||||
#ifdef FEATURE_DPAD
|
#ifdef FEATURE_DPAD
|
||||||
bootLabel.redraw("dpad");
|
bootLabel.redraw("dpad");
|
||||||
dpad::init();
|
dpad::init();
|
||||||
@@ -204,32 +236,6 @@ extern "C" void app_main()
|
|||||||
digitalWrite(PINS_MOSFET2, LOW);
|
digitalWrite(PINS_MOSFET2, LOW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bootLabel.redraw("settings");
|
|
||||||
settings = presets::defaultSettings;
|
|
||||||
stringSettings = presets::makeDefaultStringSettings();
|
|
||||||
|
|
||||||
if (settingsPersister.init())
|
|
||||||
{
|
|
||||||
if (!settingsPersister.openCommon())
|
|
||||||
ESP_LOGE("BOBBY", "openCommon() failed");
|
|
||||||
|
|
||||||
if (!settingsPersister.openProfile(0))
|
|
||||||
ESP_LOGE("BOBBY", "openProfile(0) failed");
|
|
||||||
|
|
||||||
loadSettings();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ESP_LOGE("BOBBY", "init() failed");
|
|
||||||
|
|
||||||
bootLabel.redraw("deviceName");
|
|
||||||
if (const auto result = wifi_stack::get_default_mac_addr())
|
|
||||||
std::sprintf(deviceName, STRING(DEVICE_PREFIX) "_%02hhx%02hhx%02hhx", result->at(3), result->at(4), result->at(5));
|
|
||||||
else
|
|
||||||
ESP_LOGE("MAIN", "get_default_mac_addr() failed: %.*s", result.error().size(), result.error().data());
|
|
||||||
|
|
||||||
bootLabel.redraw("wifi");
|
|
||||||
wifi_begin();
|
|
||||||
|
|
||||||
#ifdef FEATURE_SERIAL
|
#ifdef FEATURE_SERIAL
|
||||||
bootLabel.redraw("swap front back");
|
bootLabel.redraw("swap front back");
|
||||||
updateSwapFrontBack();
|
updateSwapFrontBack();
|
||||||
@@ -256,6 +262,7 @@ extern "C" void app_main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_CAN
|
#ifdef FEATURE_CAN
|
||||||
|
bootLabel.redraw("can");
|
||||||
can::initCan();
|
can::initCan();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -267,6 +274,11 @@ extern "C" void app_main()
|
|||||||
controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2);
|
controllers.back.serial.get().begin(38400, SERIAL_8N1, PINS_RX2, PINS_TX2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
bootLabel.redraw("LED strip");
|
||||||
|
initLedStrip();
|
||||||
|
#endif
|
||||||
|
|
||||||
raw_gas = std::nullopt;
|
raw_gas = std::nullopt;
|
||||||
raw_brems = std::nullopt;
|
raw_brems = std::nullopt;
|
||||||
gas = std::nullopt;
|
gas = std::nullopt;
|
||||||
@@ -451,5 +463,14 @@ extern "C" void app_main()
|
|||||||
#ifdef FEATURE_BMS
|
#ifdef FEATURE_BMS
|
||||||
bms::update();
|
bms::update();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_LEDSTRIP
|
||||||
|
if (!lastLedstripUpdate || now - *lastLedstripUpdate >= 1000ms / 60)
|
||||||
|
{
|
||||||
|
updateLedStrip();
|
||||||
|
|
||||||
|
lastLedstripUpdate = now;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -127,6 +127,13 @@ CONFIG_PARTITION_TABLE_OFFSET=0xf000
|
|||||||
CONFIG_PARTITION_TABLE_MD5=y
|
CONFIG_PARTITION_TABLE_MD5=y
|
||||||
# end of Partition Table
|
# end of Partition Table
|
||||||
|
|
||||||
|
#
|
||||||
|
# FastLED
|
||||||
|
#
|
||||||
|
# CONFIG_FASTLED_METHOD_I2S is not set
|
||||||
|
CONFIG_FASTLED_METHOD_RMT=y
|
||||||
|
# end of FastLED
|
||||||
|
|
||||||
#
|
#
|
||||||
# Arduino Configuration
|
# Arduino Configuration
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user