53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
#pragma once
|
|
|
|
/**
|
|
* @file StatusLed.h
|
|
* @brief NeoPixel RGB LED status indicator.
|
|
*
|
|
* Encodes BLE and WiFi operational state as colour + blink pattern:
|
|
*
|
|
* BLE Scanning → Blue pulse (on 100 ms / off 900 ms)
|
|
* BLE Connecting → Blue pulse (on 300 ms / off 300 ms)
|
|
* BLE Connected → Solid green
|
|
* BLE Disconnected → Red blink (on 200 ms / off 800 ms)
|
|
* BLE Error → Solid red
|
|
* WiFi AP active → Amber pulse (on 500 ms / off 500 ms)
|
|
* OTA in progress → Magenta rapid pulse
|
|
* All off → Black
|
|
*/
|
|
|
|
#include "Config.h"
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
class StatusLed {
|
|
public:
|
|
void begin();
|
|
|
|
/**
|
|
* @brief Call from loop() to update the LED animation.
|
|
* Non-blocking — uses millis() internally.
|
|
*/
|
|
void update(AppState::BleStatus ble, AppState::WifiStatus wifi, bool ota = false);
|
|
|
|
/** @brief Immediately set a solid colour (overrides animation until next update()). */
|
|
void setColor(uint32_t color, uint8_t brightness = 40);
|
|
|
|
/** @brief Turn off the LED. */
|
|
void off();
|
|
|
|
private:
|
|
Adafruit_NeoPixel _strip{STATUS_LED_COUNT, STATUS_LED_PIN, NEO_GRB + NEO_KHZ800};
|
|
|
|
uint32_t _lastToggle = 0;
|
|
bool _ledOn = false;
|
|
|
|
AppState::BleStatus _prevBle = AppState::BleStatus::IDLE;
|
|
AppState::WifiStatus _prevWifi = AppState::WifiStatus::OFF;
|
|
bool _prevOta = false;
|
|
|
|
void _pulse(uint32_t color, uint32_t onMs, uint32_t offMs, uint8_t brightness = 40);
|
|
void _solid(uint32_t color, uint8_t brightness = 40);
|
|
};
|
|
|
|
extern StatusLed statusLed;
|