rgb led
This commit is contained in:
29
RotaxMonitor/lib/led/led.cpp
Normal file
29
RotaxMonitor/lib/led/led.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include <led.h>
|
||||||
|
|
||||||
|
RGBled::RGBled(const uint8_t pin, const uint8_t num)
|
||||||
|
{
|
||||||
|
m_led = Adafruit_NeoPixel(num, pin, NEO_GRB + NEO_KHZ800);
|
||||||
|
m_led.begin();
|
||||||
|
m_led.setPixelColor(0, RED);
|
||||||
|
m_led.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
RGBled::~RGBled()
|
||||||
|
{
|
||||||
|
m_led.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RGBled::setStatus(const LedStatus s)
|
||||||
|
{
|
||||||
|
if (m_status == s) return;
|
||||||
|
m_status = s;
|
||||||
|
RGB_BUILTIN_LED_COLOR_ORDER
|
||||||
|
m_led.setPixelColor(0, s);
|
||||||
|
m_led.setBrightness(16);
|
||||||
|
m_led.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
const RGBled::LedStatus RGBled::getSatus(void)
|
||||||
|
{
|
||||||
|
return m_status;
|
||||||
|
}
|
||||||
48
RotaxMonitor/lib/led/led.h
Normal file
48
RotaxMonitor/lib/led/led.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// System Inlcudes
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define RED 0x00FF00
|
||||||
|
#define GREEN 0xFF0000
|
||||||
|
#define BLUE 0x0000FF
|
||||||
|
#define WHITE 0xFFFFFF
|
||||||
|
#define YELLOW 0xFFFF00
|
||||||
|
#define CYAN 0xFF00FF
|
||||||
|
#define MAGENTA 0x00FFFF
|
||||||
|
#define ORANGE 0xA5FF00
|
||||||
|
#define PURPLE 0x008080
|
||||||
|
#define PINK 0x69FFB4
|
||||||
|
#define LIME 0xCD3232
|
||||||
|
#define SKY_BLUE 0xCE87EB
|
||||||
|
#define GOLD 0xD7FF00
|
||||||
|
#define TURQUOISE 0xE040D0
|
||||||
|
#define INDIGO 0x004B82
|
||||||
|
#define GRAY 0x808080
|
||||||
|
|
||||||
|
class RGBled
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum LedStatus
|
||||||
|
{
|
||||||
|
OK = GREEN,
|
||||||
|
ERROR = RED,
|
||||||
|
INIT = YELLOW,
|
||||||
|
DATA_A = CYAN,
|
||||||
|
DATA_B = MAGENTA,
|
||||||
|
DATA_ALL = ORANGE,
|
||||||
|
IDLE = GRAY
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
RGBled(const uint8_t pin = 48, const uint8_t num = 1);
|
||||||
|
~RGBled();
|
||||||
|
|
||||||
|
void setStatus(const LedStatus s);
|
||||||
|
const LedStatus getSatus(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Adafruit_NeoPixel m_led;
|
||||||
|
LedStatus m_status = LedStatus::IDLE;
|
||||||
|
};
|
||||||
@@ -20,6 +20,7 @@ lib_deps =
|
|||||||
hideakitai/PCA95x5@^0.1.3
|
hideakitai/PCA95x5@^0.1.3
|
||||||
me-no-dev/AsyncTCP@^3.3.2
|
me-no-dev/AsyncTCP@^3.3.2
|
||||||
me-no-dev/ESPAsyncWebServer@^3.6.0
|
me-no-dev/ESPAsyncWebServer@^3.6.0
|
||||||
|
adafruit/Adafruit NeoPixel@^1.15.4
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = /dev/ttyACM1
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
@@ -45,6 +46,7 @@ platform = ${env:esp32-s3-devkitc1-n16r8.platform}
|
|||||||
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
|
framework = ${env:esp32-s3-devkitc1-n16r8.framework}
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
${env:esp32-s3-devkitc1-n16r8.lib_deps}
|
||||||
|
adafruit/Adafruit NeoPixel@^1.15.4
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
upload_port = /dev/ttyACM1
|
upload_port = /dev/ttyACM1
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <datasave.h>
|
#include <datasave.h>
|
||||||
#include <webserver.h>
|
#include <webserver.h>
|
||||||
#include <ui.h>
|
#include <ui.h>
|
||||||
|
#include <led.h>
|
||||||
|
|
||||||
// Defines to enable channel B
|
// Defines to enable channel B
|
||||||
#define CH_B_ENABLE
|
#define CH_B_ENABLE
|
||||||
@@ -76,6 +77,8 @@ void setup()
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// global variables
|
// global variables
|
||||||
|
RGBled led;
|
||||||
|
led.setStatus(RGBled::LedStatus::INIT);
|
||||||
bool running = true;
|
bool running = true;
|
||||||
const uint32_t max_queue = 128;
|
const uint32_t max_queue = 128;
|
||||||
const uint32_t filter_k = 10;
|
const uint32_t filter_k = 10;
|
||||||
@@ -219,6 +222,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Real Time Tasks A & B initialized");
|
LOG_DEBUG("Real Time Tasks A & B initialized");
|
||||||
|
led.setStatus(RGBled::LedStatus::OK);
|
||||||
|
|
||||||
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
bool partial_save = false; // flag to indicate if a partial save has been done after a timeout
|
||||||
auto last_data = millis();
|
auto last_data = millis();
|
||||||
@@ -264,9 +268,15 @@ void loop()
|
|||||||
#endif
|
#endif
|
||||||
// Update last data
|
// Update last data
|
||||||
if (dataA == pdTRUE || dataB == pdTRUE)
|
if (dataA == pdTRUE || dataB == pdTRUE)
|
||||||
{
|
|
||||||
last_data = millis();
|
last_data = millis();
|
||||||
}
|
|
||||||
|
// Update Led color
|
||||||
|
if (dataA == pdTRUE && dataB == pdFALSE)
|
||||||
|
led.setStatus(RGBled::DATA_A);
|
||||||
|
else if (dataB == pdTRUE && dataA == pdFALSE)
|
||||||
|
led.setStatus(RGBled::DATA_B);
|
||||||
|
else
|
||||||
|
led.setStatus(RGBled::DATA_ALL);
|
||||||
|
|
||||||
if (dataA == pdTRUE)
|
if (dataA == pdTRUE)
|
||||||
{
|
{
|
||||||
@@ -314,7 +324,8 @@ void loop()
|
|||||||
partial_save = true;
|
partial_save = true;
|
||||||
first_save = true;
|
first_save = true;
|
||||||
}
|
}
|
||||||
//Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
// Serial.printf("[%d] Waiting for data...\r", wait_count++);
|
||||||
|
led.setStatus(RGBled::LedStatus::IDLE);
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +335,6 @@ void loop()
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
printRunningTasksMod(Serial);
|
printRunningTasksMod(Serial);
|
||||||
last_info = millis();
|
last_info = millis();
|
||||||
|
|
||||||
}
|
}
|
||||||
} //////////////// INNER LOOP /////////////////////
|
} //////////////// INNER LOOP /////////////////////
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user