Skip to content

LedFeedbackClass fix led pin not initialized #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/utility/LEDFeedback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void LEDFeedbackClass::setMode(LEDFeedbackMode mode) {
case LEDFeedbackMode::NONE:
{
_ledChangeInterval = 0;
turnOFF();
#ifdef BOARD_HAS_LED_MATRIX
ledMatrixAnimationHandler.clear();
#endif
Expand Down Expand Up @@ -288,14 +289,11 @@ void LEDFeedbackClass::restart() {
}

void LEDFeedbackClass::update() {
if(stopped) {
if(stopped || _mode == LEDFeedbackMode::NONE) {
return;
}

if(_ledChangeInterval == 0) {
turnOFF();
return;
} else if (_ledChangeInterval == ALWAYS_ON_INTERVAL) {
if (_ledChangeInterval == ALWAYS_ON_INTERVAL) {
turnON();
return;
}
Expand Down Expand Up @@ -330,11 +328,13 @@ void LEDFeedbackClass::update() {
}

void LEDFeedbackClass::turnOFF() {
#ifdef BOARD_USE_NINA
WiFiDrv::digitalWrite(_ledPin, LED_OFF);
#else
digitalWrite(_ledPin, LED_OFF);
#endif
if(_ledPin != INVALID_LED_PIN) {
#ifdef BOARD_USE_NINA
WiFiDrv::digitalWrite(_ledPin, LED_OFF);
#else
digitalWrite(_ledPin, LED_OFF);
#endif
}
#ifdef BOARD_HAS_LED_MATRIX
if(_framePtr != nullptr){
ledMatrixAnimationHandler.clear();
Expand All @@ -345,11 +345,13 @@ void LEDFeedbackClass::turnOFF() {
}

void LEDFeedbackClass::turnON() {
#ifdef BOARD_USE_NINA
WiFiDrv::digitalWrite(_ledPin, LED_ON);
#else
digitalWrite(_ledPin, LED_ON);
#endif
if(_ledPin != INVALID_LED_PIN) {
#ifdef BOARD_USE_NINA
WiFiDrv::digitalWrite(_ledPin, LED_ON);
#else
digitalWrite(_ledPin, LED_ON);
#endif
}
#ifdef BOARD_HAS_LED_MATRIX
if(_framePtr != nullptr){
ledMatrixAnimationHandler.loadFrame(_framePtr);
Expand Down
6 changes: 3 additions & 3 deletions src/utility/LEDFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once
#include "Arduino.h"


#define INVALID_LED_PIN -1

class LEDFeedbackClass {
public:
Expand Down Expand Up @@ -37,8 +37,8 @@ class LEDFeedbackClass {
uint32_t _lastUpdate = 0;
uint32_t _count = 0;
bool _ledState = false;
uint16_t _ledPin = 0;
int _ledPin = INVALID_LED_PIN;
uint32_t* _framePtr = nullptr;
int32_t _ledChangeInterval = 500;
int32_t _ledChangeInterval = 0;
Copy link
Preview

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the default value of _ledChangeInterval from 500 to 0 may have unintended side effects. The original value of 500 appears to be a meaningful default interval, and setting it to 0 could affect existing behavior where this interval is expected to have a non-zero value.

Suggested change
int32_t _ledChangeInterval = 0;
int32_t _ledChangeInterval = 500;

Copilot uses AI. Check for mistakes.

bool stopped = false;
};
Loading