Compare commits
2 commits
4e56888e49
...
a2a7521e1d
Author | SHA1 | Date | |
---|---|---|---|
a2a7521e1d | |||
29272d43bc |
3 changed files with 32 additions and 21 deletions
|
@ -32,7 +32,7 @@ int main() {
|
||||||
#endif
|
#endif
|
||||||
printf("Firmware version: %s\n", PROJECT_VERSION);
|
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
|
wifi_enable(); // Enable Wifi in order to set time and retrieve data
|
||||||
|
|
||||||
|
@ -89,29 +89,33 @@ int main() {
|
||||||
printf("%d-%02d-%02d %02d:%02d.%02d\n", dt.year, dt.month, dt.day, hour, dt.min, dt.sec);
|
printf("%d-%02d-%02d %02d:%02d.%02d\n", dt.year, dt.month, dt.day, hour, dt.min, dt.sec);
|
||||||
|
|
||||||
// If there was a waste bin pickup found AND we are in the evening (>= 18:00) …
|
// If there was a waste bin pickup found AND we are in the evening (>= 18:00) …
|
||||||
if (it != dates.end() && hour >= 18) {
|
if (it != dates.end() && hour >= 18 && hour < 23) {
|
||||||
auto wasteDate = *it;
|
auto wasteDate = *it;
|
||||||
size_t count{0};
|
size_t count{0};
|
||||||
auto currentTime = time_us_64();
|
auto currentTime = time_us_64();
|
||||||
while (currentTime < timestamp) {
|
while (currentTime < timestamp) {
|
||||||
size_t index = count % wasteDate.wasteTypes.size();
|
size_t index = count % wasteDate.wasteTypes.size();
|
||||||
|
|
||||||
switch (wasteDate.wasteTypes.at(index)) {
|
{
|
||||||
case Waste::GelberSack:
|
WS2812 led(WS2812_PIN);
|
||||||
led.switchColor(Color::YELLOW);
|
|
||||||
break;
|
switch (wasteDate.wasteTypes.at(index)) {
|
||||||
case Waste::Restmuell:
|
case Waste::GelberSack:
|
||||||
led.switchColor(Color::RED);
|
led.switchColor(Color::YELLOW);
|
||||||
break;
|
break;
|
||||||
case Waste::Papiertonne:
|
case Waste::Restmuell:
|
||||||
led.switchColor(Color::BLUE);
|
led.switchColor(Color::RED);
|
||||||
break;
|
break;
|
||||||
case Waste::Problemstoffmobil:
|
case Waste::Papiertonne:
|
||||||
led.switchColor(Color::CYAN);
|
led.switchColor(Color::BLUE);
|
||||||
break;
|
break;
|
||||||
case Waste::Biotonne:
|
case Waste::Problemstoffmobil:
|
||||||
led.switchColor(Color::GREEN);
|
led.switchColor(Color::CYAN);
|
||||||
break;
|
break;
|
||||||
|
case Waste::Biotonne:
|
||||||
|
led.switchColor(Color::GREEN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto timeLeft = timestamp - currentTime;
|
auto timeLeft = timestamp - currentTime;
|
||||||
|
@ -127,7 +131,10 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
led.blinkReady();
|
{
|
||||||
|
WS2812 led(WS2812_PIN);
|
||||||
|
led.blinkReady();
|
||||||
|
}
|
||||||
sleep_until(static_cast<absolute_time_t>(timestamp));
|
sleep_until(static_cast<absolute_time_t>(timestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
#include "ws2812.h"
|
#include "ws2812.h"
|
||||||
|
|
||||||
WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_sm{sm} {
|
WS2812::WS2812(uint gpio, PIO pio, uint sm) : m_pio{pio}, m_sm{sm} {
|
||||||
uint offset = pio_add_program(m_pio, &ws2812_program);
|
m_offset = pio_add_program(m_pio, &ws2812_program);
|
||||||
ws2812_program_init(m_pio, m_sm, offset, gpio, 800000, true);
|
ws2812_program_init(m_pio, m_sm, m_offset, gpio, 800000, true);
|
||||||
switchColor(Color::OFF);
|
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::switchColor(Color color) { putPixel(static_cast<uint32_t>(color)); }
|
||||||
|
|
||||||
void WS2812::blinkReady() {
|
void WS2812::blinkReady() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ enum class Color : uint32_t {
|
||||||
class WS2812 {
|
class WS2812 {
|
||||||
public:
|
public:
|
||||||
WS2812(uint gpio, PIO pio = pio0, uint sm = 0);
|
WS2812(uint gpio, PIO pio = pio0, uint sm = 0);
|
||||||
|
virtual ~WS2812();
|
||||||
void switchColor(Color color);
|
void switchColor(Color color);
|
||||||
void blinkReady();
|
void blinkReady();
|
||||||
|
|
||||||
|
@ -24,4 +25,5 @@ class WS2812 {
|
||||||
void putPixel(uint32_t pixel_rgb);
|
void putPixel(uint32_t pixel_rgb);
|
||||||
PIO m_pio;
|
PIO m_pio;
|
||||||
uint m_sm;
|
uint m_sm;
|
||||||
|
uint m_offset{0};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue