Skip to content

Commit

Permalink
Merge pull request #373 from WildernessLabs/v1.3.4
Browse files Browse the repository at this point in the history
V1.3.4
  • Loading branch information
jorgedevs authored Sep 26, 2023
2 parents a2d8ae5 + 11f8b79 commit cbebef3
Show file tree
Hide file tree
Showing 63 changed files with 1,463 additions and 935 deletions.
28 changes: 28 additions & 0 deletions Contributing.md
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/).
189 changes: 94 additions & 95 deletions source/Meadow.Core/Bases/App.cs
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); }
}
6 changes: 3 additions & 3 deletions source/Meadow.Core/Gateways/Bluetooth/Characteristic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ public class Characteristic : ICharacteristic
public CharacteristicWriteType WriteType { get; set; }
/// <summary>
/// Indicates wheter the characteristic can be read or not.
/// Indicates whether the characteristic can be read or not.
/// </summary>
public bool CanRead { get; set; }
/// <summary>
/// Indicates wheter the characteristic can be written or not.
/// Indicates whether the characteristic can be written or not.
/// </summary>
public bool CanWrite { get; set; }
/// <summary>
/// Indicates wheter the characteristic supports notify or not.
/// Indicates whether the characteristic supports notify or not.
/// </summary>
public bool CanUpdate { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Meadow.Gateways.Bluetooth
public enum CharacteristicPropertyType
{
/// <summary>
/// Characteristic value can be broadcasted.
/// Characteristic value can be broadcast.
/// </summary>
Broadcast = 1,

Expand All @@ -31,12 +31,12 @@ public enum CharacteristicPropertyType
Write = 8,

/// <summary>
/// Characteristic can notify value changes without acknowledgement.
/// Characteristic can notify value changes without acknowledgment.
/// </summary>
Notify = 16,

/// <summary>
///Characteristic can indicate value changes with acknowledgement.
///Characteristic can indicate value changes with acknowledgment.
/// </summary>
Indicate = 32,

Expand All @@ -50,7 +50,7 @@ public enum CharacteristicPropertyType
/// </summary>
ExtendedProperties = 128,

// TODO: move these to seperate enum
// TODO: move these to separate enum
NotifyEncryptionRequired = 256, //0x100

IndicateEncryptionRequired = 512, //0x200
Expand Down
3 changes: 3 additions & 0 deletions source/Meadow.Core/Gateways/Bluetooth/Definitions/Service.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Meadow.Gateways.Bluetooth
{
/// <summary>
/// Provides access to a device Bluetooth capabilities
/// </summary>
public class Service : IService
{
public ushort Handle { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions source/Meadow.Core/Gateways/Bluetooth/KnownCharacteristics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static KnownCharacteristic Lookup(Guid id)
new KnownCharacteristic("Tx Power Level", Guid.ParseExact("00002a07-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Unread Alert Status", Guid.ParseExact("00002a45-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Aerobic Heart Rate Lower Limit", Guid.ParseExact("00002a7e-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Aerobic Heart Rate Uppoer Limit", Guid.ParseExact("00002a84-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Aerobic Heart Rate Upper Limit", Guid.ParseExact("00002a84-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Age", Guid.ParseExact("00002a80-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Aggregate Input", Guid.ParseExact("00002a5a-0000-1000-8000-00805f9b34fb", "d")),
new KnownCharacteristic("Anaerobic Heart Rate Lower Limit", Guid.ParseExact("00002a81-0000-1000-8000-00805f9b34fb", "d")),
Expand Down Expand Up @@ -190,9 +190,9 @@ public static KnownCharacteristic Lookup(Guid id)
new KnownCharacteristic("TI SensorTag Humidity Data", Guid.ParseExact("f000aa21-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Humidity On/Off", Guid.ParseExact("f000aa22-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Humidity Sample Rate", Guid.ParseExact("f000aa23-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnometer Data", Guid.ParseExact("f000aa31-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnometer On/Off", Guid.ParseExact("f000aa32-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnometer Sample Rate", Guid.ParseExact("f000aa33-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnetometer Data", Guid.ParseExact("f000aa31-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnetometer On/Off", Guid.ParseExact("f000aa32-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Magnetometer Sample Rate", Guid.ParseExact("f000aa33-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Barometer Data", Guid.ParseExact("f000aa41-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Barometer On/Off", Guid.ParseExact("f000aa42-0451-4000-b000-000000000000", "d")),
new KnownCharacteristic("TI SensorTag Barometer Calibration", Guid.ParseExact("f000aa43-0451-4000-b000-000000000000", "d")),
Expand Down
2 changes: 1 addition & 1 deletion source/Meadow.Core/Gateways/Bluetooth/KnownServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static KnownService Lookup(Guid id)
new KnownService("TI SensorTag Infrared Thermometer", Guid.ParseExact("f000aa00-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Accelerometer", Guid.ParseExact("f000aa10-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Humidity", Guid.ParseExact("f000aa20-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Magnometer", Guid.ParseExact("f000aa30-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Magnetometer", Guid.ParseExact("f000aa30-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Barometer", Guid.ParseExact("f000aa40-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Gyroscope", Guid.ParseExact("f000aa50-0451-4000-b000-000000000000", "d")),
new KnownService("TI SensorTag Test", Guid.ParseExact("f000aa60-0451-4000-b000-000000000000", "d")),
Expand Down
13 changes: 7 additions & 6 deletions source/Meadow.Core/Hardware/AnalogInputPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Meadow.Hardware;
// ReadVoltage();
// ```
//
// * User needs to take contuinous voltage readings. Most likely getting
// * User needs to take continuous voltage readings. Most likely getting
// oversampled readings each time for accuracy.
//
// ```
Expand All @@ -30,7 +30,7 @@ namespace Meadow.Hardware;
// ```
//
// * User wants to take continuous voltage readings and wants to be notified
// //TODO: think through some notifcation configuration
// //TODO: think through some notification configuration
// ```
// analogPort.VoltageChanged += (float newVoltage){ /*do something*/ };

Expand All @@ -47,7 +47,7 @@ public class AnalogInputPort : AnalogInputPortBase, IObservable<IChangeResult<Vo
/// </summary>
public static readonly TimeSpan DefaultSampleInterval = TimeSpan.FromMilliseconds(40);
/// <summary>
/// The default reference votlage for the Input (3.3V)
/// The default reference voltage for the Input (3.3V)
/// </summary>
public static readonly Voltage DefaultReferenceVoltage = new Voltage(3.3, Voltage.UnitType.Volts);

Expand All @@ -73,14 +73,15 @@ public class AnalogInputPort : AnalogInputPortBase, IObservable<IChangeResult<Vo
protected Voltage? PreviousVoltageReading { get; set; }

/// <summary>
/// Creates an AnalogInputPort given the povided parameters
/// Creates an AnalogInputPort given the provided parameters
/// </summary>
/// <param name="pin">The IPin to use for the input port</param>
/// <param name="ioController">The IMeadowIOController for the pin</param>
/// <param name="channel">The pin's channel info</param>
/// <param name="sampleCount">The number of ADC readings to average for a single sample</param>
/// <param name="sampleInterval">The time between readings used for calculating the average for a sample</param>
/// <param name="referenceVoltage">The ADCs reference voltage</param>
/// <exception cref="PortInUseException"></exception>
protected AnalogInputPort(
IPin pin, IMeadowIOController ioController, IAnalogChannelInfo channel,
int sampleCount, TimeSpan sampleInterval,
Expand All @@ -104,7 +105,7 @@ protected AnalogInputPort(
}

/// <summary>
/// Creates an AnalogInputPort given the povided parameters
/// Creates an AnalogInputPort given the provided parameters
/// </summary>
/// <param name="pin"></param>
/// <param name="ioController"></param>
Expand All @@ -119,7 +120,7 @@ public static AnalogInputPort From(
}

/// <summary>
/// Creates an AnalogInputPort given the povided parameters
/// Creates an AnalogInputPort given the provided parameters
/// </summary>
/// <param name="pin"></param>
/// <param name="ioController"></param>
Expand Down
Loading

0 comments on commit cbebef3

Please sign in to comment.