initial commit
This commit is contained in:
26
lib/indicator_led/src/GenericDevBoardIndicatorLed.cpp
Normal file
26
lib/indicator_led/src/GenericDevBoardIndicatorLed.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "Arduino.h"
|
||||
#include "GenericDevBoardIndicatorLed.h"
|
||||
|
||||
#ifdef LED_BUILTIN
|
||||
const uint8_t BUILT_IN_LED = LED_BUILTIN;
|
||||
#else
|
||||
const uint8_t BUILT_IN_LED = GPIO_NUM_2;
|
||||
#endif
|
||||
|
||||
GenericDevBoardIndicatorLed::GenericDevBoardIndicatorLed()
|
||||
{
|
||||
pinMode(BUILT_IN_LED, OUTPUT);
|
||||
}
|
||||
|
||||
// we don't really have any colors so just use the built in LED
|
||||
void GenericDevBoardIndicatorLed::set_led_rgb(uint32_t color)
|
||||
{
|
||||
if (color == 0)
|
||||
{
|
||||
digitalWrite(BUILT_IN_LED, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(BUILT_IN_LED, HIGH);
|
||||
}
|
||||
}
|
||||
12
lib/indicator_led/src/GenericDevBoardIndicatorLed.h
Normal file
12
lib/indicator_led/src/GenericDevBoardIndicatorLed.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "IndicatorLed.h"
|
||||
|
||||
class GenericDevBoardIndicatorLed : public IndicatorLed
|
||||
{
|
||||
protected:
|
||||
void set_led_rgb(uint32_t color);
|
||||
|
||||
public:
|
||||
GenericDevBoardIndicatorLed();
|
||||
};
|
||||
34
lib/indicator_led/src/IndicatorLed.cpp
Normal file
34
lib/indicator_led/src/IndicatorLed.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <Arduino.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include "IndicatorLed.h"
|
||||
|
||||
void update_indicator_task(void *param)
|
||||
{
|
||||
IndicatorLed *indicator = reinterpret_cast<IndicatorLed *>(param);
|
||||
while (true)
|
||||
{
|
||||
if (indicator->m_is_flashing)
|
||||
{
|
||||
indicator->set_led_rgb(indicator->m_flash_color);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
indicator->set_led_rgb(indicator->m_default_color);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void IndicatorLed::begin()
|
||||
{
|
||||
TaskHandle_t task_handle;
|
||||
xTaskCreate(update_indicator_task, "Indicator LED Task", 4096, this, 0, &task_handle);
|
||||
}
|
||||
|
||||
void IndicatorLed::set_is_flashing(bool is_flashing, uint32_t flash_color)
|
||||
{
|
||||
m_is_flashing = is_flashing;
|
||||
m_flash_color = flash_color;
|
||||
}
|
||||
void IndicatorLed::set_default_color(uint32_t color)
|
||||
{
|
||||
m_default_color = color;
|
||||
}
|
||||
21
lib/indicator_led/src/IndicatorLed.h
Normal file
21
lib/indicator_led/src/IndicatorLed.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class IndicatorLed
|
||||
{
|
||||
private:
|
||||
bool m_is_flashing = false;
|
||||
uint32_t m_default_color = 0;
|
||||
uint32_t m_flash_color = 0;
|
||||
|
||||
protected:
|
||||
virtual void set_led_rgb(uint32_t color) = 0;
|
||||
|
||||
public:
|
||||
void begin();
|
||||
void set_is_flashing(bool is_flashing, uint32_t flash_color);
|
||||
void set_default_color(uint32_t color);
|
||||
|
||||
friend void update_indicator_task(void *param);
|
||||
};
|
||||
Reference in New Issue
Block a user