Skip to content
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

Closed
E-R-T-W opened this issue Mar 31, 2023 · 3 comments

Comments

@E-R-T-W
Copy link

E-R-T-W commented Mar 31, 2023

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!

    public void StartPulse(Color color, TimeSpan pulseDuration, float highBrightness = 1f, float lowBrightness = 0.15f)
    {
        pulseDuration = TimeSpan.FromMilliseconds(600.0);
        if (highBrightness > 1f || highBrightness <= 0f)
        {
            throw new ArgumentOutOfRangeException("highBrightness", "onBrightness must be > 0 and <= 1");
        }

        if (lowBrightness >= 1f || lowBrightness < 0f)
        {
            throw new ArgumentOutOfRangeException("lowBrightness", "lowBrightness must be >= 0 and < 1");
        }

        if (lowBrightness >= highBrightness)
        {
            throw new Exception("offBrightness must be less than onBrightness");
        }

        Color = color;
        Stop();
        animationTask = new Task(async delegate
        {
            cancellationTokenSource = new CancellationTokenSource();
            await StartPulseAsync(color, pulseDuration, highBrightness, lowBrightness, cancellationTokenSource!.Token);
        });
        animationTask!.Start();
    }

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Meadow C# Application Project
  2. Modify the templated MeadowApp.cs code line 21 from "CycleColors(TimeSpan.FromMilliseconds(1000));" to "CycleColors(TimeSpan.FromMilliseconds(2400));"
  3. Modify the template MeadowApp.cs code line 61 from "onboardLed.StartPulse(color, duration / 2);" to "onboardLed.StartPulse(color, duration / 2, 1f, 0f);"
  4. You'll find that the LED Pulses twice for each color i.e. 600 milliSeconds * 4 = 2400 milliSeconds, ignoring the TimeSpan pulseDuration parameter.

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");
}

        if (lowBrightness >= 1f || lowBrightness < 0f)
        {
            throw new ArgumentOutOfRangeException("lowBrightness", "lowBrightness must be >= 0 and < 1");
        }

        if (lowBrightness >= highBrightness)
        {
            throw new Exception("offBrightness must be less than onBrightness");
        }

        Color = color;
        Stop();
        animationTask = new Task(async delegate
        {
            cancellationTokenSource = new CancellationTokenSource();
            await StartPulseAsync(color, pulseDuration, highBrightness, lowBrightness, cancellationTokenSource!.Token);
        });
        animationTask!.Start();
    }

    //
    // Summary:
    //     Start the Pulse animation which gradually alternates the brightness of the LED
    //     between a low and high brightness setting, using the durations provided.
    //
    // Parameters:
    //   color:
    //
    //   pulseDuration:
    //
    //   highBrightness:
    //
    //   lowBrightness:
    public void StartPulse(Color color, TimeSpan pulseDuration, float highBrightness = 1f, float lowBrightness = 0.15f)
    {
        pulseDuration = TimeSpan.FromMilliseconds(600.0);
        if (highBrightness > 1f || highBrightness <= 0f)
        {
            throw new ArgumentOutOfRangeException("highBrightness", "onBrightness must be > 0 and <= 1");
        }

        if (lowBrightness >= 1f || lowBrightness < 0f)
        {
            throw new ArgumentOutOfRangeException("lowBrightness", "lowBrightness must be >= 0 and < 1");
        }

        if (lowBrightness >= highBrightness)
        {
            throw new Exception("offBrightness must be less than onBrightness");
        }

        Color = color;
        Stop();
        animationTask = new Task(async delegate
        {
            cancellationTokenSource = new CancellationTokenSource();
            await StartPulseAsync(color, pulseDuration, highBrightness, lowBrightness, cancellationTokenSource!.Token);
        });
        animationTask!.Start();
    }

