-
Notifications
You must be signed in to change notification settings - Fork 0
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
RgbPwmLed.StartPulse - bug in the overloaded constructor that includes the TimeSpan pulseDuration parameter #279
Comments
good catch @E-R-T-W! We'll patch this up for the upcoming release :) |
Thanks @jorgedevs! So... I'm brand new to the Meadow F7, but I've worked with PIC microControllers with ME Labs PicBasic Pro for quite a while (I'm an old VB4/5/6 coder, then VB.NET, and now C# - absolutely love that I can code a microController with C# and .NET 👍). I realize that this is just an LED, but I'm looking at the example code and working towards controlling a 6 zone slab heating system in a very large industrial sawmill builing in Northern Canada - a Mickey Mouse 6 zone PID controller of sorts. The following simply discusses the use of the new Meadow App Project Template and the use and implementation of the RgbPwmLed class (it's where every single newbie like me starts): #1. Since the timing of the LED Pulse routines simply rely on 'await Task.Delay()', it doesn't work very well at all due to the overhead in the microController instructions. If you crank up the pulseDuration to several seconds, then what happens is that the LED pulse gets cut short, a lot short, and so it ramps up to full brightness, but then only dims 1/2 way down before it is cut off by the cancellation from the onboardLED.Stop() routine:
#2. This implementation can do nothing more than pulse the LEDs, it's analagous to locking up the UI thread in a normal C# application. i.e. the "doing more work" in the Console.WriteLine() for() loop will NEVER run, in the following code:
Since the Meadow F7 has an onboard clock, why not implement the ShowColorPulse() routine as follows, for example:
First, this solves point #1: timing is always perfect and the LED goes from zero to full on and back to zero perfectly regardless of how long the pulse duration is. Secondly, if you code the Run() routine as follows, then you DON'T block the main Run() routine and can execute other work while the LED pulses perfectly:
Anyway, I'm hoping not to have to roll my own for everything and thought it would be nice to make changes to the RgbPwmLed class so that it is much more usefull for all Meadow F7v2 users (every single newbie will start with the new Meadow App Project and the blinking LED). Thoughts? Comments? Thanks! P.S. I guess I'll post a new bug, and a new request, but would appreciate a quick comment back on the following: #3. The Meadow F7v2 has 2 DACs, but I see that they are not implemented and not on the road map either :( (as far as I can tell). #4. Is it just me? or a bug? About 1/2 the time when deploying an app to the Meadow F7v2 it just hangs. Then I have to reboot the Meadow (typically reseat the USB cable) and then have to kill VS2022 and start all over again (same thing happens with VS2019). Super annoying and super time consuming. This happens about 1/2 the time when deploying into debug mode to do In Circuit Debugging. Output Window: Build Build started... Output Window: Meadow Launching application... Connecting to Meadow on COM7 |
I just realized, in the example code I provided that uses the Real Time Clock, I didn't include the highBrightness and lowBrightness parameters. The example code should have been as follows:
and it can be called as follows:
|
Describe the bug
It's simply a copy and paste bug between overloaded constructors...
The first line "pulseDuration = TimeSpan.FromMilliseconds(600.0);" in the code for the overloaded RgbPwmLed.StartPulse constructor that includes the TimeSpan pulseDuration, should not exist! i.e. the first line in the following code should not exist!
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Each color should pulse the LED once for the duration of the TimeSpan pulseDuration parameter.
Screenshots
Not a screenshot, but here are the two overloaded constructors with IDENTICAL code (except for the signatures) and it's obvious that the first line of the 2nd overloaded constructor "pulseDuration = TimeSpan.FromMilliseconds(600.0);" should not be there - simply a copy and paste thing at the time of writing the code.
//
// Summary:
// Start the Pulse animation which gradually alternates the brightness of the LED
// between a low and high brightness setting.
//
// Parameters:
// color:
//
// highBrightness:
//
// lowBrightness:
public void StartPulse(Color color, float highBrightness = 1f, float lowBrightness = 0.15f)
{
TimeSpan pulseDuration = TimeSpan.FromMilliseconds(600.0);
if (highBrightness > 1f || highBrightness <= 0f)
{
throw new ArgumentOutOfRangeException("highBrightness", "onBrightness must be > 0 and <= 1");
}
Developer tools (please complete the following information as best as you can):
Meadow (please complete the following information as best as you can):
Most of these vaues can be found by running
meadow device info
using the Meadow CLI.Additional context
None - bug is obviously just a cut and paste issue.
The text was updated successfully, but these errors were encountered: