WIP: try to safe energy (deinit pio)

This commit is contained in:
Martin Brodbeck 2023-01-09 08:10:35 +01:00
parent 4e56888e49
commit 29272d43bc
3 changed files with 31 additions and 20 deletions

View file

@ -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,6 +96,9 @@ 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);
@ -113,6 +116,7 @@ int main() {
led.switchColor(Color::GREEN);
break;
}
}
auto timeLeft = timestamp - currentTime;
@ -127,7 +131,10 @@ int main() {
}
} else {
{
WS2812 led(WS2812_PIN);
led.blinkReady();
}
sleep_until(static_cast<absolute_time_t>(timestamp));
}
}

View file

@ -1,11 +1,13 @@
#include "ws2812.h"
WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_sm{sm} {
uint offset = pio_add_program(m_pio, &ws2812_program);
ws2812_program_init(m_pio, m_sm, offset, gpio, 800000, true);
m_offset = pio_add_program(m_pio, &ws2812_program);
ws2812_program_init(m_pio, m_sm, m_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<uint32_t>(color)); }
void WS2812::blinkReady() {

View file

@ -17,6 +17,7 @@ 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();
@ -24,4 +25,5 @@ class WS2812 {
void putPixel(uint32_t pixel_rgb);
PIO m_pio;
uint m_sm;
uint m_offset{0};
};