Developer tools (please complete the following information as best as you can):

  • OS and version: [Windows 10 Pro v21H2]
  • IDE and version: [Visual Studio Professional 2022 v17.5.3]
  • Meadow extension for IDE version: [VS 2022 Tools for Meadow v0.95.0]

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.

  • Meadow hardware version: [F7FeatherV2]
  • Meadow OS version: [0.9.4.0]
  • If they are different, please provide these versions as well.
    • Meadow Mono version: [0.9.4.0]
    • Meadow coprocessor version: [0.9.4.0]

Additional context
None - bug is obviously just a cut and paste issue.

@jorgedevs
Copy link

good catch @E-R-T-W! We'll patch this up for the upcoming release :)

@E-R-T-W
Copy link
Author

E-R-T-W commented Apr 1, 2023

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 implementation of the RgbPwmLed class seems rather odd to me (but could be just me as I'm new to this).

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:
void ShowColorPulse(Color color, TimeSpan duration)
{
onboardLed.StartPulse(color, duration / 2);
Thread.Sleep(duration);
onboardLed.Stop();
}

    public void Stop()
    {
        cancellationTokenSource?.Cancel();
        IsOn = false;
    }

#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:
public override Task Run()
{
Console.WriteLine("Run...");

        CycleColors(TimeSpan.FromMilliseconds(5000));
        for (int i = 0; i < 300; i++)
        {
            Console.WriteLine("This will never run :( -> I'm doing more work now while LEDs are blinking :) for " + i + "seconds.");
            Thread.Sleep(1000);
        }
        return base.Run();
    }

Since the Meadow F7 has an onboard clock, why not implement the ShowColorPulse() routine as follows, for example:
private void ShowColorPulse(Color color, TimeSpan duration)
{
DateTime dateTime = DateTime.Now;
int interval = 25;
float decimalPercent;
double elapsedTime;

        onboardLed.SetColor(color, 0.01f);
        Console.WriteLine("0.01");
        Thread.Sleep(interval);
        do
        {
            elapsedTime = (DateTime.Now - dateTime).TotalMilliseconds;
            decimalPercent = (float)(elapsedTime / (duration.TotalMilliseconds / 2.0));
            if (decimalPercent > 1f) decimalPercent = 1;
            onboardLed.SetColor(color, decimalPercent);
            Console.WriteLine(((double)decimalPercent).ToString("0.00"));
            Thread.Sleep(interval);
        } while (decimalPercent < 1f);

        do
        {
            elapsedTime = (DateTime.Now - dateTime).TotalMilliseconds;
            decimalPercent = 1f - (float)((elapsedTime - (duration.TotalMilliseconds / 2.0)) / (duration.TotalMilliseconds / 2.0));
            if (decimalPercent < 0f) decimalPercent = 0f;
            onboardLed.SetColor(color, decimalPercent);
            Console.WriteLine(((double)decimalPercent).ToString("0.00"));
            Thread.Sleep(interval);
        } while (decimalPercent > 0f);

        onboardLed.Stop();
    }

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:
public override Task Run()
{
Console.WriteLine("Run...");

        Task.Run(() => CycleColors(TimeSpan.FromMilliseconds(5000)));
        for (int i = 0; i < 300; i++)
        {
            Console.WriteLine("I'm doing more work now while LEDs are blinking :) for " + i + "seconds.");
            Thread.Sleep(1000);
        }
        return base.Run();
    }

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).
The slab floor heating system I'm working on requires controlling analog voltage valves (sure I can add external DACs, but why when the Meadow F7v2 has them built in - again I'm used to having DACs available in PIC microControllers).

#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.
Here's the Output Window from the Build, as well as the Output Window from the Meadow, post deployment, at which time everything just hangs:

Output Window: Build

Build started...
1>------ Build started: Project: HellowMeadow, Configuration: Debug Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>HellowMeadow -> D:\Data_Weyco\VS2022\Meadow\HelloMeadow\HellowMeadow sync into async\HellowMeadow\bin\Debug\netstandard2.1\App.dll
2>------ Deploy started: Project: HellowMeadow, Configuration: Debug Any CPU ------
2>[2023-03-31 13:54:20] Connecting to Meadow on COM7
2>[2023-03-31 13:54:21] Downloading version file for Meadow OS 0.9.4.0
2>[2023-03-31 13:54:21] Downloaded 285 bytes
2>[2023-03-31 13:54:21] Meadow OS version 0.9.4.0 is already downloaded
2>[2023-03-31 13:54:21] Meadow StdInfo: Mono is enabled
2>[2023-03-31 13:54:21] Mono is enabled
2>[2023-03-31 13:54:21] Meadow StdInfo: Mono has been disabled - restarting Meadow
2>[2023-03-31 13:54:21] Mono has been disabled - restarting Meadow
2>[2023-03-31 13:54:25] Connecting to Meadow on COM7
2>[2023-03-31 13:54:25] Meadow StdInfo: Mono is disabled
2>[2023-03-31 13:54:27] Meadow StdInfo: Mono is disabled
2>[2023-03-31 13:54:27] Mono is disabled
2>[2023-03-31 13:54:27] Meadow StdInfo: dev/
2>[2023-03-31 13:54:27] dev/
2>[2023-03-31 13:54:27] Meadow StdInfo: little0 [block]
2>[2023-03-31 13:54:27] little0 [block]
2>[2023-03-31 13:54:27] Meadow StdInfo: little0p0 [block]
2>[2023-03-31 13:54:27] little0p0 [block]
2>[2023-03-31 13:54:27] Meadow StdInfo: monostderr [char]
2>[2023-03-31 13:54:27] monostderr [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: monostdout [char]
2>[2023-03-31 13:54:27] monostdout [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: mtdblock0 [block]
2>[2023-03-31 13:54:27] mtdblock0 [block]
2>[2023-03-31 13:54:27] Meadow StdInfo: null [char]
2>[2023-03-31 13:54:27] null [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: nxupd [char]
2>[2023-03-31 13:54:27] nxupd [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: pwm0 [char]
2>[2023-03-31 13:54:27] pwm0 [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: ramlog [char]
2>[2023-03-31 13:54:27] ramlog [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: ttyACM0 [char]
2>[2023-03-31 13:54:27] ttyACM0 [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: ttyS0 [char]
2>[2023-03-31 13:54:27] ttyS0 [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: ttyS1 [char]
2>[2023-03-31 13:54:27] ttyS1 [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: ttyS2 [char]
2>[2023-03-31 13:54:27] ttyS2 [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: upd [char]
2>[2023-03-31 13:54:27] upd [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: urandom [char]
2>[2023-03-31 13:54:27] urandom [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: usrsock [char]
2>[2023-03-31 13:54:27] usrsock [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: meadow0/
2>[2023-03-31 13:54:27] meadow0/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: App.deps.json [file]
2>[2023-03-31 13:54:27] App.deps.json [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: App.exe [file]
2>[2023-03-31 13:54:27] App.exe [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: meadow.config.yaml [file]
2>[2023-03-31 13:54:27] meadow.config.yaml [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.Contracts.dll [file]
2>[2023-03-31 13:54:27] Meadow.Contracts.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.dll [file]
2>[2023-03-31 13:54:27] Meadow.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.F7.dll [file]
2>[2023-03-31 13:54:27] Meadow.F7.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.Foundation.dll [file]
2>[2023-03-31 13:54:27] Meadow.Foundation.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.Logging.dll [file]
2>[2023-03-31 13:54:27] Meadow.Logging.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Meadow.Units.dll [file]
2>[2023-03-31 13:54:27] Meadow.Units.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Bcl.AsyncInterfaces.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Bcl.AsyncInterfaces.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.Configuration.Abstractions.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.Configuration.Abstractions.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.Configuration.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.Configuration.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.Configuration.FileExtensions.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.Configuration.FileExtensions.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.Configuration.Json.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.Configuration.Json.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.FileProviders.Abstractions.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.FileProviders.Abstractions.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.FileProviders.Physical.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.FileProviders.Physical.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.FileSystemGlobbing.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.FileSystemGlobbing.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Microsoft.Extensions.Primitives.dll [file]
2>[2023-03-31 13:54:27] Microsoft.Extensions.Primitives.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Mono.Security.dll [file]
2>[2023-03-31 13:54:27] Mono.Security.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: MQTTnet.dll [file]
2>[2023-03-31 13:54:27] MQTTnet.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: mscorlib.dll [file]
2>[2023-03-31 13:54:27] mscorlib.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: NetEscapades.Configuration.Yaml.dll [file]
2>[2023-03-31 13:54:27] NetEscapades.Configuration.Yaml.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: netstandard.dll [file]
2>[2023-03-31 13:54:27] netstandard.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Buffers.dll [file]
2>[2023-03-31 13:54:27] System.Buffers.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Configuration.dll [file]
2>[2023-03-31 13:54:27] System.Configuration.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Core.dll [file]
2>[2023-03-31 13:54:27] System.Core.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.dll [file]
2>[2023-03-31 13:54:27] System.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.IO.Compression.dll [file]
2>[2023-03-31 13:54:27] System.IO.Compression.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.IO.Compression.FileSystem.dll [file]
2>[2023-03-31 13:54:27] System.IO.Compression.FileSystem.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Memory.dll [file]
2>[2023-03-31 13:54:27] System.Memory.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Net.Http.dll [file]
2>[2023-03-31 13:54:27] System.Net.Http.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Numerics.dll [file]
2>[2023-03-31 13:54:27] System.Numerics.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Numerics.Vectors.dll [file]
2>[2023-03-31 13:54:27] System.Numerics.Vectors.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Runtime.CompilerServices.Unsafe.dll [file]
2>[2023-03-31 13:54:27] System.Runtime.CompilerServices.Unsafe.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Text.Encodings.Web.dll [file]
2>[2023-03-31 13:54:27] System.Text.Encodings.Web.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Text.Json.dll [file]
2>[2023-03-31 13:54:27] System.Text.Json.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Web.dll [file]
2>[2023-03-31 13:54:27] System.Web.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Xml.dll [file]
2>[2023-03-31 13:54:27] System.Xml.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: YamlDotNet.dll [file]
2>[2023-03-31 13:54:27] YamlDotNet.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Threading.Tasks.Extensions.dll [file]
2>[2023-03-31 13:54:27] System.Threading.Tasks.Extensions.dll [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: Cache/
2>[2023-03-31 13:54:27] Cache/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: Data/
2>[2023-03-31 13:54:27] Data/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: Documents/
2>[2023-03-31 13:54:27] Documents/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: Temp/
2>[2023-03-31 13:54:27] Temp/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: update-store/
2>[2023-03-31 13:54:27] update-store/
2>[2023-03-31 13:54:27] Meadow StdInfo: ./
2>[2023-03-31 13:54:27] ./
2>[2023-03-31 13:54:27] Meadow StdInfo: ../
2>[2023-03-31 13:54:27] ../
2>[2023-03-31 13:54:27] Meadow StdInfo: App.pdb [file]
2>[2023-03-31 13:54:27] App.pdb [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: mscorlib.pdb [file]
2>[2023-03-31 13:54:27] mscorlib.pdb [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.Core.pdb [file]
2>[2023-03-31 13:54:27] System.Core.pdb [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: System.pdb [file]
2>[2023-03-31 13:54:27] System.pdb [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: dns.conf [file]
2>[2023-03-31 13:54:27] dns.conf [file]
2>[2023-03-31 13:54:27] Meadow StdInfo: var/
2>[2023-03-31 13:54:27] var/
2>[2023-03-31 13:54:27] Meadow StdInfo: mqueue/
2>[2023-03-31 13:54:27] mqueue/
2>[2023-03-31 13:54:27] Meadow StdInfo: Esp32Events [char]
2>[2023-03-31 13:54:27] Esp32Events [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: Esp32Requests [char]
2>[2023-03-31 13:54:27] Esp32Requests [char]
2>[2023-03-31 13:54:27] Meadow StdInfo: IncomingEvents [char]
2>[2023-03-31 13:54:27] IncomingEvents [char]
2>[2023-03-31 13:54:29] Found App.deps.json (CRC: 42267865)
2>[2023-03-31 13:54:29] Found App.exe (CRC: 1855195920)
2>[2023-03-31 13:54:29] Found meadow.config.yaml (CRC: 4043840953)
2>[2023-03-31 13:54:29] Found Meadow.Contracts.dll (CRC: 9326843)
2>[2023-03-31 13:54:29] Found Meadow.dll (CRC: 3503952112)
2>[2023-03-31 13:54:29] Found Meadow.F7.dll (CRC: 2963243811)
2>[2023-03-31 13:54:29] Found Meadow.Foundation.dll (CRC: 1395705424)
2>[2023-03-31 13:54:29] Found Meadow.Logging.dll (CRC: 226478549)
2>[2023-03-31 13:54:29] Found Meadow.Units.dll (CRC: 3884730322)
2>[2023-03-31 13:54:29] Found Microsoft.Bcl.AsyncInterfaces.dll (CRC: 3215379713)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.Configuration.Abstractions.dll (CRC: 33053645)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.Configuration.dll (CRC: 2526625974)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.Configuration.FileExtensions.dll (CRC: 4121043609)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.Configuration.Json.dll (CRC: 1836327059)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.FileProviders.Abstractions.dll (CRC: 2670091038)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.FileProviders.Physical.dll (CRC: 338685548)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.FileSystemGlobbing.dll (CRC: 2950879595)
2>[2023-03-31 13:54:29] Found Microsoft.Extensions.Primitives.dll (CRC: 163906323)
2>[2023-03-31 13:54:29] Found Mono.Security.dll (CRC: 945399146)
2>[2023-03-31 13:54:29] Found MQTTnet.dll (CRC: 506427821)
2>[2023-03-31 13:54:29] Found mscorlib.dll (CRC: 1094711394)
2>[2023-03-31 13:54:29] Found NetEscapades.Configuration.Yaml.dll (CRC: 2894847578)
2>[2023-03-31 13:54:29] Found netstandard.dll (CRC: 598635719)
2>[2023-03-31 13:54:29] Found System.Buffers.dll (CRC: 2270003332)
2>[2023-03-31 13:54:29] Found System.Configuration.dll (CRC: 2074593218)
2>[2023-03-31 13:54:29] Found System.Core.dll (CRC: 2308559818)
2>[2023-03-31 13:54:29] Found System.dll (CRC: 2126239260)
2>[2023-03-31 13:54:29] Found System.IO.Compression.dll (CRC: 2573790115)
2>[2023-03-31 13:54:29] Found System.IO.Compression.FileSystem.dll (CRC: 817424733)
2>[2023-03-31 13:54:29] Found System.Memory.dll (CRC: 1315600087)
2>[2023-03-31 13:54:29] Found System.Net.Http.dll (CRC: 3587756045)
2>[2023-03-31 13:54:29] Found System.Numerics.dll (CRC: 612903199)
2>[2023-03-31 13:54:29] Found System.Numerics.Vectors.dll (CRC: 1090432325)
2>[2023-03-31 13:54:29] Found System.Runtime.CompilerServices.Unsafe.dll (CRC: 4142136300)
2>[2023-03-31 13:54:29] Found System.Text.Encodings.Web.dll (CRC: 2255902349)
2>[2023-03-31 13:54:29] Found System.Text.Json.dll (CRC: 3582527655)
2>[2023-03-31 13:54:29] Found System.Web.dll (CRC: 352214362)
2>[2023-03-31 13:54:29] Found System.Xml.dll (CRC: 3898021245)
2>[2023-03-31 13:54:29] Found YamlDotNet.dll (CRC: 1259838021)
2>[2023-03-31 13:54:29] Found System.Threading.Tasks.Extensions.dll (CRC: 2160723354)
2>[2023-03-31 13:54:29] Found App.pdb (CRC: 2043755720)
2>[2023-03-31 13:54:29] Found mscorlib.pdb (CRC: 1844509202)
2>[2023-03-31 13:54:29] Found System.Core.pdb (CRC: 100559469)
2>[2023-03-31 13:54:29] Found System.pdb (CRC: 489292201)
2>[2023-03-31 13:54:29] Found dns.conf (CRC: 2979744109)
2>[2023-03-31 13:54:45] Meadow StdInfo: Meadow successfully deleted '/meadow0/dns.conf'
2>[2023-03-31 13:54:45] Meadow successfully deleted '/meadow0/dns.conf'
2>[2023-03-31 13:54:45] Removing file: dns.conf
2>[2023-03-31 13:54:45] Writing file: App.pdb
2>[2023-03-31 13:54:45] Starting File Transfer...
2>[2023-03-31 13:54:45] Meadow StdInfo: File 10% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 20% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 30% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 41% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 51% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 61% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 71% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 82% downloaded
2>[2023-03-31 13:54:45] File 82% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 92% downloaded
2>[2023-03-31 13:54:45] File 92% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: Download of 'App.pdb' success (checksums calculated:0x2ABD4F62, expected:0x2ABD4F62)
2>[2023-03-31 13:54:45] Download of 'App.pdb' success (checksums calculated:0x2ABD4F62, expected:0x2ABD4F62)
2>[2023-03-31 13:54:45] Transfer Complete, wrote 9964 bytes to Meadow
2>[2023-03-31 13:54:45] Wrote file: D:\Data_Weyco\VS2022\Meadow\HelloMeadow\HellowMeadow sync into async\HellowMeadow\bin\Debug\netstandard2.1\App.pdb
2>[2023-03-31 13:54:45] Skipping file (hash match): App.deps.json
2>[2023-03-31 13:54:45] Writing file: App.exe
2>[2023-03-31 13:54:45] Starting File Transfer...
2>[2023-03-31 13:54:45] Meadow StdInfo: File 16% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 25% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 33% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 41% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 50% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 66% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 75% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 83% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: File 91% downloaded
2>[2023-03-31 13:54:45] File 91% downloaded
2>[2023-03-31 13:54:45] Meadow StdInfo: Download of 'App.exe' success (checksums calculated:0xFB40121D, expected:0xFB40121D)
2>[2023-03-31 13:54:45] Download of 'App.exe' success (checksums calculated:0xFB40121D, expected:0xFB40121D)
2>[2023-03-31 13:54:45] Transfer Complete, wrote 6144 bytes to Meadow
2>[2023-03-31 13:54:45] Wrote file: D:\Data_Weyco\VS2022\Meadow\HelloMeadow\HellowMeadow sync into async\HellowMeadow\bin\Debug\netstandard2.1\App.exe
2>[2023-03-31 13:54:45] Skipping file (hash match): meadow.config.yaml
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.Contracts.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.F7.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.Foundation.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.Logging.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Meadow.Units.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Bcl.AsyncInterfaces.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.Configuration.Abstractions.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.Configuration.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.Configuration.FileExtensions.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.Configuration.Json.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.FileProviders.Abstractions.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.FileProviders.Physical.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.FileSystemGlobbing.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Microsoft.Extensions.Primitives.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): Mono.Security.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): MQTTnet.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): mscorlib.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): mscorlib.pdb
2>[2023-03-31 13:54:45] Skipping file (hash match): NetEscapades.Configuration.Yaml.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): netstandard.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Buffers.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Configuration.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Core.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Core.pdb
2>[2023-03-31 13:54:45] Skipping file (hash match): System.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.IO.Compression.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.IO.Compression.FileSystem.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Memory.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Net.Http.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Numerics.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Numerics.Vectors.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.pdb
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Runtime.CompilerServices.Unsafe.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Text.Encodings.Web.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Text.Json.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Web.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Xml.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): YamlDotNet.dll
2>[2023-03-31 13:54:45] Skipping file (hash match): System.Threading.Tasks.Extensions.dll
2>[2023-03-31 13:54:45] App.dll deploy complete
2>[2023-03-31 13:54:45] Meadow StdInfo: Mono is disabled
2>[2023-03-31 13:54:45] Mono is disabled
2>[2023-03-31 13:54:45] Meadow StdInfo: Mono has been enabled - restarting Meadow
2>[2023-03-31 13:54:45] Mono has been enabled - restarting Meadow
2>[2023-03-31 13:54:47] Connecting to Meadow on COM7
2>[2023-03-31 13:54:47] Meadow StdInfo: Meadow successfully started MONO
2>[2023-03-31 13:54:49] Meadow StdInfo: Mono is enabled
2>[2023-03-31 13:54:49] Mono is enabled
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 1:54 PM and took 31.880 seconds ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
========== Deploy started at 1:54 PM and took 31.880 seconds ==========

Output Window: Meadow

Launching application...

Connecting to Meadow on COM7
Connecting to Meadow on COM7
Meadow StdInfo: Meadow successfully started MONO
Listening for Visual Studio to connect on 127.0.0.1:55898
Visual Studio has Connected

@E-R-T-W
Copy link
Author

E-R-T-W commented Apr 2, 2023

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:

        private void ShowColorPulse(Color color, TimeSpan duration, float highBrightness, float lowBrightness)
        {
            if (highBrightness > 1f) highBrightness = 1f;
            if (lowBrightness < 0f) lowBrightness = 0f;
            if (lowBrightness > highBrightness) highBrightness = lowBrightness;

            DateTime dateTimeStart = DateTime.Now;
            int interval = 25;
            float decimalPercent;
            double elapsedMilliSecs;

            onboardLed.SetColor(color, lowBrightness);
            Console.WriteLine(lowBrightness.ToString("0.00"));
            Thread.Sleep(interval);
            do
            {
                elapsedMilliSecs = (DateTime.Now - dateTimeStart).TotalMilliseconds;
                decimalPercent = (((float)(elapsedMilliSecs / (duration.TotalMilliseconds / 2.0))) * (highBrightness - lowBrightness)) + lowBrightness;
                if (decimalPercent > highBrightness) decimalPercent = highBrightness;
                onboardLed.SetColor(color, decimalPercent);
                Console.WriteLine((decimalPercent).ToString("0.00"));
                Thread.Sleep(interval);
            } while (elapsedMilliSecs <= duration.TotalMilliseconds / 2.0);

            do
            {
                elapsedMilliSecs = (DateTime.Now - dateTimeStart).TotalMilliseconds;
                decimalPercent = ((1f - (float)((elapsedMilliSecs - (duration.TotalMilliseconds / 2.0)) / (duration.TotalMilliseconds / 2.0))) * (highBrightness - lowBrightness)) + lowBrightness;
                if (decimalPercent < lowBrightness) decimalPercent = lowBrightness;
                onboardLed.SetColor(color, decimalPercent);
                Console.WriteLine((decimalPercent).ToString("0.00"));
                Thread.Sleep(interval);
            } while (elapsedMilliSecs <= duration.TotalMilliseconds);

            onboardLed.Stop();
        }

and it can be called as follows:

        public override Task Run()
        {
            Console.WriteLine("Run...");

            Task.Run(() => CycleColors(TimeSpan.FromMilliseconds(2000)));
            for (int i = 0; i < 300; i++)
            {
                Console.WriteLine("I'm doing more work now while LEDs are blinking :) for " + i + " seconds.");
                Thread.Sleep(1000);
            }
            return base.Run();
        }

        Task CycleColors(TimeSpan duration)
        {
            Console.WriteLine("Cycle colors...");

            while (true)
            {
                ShowColorPulse(Color.Red, duration, 0.5f, 0.02f);
                ShowColorPulse(Color.Green, duration, 0.5f, 0.02f);
                ShowColorPulse(Color.Blue, duration, 0.5f, 0.02f);
            }
        }

@E-R-T-W E-R-T-W closed this as completed Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants