From aaa2c6dac4039caecafb9dfffadb40b2c8fc43c8 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 10 Jan 2023 08:39:51 +0100 Subject: [PATCH] Revert "WIP: try to safe energy (deinit pio)" This reverts commit 29272d43bc7bf77cf6f4dc08ecc00c4cc36c73d7. --- src/abfall.cpp | 43 ++++++++++++++++++------------------------- src/ws2812.cpp | 6 ++---- src/ws2812.h | 2 -- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/abfall.cpp b/src/abfall.cpp index 94d20dc..aaeb08b 100644 --- a/src/abfall.cpp +++ b/src/abfall.cpp @@ -32,7 +32,7 @@ int main() { #endif printf("Firmware version: %s\n", PROJECT_VERSION); - // WS2812 led(WS2812_PIN); + WS2812 led(WS2812_PIN); wifi_enable(); // Enable Wifi in order to set time and retrieve data @@ -96,26 +96,22 @@ int main() { while (currentTime < timestamp) { size_t index = count % wasteDate.wasteTypes.size(); - { - WS2812 led(WS2812_PIN); - - switch (wasteDate.wasteTypes.at(index)) { - case Waste::GelberSack: - led.switchColor(Color::YELLOW); - break; - case Waste::Restmuell: - led.switchColor(Color::RED); - break; - case Waste::Papiertonne: - led.switchColor(Color::BLUE); - break; - case Waste::Problemstoffmobil: - led.switchColor(Color::CYAN); - break; - case Waste::Biotonne: - led.switchColor(Color::GREEN); - break; - } + switch (wasteDate.wasteTypes.at(index)) { + case Waste::GelberSack: + led.switchColor(Color::YELLOW); + break; + case Waste::Restmuell: + led.switchColor(Color::RED); + break; + case Waste::Papiertonne: + led.switchColor(Color::BLUE); + break; + case Waste::Problemstoffmobil: + led.switchColor(Color::CYAN); + break; + case Waste::Biotonne: + led.switchColor(Color::GREEN); + break; } auto timeLeft = timestamp - currentTime; @@ -131,10 +127,7 @@ int main() { } } else { - { - WS2812 led(WS2812_PIN); - led.blinkReady(); - } + led.blinkReady(); sleep_until(static_cast(timestamp)); } } diff --git a/src/ws2812.cpp b/src/ws2812.cpp index 12d2a34..c7ad5ac 100644 --- a/src/ws2812.cpp +++ b/src/ws2812.cpp @@ -1,13 +1,11 @@ #include "ws2812.h" WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_sm{sm} { - m_offset = pio_add_program(m_pio, &ws2812_program); - ws2812_program_init(m_pio, m_sm, m_offset, gpio, 800000, true); + uint offset = pio_add_program(m_pio, &ws2812_program); + ws2812_program_init(m_pio, m_sm, offset, gpio, 800000, true); switchColor(Color::OFF); } -WS2812::~WS2812() { pio_remove_program(m_pio, &ws2812_program, m_offset); } - void WS2812::switchColor(Color color) { putPixel(static_cast(color)); } void WS2812::blinkReady() { diff --git a/src/ws2812.h b/src/ws2812.h index 2d0d05c..229fccf 100644 --- a/src/ws2812.h +++ b/src/ws2812.h @@ -17,7 +17,6 @@ enum class Color : uint32_t { class WS2812 { public: WS2812(uint gpio, PIO pio = pio0, uint sm = 0); - virtual ~WS2812(); void switchColor(Color color); void blinkReady(); @@ -25,5 +24,4 @@ class WS2812 { void putPixel(uint32_t pixel_rgb); PIO m_pio; uint m_sm; - uint m_offset{0}; };