Version fonctionnelle 1.0

This commit is contained in:
2025-11-30 15:07:12 +01:00
parent 56d8cd96c8
commit 4c6c528d22
9 changed files with 269 additions and 124 deletions

View File

@@ -8,107 +8,108 @@
/**
* @brief Constructor - initialize with default state
*/
LEDIndicator::LEDIndicator() :
powerOn(false),
dccMode(false),
brightness(128),
lastUpdate(0),
pulsePhase(0) {
}
// LEDIndicator::LEDIndicator() :
// powerOn(false),
// dccMode(false),
// brightness(128),
// lastUpdate(0),
// pulsePhase(0)
// {}
LEDIndicator::LEDIndicator(){}
void LEDIndicator::begin() {
FastLED.addLeds<WS2812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(brightness);
// FastLED.addLeds<WS2812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
// FastLED.setBrightness(brightness);
// Initialize both LEDs to off
leds[LED_POWER] = COLOR_OFF;
leds[LED_MODE] = COLOR_OFF;
FastLED.show();
// leds[LED_POWER] = COLOR_OFF;
// leds[LED_MODE] = COLOR_OFF;
// FastLED.show();
Serial.println("LED Indicator initialized");
Serial.printf("LED Data Pin: %d, Num LEDs: %d\n", LED_DATA_PIN, NUM_LEDS);
// Serial.println("LED Indicator initialized");
// Serial.printf("LED Data Pin: %d, Num LEDs: %d\n", LED_DATA_PIN, NUM_LEDS);
}
void LEDIndicator::update() {
unsigned long now = millis();
// unsigned long now = millis();
// Update power LED
if (powerOn) {
leds[LED_POWER] = COLOR_POWER_ON;
} else {
leds[LED_POWER] = COLOR_POWER_OFF;
}
// // Update power LED
// if (powerOn) {
// leds[LED_POWER] = COLOR_POWER_ON;
// } else {
// leds[LED_POWER] = COLOR_POWER_OFF;
// }
// Update mode LED with subtle pulsing effect
if (now - lastUpdate > 20) {
lastUpdate = now;
pulsePhase++;
// if (now - lastUpdate > 20) {
// lastUpdate = now;
// pulsePhase++;
// Create gentle pulse effect
uint8_t pulseBrightness = 128 + (sin8(pulsePhase * 2) / 4);
// // Create gentle pulse effect
// uint8_t pulseBrightness = 128 + (sin8(pulsePhase * 2) / 4);
CRGB baseColor = dccMode ? COLOR_DCC : COLOR_ANALOG;
leds[LED_MODE] = baseColor;
leds[LED_MODE].fadeToBlackBy(255 - pulseBrightness);
}
// CRGB baseColor = dccMode ? COLOR_DCC : COLOR_ANALOG;
// leds[LED_MODE] = baseColor;
// leds[LED_MODE].fadeToBlackBy(255 - pulseBrightness);
// }
FastLED.show();
// FastLED.show();
}
void LEDIndicator::setPowerOn(bool on) {
if (powerOn != on) {
powerOn = on;
if (on) {
powerOnSequence();
}
}
// if (powerOn != on) {
// powerOn = on;
// if (on) {
// powerOnSequence();
// }
// }
}
void LEDIndicator::setMode(bool isDCC) {
if (dccMode != isDCC) {
dccMode = isDCC;
modeChangeEffect();
}
// if (dccMode != isDCC) {
// dccMode = isDCC;
// modeChangeEffect();
// }
}
void LEDIndicator::setBrightness(uint8_t newBrightness) {
brightness = newBrightness;
FastLED.setBrightness(brightness);
// brightness = newBrightness;
// FastLED.setBrightness(brightness);
}
void LEDIndicator::powerOnSequence() {
// Quick flash sequence on power on
for (int i = 0; i < 3; i++) {
leds[LED_POWER] = COLOR_POWER_ON;
FastLED.show();
delay(100);
leds[LED_POWER] = COLOR_OFF;
FastLED.show();
delay(100);
}
leds[LED_POWER] = COLOR_POWER_ON;
FastLED.show();
Serial.println("LED: Power ON sequence");
// // Quick flash sequence on power on
// for (int i = 0; i < 3; i++) {
// leds[LED_POWER] = COLOR_POWER_ON;
// FastLED.show();
// delay(100);
// leds[LED_POWER] = COLOR_OFF;
// FastLED.show();
// delay(100);
// }
// leds[LED_POWER] = COLOR_POWER_ON;
// FastLED.show();
// Serial.println("LED: Power ON sequence");
}
void LEDIndicator::modeChangeEffect() {
// Smooth transition effect when changing modes
CRGB targetColor = dccMode ? COLOR_DCC : COLOR_ANALOG;
// // Smooth transition effect when changing modes
// CRGB targetColor = dccMode ? COLOR_DCC : COLOR_ANALOG;
// Fade out
for (int i = 255; i >= 0; i -= 15) {
leds[LED_MODE].fadeToBlackBy(15);
FastLED.show();
delay(10);
}
// // Fade out
// for (int i = 255; i >= 0; i -= 15) {
// leds[LED_MODE].fadeToBlackBy(15);
// FastLED.show();
// delay(10);
// }
// Fade in new color
for (int i = 0; i <= 255; i += 15) {
leds[LED_MODE] = targetColor;
leds[LED_MODE].fadeToBlackBy(255 - i);
FastLED.show();
delay(10);
}
// // Fade in new color
// for (int i = 0; i <= 255; i += 15) {
// leds[LED_MODE] = targetColor;
// leds[LED_MODE].fadeToBlackBy(255 - i);
// FastLED.show();
// delay(10);
// }
Serial.printf("LED: Mode changed to %s\n", dccMode ? "DCC (Blue)" : "Analog (Yellow)");
// Serial.printf("LED: Mode changed to %s\n", dccMode ? "DCC (Blue)" : "Analog (Yellow)");
}