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

LedFeedbackClass fix led pin not initialized #22

merged 1 commit into from
Aug 13, 2025

Conversation

fabik111
Copy link
Collaborator

Issue

It has been reported a malfunction of the OPTA relay number 1 that was continously turning on and off.
The device was running a Cloud Sketch 2.0 with the NetworkConfigurator enabled.

After investigation the problem was found on a not properly initialization of the pin for the feedback led when no feedback mode is selected.

Changes

  • Initialize the _ledPin with an invalid value and check its value before setting it ON or OFF
  • turn off the led when the mode NONE is selected

@fabik111 fabik111 requested review from pennam and Copilot August 12, 2025 12:28
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.27%. Comparing base (1b4ad0f) to head (f20103f).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #22   +/-   ##
=======================================
  Coverage   90.27%   90.27%           
=======================================
  Files           7        7           
  Lines         720      720           
  Branches       86       86           
=======================================
  Hits          650      650           
  Misses         70       70           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Memory usage change @ 8fef0c7

Board flash % RAM for global variables %
arduino:mbed_giga:giga 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 +20 - +20 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nicla:nicla_vision 🔺 +64 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 🔺 +16 - +16 0.0 - 0.0 🔺 +8 - +8 0.0 - 0.0
arduino:renesas_uno:unor4wifi 🔺 +16 - +16 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
arduino:samd:mkrwifi1010 🔺 +24 - +24 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
arduino:samd:nano_33_iot 🔺 +32 - +32 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
Click for full report table
Board examples/NetworkConfiguratorDemo
flash
% examples/NetworkConfiguratorDemo
RAM for global variables
%
arduino:mbed_giga:giga 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 20 0.0 0 0.0
arduino:mbed_nicla:nicla_vision 64 0.0 0 0.0
arduino:mbed_opta:opta 64 0.0 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 16 0.0 8 0.0
arduino:renesas_uno:unor4wifi 16 0.01 8 0.02
arduino:samd:mkrwifi1010 24 0.01 8 0.02
arduino:samd:nano_33_iot 32 0.01 8 0.02
Click for full report CSV
Board,examples/NetworkConfiguratorDemo<br>flash,%,examples/NetworkConfiguratorDemo<br>RAM for global variables,%
arduino:mbed_giga:giga,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,20,0.0,0,0.0
arduino:mbed_nicla:nicla_vision,64,0.0,0,0.0
arduino:mbed_opta:opta,64,0.0,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A
arduino:renesas_portenta:portenta_c33,16,0.0,8,0.0
arduino:renesas_uno:unor4wifi,16,0.01,8,0.02
arduino:samd:mkrwifi1010,24,0.01,8,0.02
arduino:samd:nano_33_iot,32,0.01,8,0.02

Copilot

This comment was marked as outdated.

@fabik111 fabik111 requested a review from Copilot August 12, 2025 12:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug where an uninitialized LED pin was causing an OPTA relay to malfunction by continuously turning on and off. The fix ensures proper pin initialization and validation before LED operations.

  • Initialize LED pin with an invalid value and validate before operations
  • Turn off the LED when NONE mode is selected instead of during updates
  • Change LED pin type from uint16_t to int to support negative invalid value

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/utility/LEDFeedback.h Adds invalid pin constant, changes pin type to int, and initializes with invalid value
src/utility/LEDFeedback.cpp Adds pin validation checks and moves LED off logic to mode selection

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.

@pennam
Copy link
Collaborator

pennam commented Aug 12, 2025

why not checking for _mode != LEDFeedbackMode::NONE in the update function?

@fabik111
Copy link
Collaborator Author

fabik111 commented Aug 12, 2025

why not checking for _mode != LEDFeedbackMode::NONE in the update function?

Because it's equivalent, but if it's not clear I will update the code.

Edit: updated for checking the mode

Copy link

Memory usage change @ f20103f

Board flash % RAM for global variables %
arduino:mbed_giga:giga 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 +22 - +22 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nicla:nicla_vision 🔺 +64 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 +64 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 🔺 +24 - +24 0.0 - 0.0 🔺 +8 - +8 0.0 - 0.0
arduino:renesas_uno:unor4wifi 🔺 +16 - +16 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
arduino:samd:mkrwifi1010 🔺 +24 - +24 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
arduino:samd:nano_33_iot 🔺 +32 - +32 +0.01 - +0.01 🔺 +8 - +8 +0.02 - +0.02
Click for full report table
Board examples/NetworkConfiguratorDemo
flash
% examples/NetworkConfiguratorDemo
RAM for global variables
%
arduino:mbed_giga:giga 0 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 22 0.0 0 0.0
arduino:mbed_nicla:nicla_vision 64 0.0 0 0.0
arduino:mbed_opta:opta 64 0.0 0 0.0
arduino:mbed_portenta:envie_m7 N/A N/A N/A N/A
arduino:renesas_portenta:portenta_c33 24 0.0 8 0.0
arduino:renesas_uno:unor4wifi 16 0.01 8 0.02
arduino:samd:mkrwifi1010 24 0.01 8 0.02
arduino:samd:nano_33_iot 32 0.01 8 0.02
Click for full report CSV
Board,examples/NetworkConfiguratorDemo<br>flash,%,examples/NetworkConfiguratorDemo<br>RAM for global variables,%
arduino:mbed_giga:giga,0,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,22,0.0,0,0.0
arduino:mbed_nicla:nicla_vision,64,0.0,0,0.0
arduino:mbed_opta:opta,64,0.0,0,0.0
arduino:mbed_portenta:envie_m7,N/A,N/A,N/A,N/A
arduino:renesas_portenta:portenta_c33,24,0.0,8,0.0
arduino:renesas_uno:unor4wifi,16,0.01,8,0.02
arduino:samd:mkrwifi1010,24,0.01,8,0.02
arduino:samd:nano_33_iot,32,0.01,8,0.02

@fabik111 fabik111 merged commit 0f19b47 into main Aug 13, 2025
29 checks passed
@fabik111 fabik111 deleted the fix-led-pin branch August 13, 2025 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants