Ver código fonte

Actually turn off LEDs when state set to off

master
jrhoffa 3 anos atrás
pai
commit
94f93d88e8
3 arquivos alterados com 16 adições e 2 exclusões
  1. +8
    -0
      main/leds.cpp
  2. +1
    -0
      main/leds.hpp
  3. +7
    -2
      main/main.cpp

+ 8
- 0
main/leds.cpp Ver arquivo

@@ -1,6 +1,8 @@
static const char *TAG = "leds";
#include <esp_log.h>

#include <cstring>

#include "leds.hpp"
#include "utils.hpp"

@@ -18,6 +20,7 @@ void LEDStrip::update_state() {
}

void LEDStrip::setLength(int _length) {
clear();
length_changing(_length);
delete[] pixels;
length = _length;
@@ -29,6 +32,11 @@ void LEDStrip::step() {
if (pattern) pattern->step(pixels, length, state);
}

void LEDStrip::clear() {
memset(pixels, 0, length * sizeof(*pixels));
show();
}

static std::string termcolor(Color c) {
return "\x1b[48;2;" +
std::to_string((int)c.r) + ";" +


+ 1
- 0
main/leds.hpp Ver arquivo

@@ -34,6 +34,7 @@ public:
~LEDStrip() { if (state) delete state; }

void step();
void clear();

virtual void show() = 0;
virtual void length_changing(int) {};


+ 7
- 2
main/main.cpp Ver arquivo

@@ -129,7 +129,11 @@ extern "C" void app_main(void) {
cJSON_Delete(json);
}

LEDStrip *LEDs = new SPI_LEDs(39); //new TerminalLEDs();
// TerminalLEDs()
// ScreenLEDs()
// SPI_LEDs(39);
LEDStrip *LEDs = new SPI_LEDs(39);
int frequency = 60;

while (true) {
// Trash the old preset in case we can't find the set effect
@@ -172,12 +176,13 @@ extern "C" void app_main(void) {
if (!pattern) ESP_LOGW(TAG, "No LED pattern set");
ESP_LOGI(TAG, "Waiting for new config");

LEDs->clear();
device.wait();

} else {
ESP_LOGI(TAG, "Starting animation");

int period_us = 1000000 / 30;
int period_us = 1000000 / frequency;
int64_t target_us = time_us();
int64_t profile_start = target_us;
#ifdef PROFILE_PERF


Carregando…
Cancelar
Salvar