-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #373 from WildernessLabs/v1.3.4
V1.3.4
- Loading branch information
Showing
63 changed files
with
1,463 additions
and
935 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Contribute to Meadow.Core | ||
|
||
**Meadow.Core** is an open-source project by [Wilderness Labs](https://www.wildernesslabs.co/) and we encourage community feedback and contributions. | ||
|
||
## How to Contribute | ||
|
||
- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues) | ||
- Want to **contribute code?** Fork the [Meadow.Core](https://github.com/WildernessLabs/Meadow.Core) repository and submit a pull request against the `develop` branch | ||
|
||
## Pull Requests | ||
|
||
1. All PRs should target the `develop` branch on the Meadow.Core repository. | ||
2. All new public or protected classes, methods, and properties need XML comment documentation. | ||
3. Please try to follow the existing coding patterns and practices. | ||
|
||
## Pull Request Steps | ||
|
||
1. Fork the repository | ||
2. Clone your fork locally: `git clone https://github.com/WildernessLabs/Meadow.Core` | ||
3. Switch to the `develop` branch | ||
4. Create a new branch: `git checkout -b feature/your-contribution` | ||
5. Make your changes and commit: `git commit -m 'Added/Updated [feature/fix]` | ||
6. Push to your fork: `git push origin feature/your-contribution` | ||
7. Open a pull request at [Meadow.Core/pulls](https://github.com/WildernessLabs/Meadow.Core/pulls) targetting the `develop` branch | ||
## Need Help? | ||
|
||
If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,113 @@ | ||
namespace Meadow | ||
namespace Meadow; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Provides a base implementation for the Meadow App. Use this | ||
/// class for Meadow applications to get strongly-typed access to the current | ||
/// device information. | ||
/// </summary> | ||
public abstract class App<D> : IApp, IAsyncDisposable | ||
where D : class, IMeadowDevice | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
private ExecutionContext executionContext; | ||
|
||
/// <inheritdoc/> | ||
public CancellationToken CancellationToken { get; internal set; } = default!; | ||
|
||
/// <inheritdoc/> | ||
public Dictionary<string, string> Settings { get; internal set; } = default!; | ||
|
||
/// <summary> | ||
/// Provides a base implementation for the Meadow App. Use this | ||
/// class for Meadow applications to get strongly-typed access to the current | ||
/// device information. | ||
/// Base constructor for the App class | ||
/// </summary> | ||
public abstract class App<D> : IApp, IAsyncDisposable | ||
where D : class, IMeadowDevice | ||
protected App() | ||
{ | ||
private ExecutionContext executionContext; | ||
executionContext = Thread.CurrentThread.ExecutionContext; | ||
|
||
/// <inheritdoc/> | ||
public CancellationToken CancellationToken { get; internal set; } | ||
Device = MeadowOS.CurrentDevice as D ?? throw new ArgumentException($"Current device is not {typeof(D).Name}"); // 'D' is guaranteed to be initialized and the same type | ||
Abort = MeadowOS.AppAbort.Token; | ||
|
||
/// <inheritdoc/> | ||
public Dictionary<string, string> Settings { get; internal set; } | ||
Resolver.Services.Add<IApp>(this); | ||
} | ||
|
||
/// <summary> | ||
/// Base constructor for the App class | ||
/// </summary> | ||
protected App() | ||
/// <summary> | ||
/// Invokes an action in the context of the applications main thread | ||
/// </summary> | ||
/// <param name="action">The action to call</param> | ||
/// <param name="state">An optional state object to pass to the Action</param> | ||
public void InvokeOnMainThread(Action<object?> action, object? state = null) | ||
{ | ||
switch (Device.Information.Platform) | ||
{ | ||
executionContext = Thread.CurrentThread.ExecutionContext; | ||
// ExecutionContext in Mono on the F7 isn't fully working - but we also don't worry about a MainThread there either | ||
case Hardware.MeadowPlatform.F7FeatherV1: | ||
case Hardware.MeadowPlatform.F7FeatherV2: | ||
case Hardware.MeadowPlatform.F7CoreComputeV2: | ||
action.Invoke(state); | ||
break; | ||
default: | ||
ExecutionContext.Run(executionContext, new ContextCallback(action), state); | ||
break; | ||
} | ||
} | ||
|
||
Device = MeadowOS.CurrentDevice as D ?? throw new ArgumentException($"Current device is not {typeof(D).Name}"); // 'D' is guaranteed to be initialized and the same type | ||
Abort = MeadowOS.AppAbort.Token; | ||
/// <summary> | ||
/// Called by MeadowOS when everything is ready for the App to run | ||
/// </summary> | ||
public virtual Task Run() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
Resolver.Services.Add<IApp>(this); | ||
} | ||
/// <summary> | ||
/// Called by MeadowOS to initialize the App | ||
/// </summary> | ||
public virtual Task Initialize() { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Invokes an action in the context of the applications main thread | ||
/// </summary> | ||
/// <param name="action">The action to call</param> | ||
/// <param name="state">An optional state object to pass to the Action</param> | ||
public void InvokeOnMainThread(Action<object?> action, object? state = null) | ||
{ | ||
switch (Device.Information.Platform) | ||
{ | ||
// ExecutionContext in Mono on the F7 isn't fully working - but we also don't worry about a MainThread there either | ||
case Hardware.MeadowPlatform.F7FeatherV1: | ||
case Hardware.MeadowPlatform.F7FeatherV2: | ||
case Hardware.MeadowPlatform.F7CoreComputeV2: | ||
action.Invoke(state); | ||
break; | ||
default: | ||
ExecutionContext.Run(executionContext, new ContextCallback(action), state); | ||
break; | ||
} | ||
} | ||
/// <summary> | ||
/// Called when a request to shut down the App occurs | ||
/// </summary> | ||
/// <remarks>This is called by the Update Service before applying an update</remarks> | ||
public virtual Task OnShutdown() { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Called by MeadowOS when everything is ready for the App to run | ||
/// </summary> | ||
public virtual Task Run() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
/// <summary> | ||
/// Called when the MeadowOS encounters an error | ||
/// </summary> | ||
/// <param name="e">The exception from MeadowOS</param> | ||
public virtual Task OnError(Exception e) { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Called by MeadowOS to initialize the App | ||
/// </summary> | ||
public virtual Task Initialize() { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Called when a request to shut down the App occurs | ||
/// </summary> | ||
/// <remarks>This is called by the Update Service before applying an update</remarks> | ||
public virtual Task OnShutdown() { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Called when the MeadowOS encounters an error | ||
/// </summary> | ||
/// <param name="e">The exception from MeadowOS</param> | ||
public virtual Task OnError(Exception e) { return Task.CompletedTask; } | ||
|
||
/// <summary> | ||
/// Called when the application is about to update itself. | ||
/// </summary> | ||
public void OnUpdate(Version newVersion, out bool approveUpdate) | ||
{ | ||
approveUpdate = true; | ||
} | ||
/// <summary> | ||
/// Called when the application is about to update itself. | ||
/// </summary> | ||
public void OnUpdate(Version newVersion, out bool approveUpdate) | ||
{ | ||
approveUpdate = true; | ||
} | ||
|
||
/// <summary> | ||
/// Called when the application has updated itself. | ||
/// </summary> | ||
public void OnUpdateComplete(Version oldVersion, out bool rollbackUpdate) | ||
{ | ||
rollbackUpdate = false; | ||
} | ||
/// <summary> | ||
/// Called when the application has updated itself. | ||
/// </summary> | ||
public void OnUpdateComplete(Version oldVersion, out bool rollbackUpdate) | ||
{ | ||
rollbackUpdate = false; | ||
} | ||
|
||
/// <summary> | ||
/// The root Device interface | ||
/// </summary> | ||
public static D Device { get; protected set; } = default!; | ||
/// <summary> | ||
/// The root Device interface | ||
/// </summary> | ||
public static D Device { get; protected set; } = default!; | ||
|
||
/// <summary> | ||
/// The app cancellation token | ||
/// </summary> | ||
public static CancellationToken Abort { get; protected set; } | ||
/// <summary> | ||
/// The app cancellation token | ||
/// </summary> | ||
public static CancellationToken Abort { get; protected set; } | ||
|
||
/// <summary> | ||
/// Virtual method provided for App implemenmtations to clean up resources on Disposal | ||
/// </summary> | ||
public virtual ValueTask DisposeAsync() { return new ValueTask(Task.CompletedTask); } | ||
} | ||
/// <summary> | ||
/// Virtual method provided for App implementations to clean up resources on Disposal | ||
/// </summary> | ||
public virtual ValueTask DisposeAsync() { return new ValueTask(Task.CompletedTask); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.