Skip to content

Commit

Permalink
Merge pull request #247 from WildernessLabs/v1.12.8
Browse files Browse the repository at this point in the history
Release 1.12.8
  • Loading branch information
jorgedevs authored Jul 12, 2024
2 parents 099237f + 675c7d7 commit 822b2ed
Show file tree
Hide file tree
Showing 26 changed files with 503 additions and 185 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Develop Build
on:
workflow_dispatch:
pull_request:
branches: [ develop ]
push:
branches: [ develop ]

Expand Down Expand Up @@ -38,12 +39,4 @@ jobs:
7.0.x

- name: Build Meadow.Contracts
run: dotnet build -c Release Meadow.Contracts/Source/Meadow.Contracts/Meadow.Contracts.sln

- name: Trigger Core Build
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.CI_ACCESS_TOKEN }}
repository: WildernessLabs/Meadow.Core
event-type: cross_repo_ci
client-payload: '{"source": "${{ github.event.repository.name }}"}'
run: dotnet build -c Release Meadow.Contracts/Source/Meadow.Contracts/Meadow.Contracts.sln
35 changes: 22 additions & 13 deletions Source/Meadow.Contracts/CircularBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CircularBuffer<T> : IEnumerable<T>
/// </remarks>
public bool HasUnderrun { get; set; }
/// <summary>
/// Returns <c>true</c> if the buffer's Count equals its MaxEleemnts.
/// Returns <c>true</c> if the buffer's Count equals its MaxElements.
/// </summary>
public bool IsFull { get; private set; }

Expand Down Expand Up @@ -146,24 +146,28 @@ public int Count

private void IncrementTail()
{
_tail++;
if (_tail >= MaxElements)
lock (_syncRoot)
{
_tail = 0;
var t = _tail + 1;

_tail = (t >= MaxElements) ? 0 : t;
}
}

private void IncrementHead()
{
_head++;
if (_head >= MaxElements)
lock (_syncRoot)
{
_head = 0;
}
_head++;
if (_head >= MaxElements)
{
_head = 0;
}

if (_head == _tail)
{
IsFull = true;
if (_head == _tail)
{
IsFull = true;
}
}
}

Expand Down Expand Up @@ -503,6 +507,10 @@ public int MoveItemsTo(T[] destination, int index, int count)

// move the tail pointer
_tail += actual;
if (_tail == MaxElements)
{
_tail = 0;
}
}
else
{
Expand All @@ -514,8 +522,9 @@ public int MoveItemsTo(T[] destination, int index, int count)
var remaining = actual - tailToEnd;
Array.Copy(_list, _tail, destination, tailToEnd + index, remaining);

// move the tail pointer
_tail = remaining;
// move the tail pointer - if it is at the end, move it to the beginning

_tail = (remaining >= MaxElements) ? 0 : remaining;
}

IsFull = false;
Expand Down
44 changes: 44 additions & 0 deletions Source/Meadow.Contracts/Enums/ResetReason.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

namespace Meadow.Hardware;

/// <summary>
/// Reasons a platform might have been reset
/// </summary>
[Flags]
public enum ResetReason
{
/// <summary>
/// The reset reason is not determined
/// </summary>
Unknown = 0,
/// <summary>
/// Power was too low to maintain operation (brown out)
/// </summary>
InsufficientPower = 1 << 1,
/// <summary>
/// Reset pin/interrupt detected
/// </summary>
HardwareReset = 1 << 2,
/// <summary>
/// Normal power-on reset
/// </summary>
PowerOnReset = 1 << 3,
/// <summary>
/// Software-triggered reset
/// </summary>
SoftwareReset = 1 << 4,
/// <summary>
/// An independent watchdog timer expired
/// </summary>
IndependentWatchdog = 1 << 5,
/// <summary>
/// An window watchdog timer expired
/// </summary>
WindowWatchdog = 1 << 6,
/// <summary>
/// A reset due to low power
/// </summary>
LowPower = 1 << 7
}

18 changes: 18 additions & 0 deletions Source/Meadow.Contracts/Exceptions/MeadowCloudSystemErrorInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;

namespace Meadow;

/// <summary>
/// Contains information about a Meadow Cloud system error
/// </summary>
public class MeadowCloudSystemErrorInfo : MeadowSystemErrorInfo
{
/// <summary>
/// Creates a MeadowCloudSystemErrorInfo object
/// </summary>
/// <param name="exception">The exception from Meadow Cloud</param>
public MeadowCloudSystemErrorInfo(Exception exception)
: base("Meadow Cloud Error", SystemErrorNumber.MeadowCloudError, exception)
{
}
}
6 changes: 5 additions & 1 deletion Source/Meadow.Contracts/Exceptions/MeadowSystemErrorInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public enum SystemErrorNumber
/// <summary>
/// The coprocessor generated an error
/// </summary>
CoprocessorError = 1
CoprocessorError = 1,
/// <summary>
/// Meadow Cloud generated an error
/// </summary>
MeadowCloudError = 2
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ protected BiDirectionalInterruptPortBase(
OutputType initialOutputType)
: base(pin, channel, initialState, resistorMode, initialDirection, initialOutputType)
{
InterruptMode = interruptMode;
DebounceDuration = debounceDuration; // Don't trigger WireInterrupt call via property
GlitchDuration = glitchDuration; // Don't trigger WireInterrupt call via property
}

/// <summary>
Expand Down
134 changes: 64 additions & 70 deletions Source/Meadow.Contracts/Hardware/Bases/PwmPortBase.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,81 @@
using Meadow.Units;
using System;

namespace Meadow.Hardware
namespace Meadow.Hardware;

/// <summary>
/// Represents a base class for PWM ports.
/// </summary>
public abstract class PwmPortBase : DigitalPortBase, IPwmPort
{
/// <summary>
/// Represents a base class for PWM ports.
/// Gets or sets the PWM channel information associated with the port.
/// </summary>
public abstract class PwmPortBase : DigitalPortBase, IPwmPort
public new IPwmChannelInfo Channel
{
/// <summary>
/// Gets or sets the PWM channel information associated with the port.
/// </summary>
public new IPwmChannelInfo Channel
{
get => (IPwmChannelInfo)base.Channel;
protected set { base.Channel = value; }
}

/// <summary>
/// Initializes a new instance of the <see cref="PwmPortBase"/> class.
/// </summary>
/// <param name="pin">The pin associated with the PWM port.</param>
/// <param name="channel">The PWM channel information for the port.</param>
/// <param name="frequency">The PWM frequency.</param>
/// <param name="dutyCycle">The initial PWM duty cycle (default is 0).</param>
/// <param name="inverted">A value indicating whether the PWM signal is inverted (default is false).</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="pin"/> or <paramref name="channel"/> is <c>null</c>.</exception>
protected PwmPortBase(
IPin pin,
IPwmChannelInfo channel,
Frequency frequency,
float dutyCycle = 0,
bool inverted = false
) : base(pin, channel)
{
Inverted = inverted;
Frequency = frequency;
DutyCycle = dutyCycle;
}
get => (IPwmChannelInfo)base.Channel;
protected set { base.Channel = value; }
}

/// <summary>
/// Gets or sets the time scale in which time-based properties (Period and Duration) are expressed.
/// </summary>
public TimeScale TimeScale { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="PwmPortBase"/> class.
/// </summary>
/// <param name="pin">The pin associated with the PWM port.</param>
/// <param name="channel">The PWM channel information for the port.</param>
/// <param name="frequency">The PWM frequency.</param>
/// <param name="dutyCycle">The initial PWM duty cycle (default is 0).</param>
/// <param name="inverted">A value indicating whether the PWM signal is inverted (default is false).</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="pin"/> or <paramref name="channel"/> is <c>null</c>.</exception>
protected PwmPortBase(
IPin pin,
IPwmChannelInfo channel,
Frequency frequency,
float dutyCycle = 0,
bool inverted = false
) : base(pin, channel)
{
Inverted = inverted;
Frequency = frequency;
DutyCycle = dutyCycle;
}

/// <summary>
/// Gets or sets a value indicating whether the PWM signal is inverted.
/// </summary>
public abstract bool Inverted { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the PWM signal is inverted.
/// </summary>
public abstract bool Inverted { get; set; }

/// <summary>
/// Gets or sets the duty cycle of the PWM signal.
/// </summary>
public abstract float DutyCycle { get; set; }
/// <summary>
/// Gets or sets the duty cycle of the PWM signal.
/// </summary>
public abstract double DutyCycle { get; set; }

/// <summary>
/// Gets or sets the frequency of the PWM signal.
/// </summary>
public abstract Frequency Frequency { get; set; }
/// <summary>
/// Gets or sets the frequency of the PWM signal.
/// </summary>
public abstract Frequency Frequency { get; set; }

/// <summary>
/// Gets or sets the duration of the PWM pulse.
/// </summary>
public abstract float Duration { get; set; }
/// <summary>
/// Gets or sets the duration of the PWM pulse.
/// </summary>
public abstract TimePeriod Duration { get; set; }

/// <summary>
/// Gets or sets the period of the PWM signal.
/// </summary>
public abstract float Period { get; set; }
/// <summary>
/// Gets or sets the period of the PWM signal.
/// </summary>
public abstract TimePeriod Period { get; set; }

/// <summary>
/// Gets the state of the PWM signal.
/// </summary>
public abstract bool State { get; }
/// <summary>
/// Gets the state of the PWM signal.
/// </summary>
public abstract bool State { get; }

/// <summary>
/// Starts the PWM signal.
/// </summary>
public abstract void Start();
/// <summary>
/// Starts the PWM signal.
/// </summary>
public abstract void Start();

/// <summary>
/// Stops the PWM signal.
/// </summary>
public abstract void Stop();
}
/// <summary>
/// Stops the PWM signal.
/// </summary>
public abstract void Stop();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;

namespace Meadow.Hardware;

/// <summary>
/// Represents a Collection of IPins
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;

namespace Meadow.Hardware;

/// <summary>
/// Represents a Collection of IConnectors
/// </summary>
public class ConnectorCollection : IEnumerable<IConnector>
{
private List<IConnector> _connectors = new();

/// <summary>
/// Creates a new ConnectorCollection
/// </summary>
protected ConnectorCollection() { }

/// <inheritdoc/>
public IEnumerator<IConnector> GetEnumerator()
{
return _connectors.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Adds a connector to the collection
/// </summary>
/// <param name="connector">The Connector instance to add</param>
protected void Add(IConnector connector)
{
_connectors.Add(connector);
}

/// <summary>
/// Retrieves an empty ConnectorCollection
/// </summary>
public static ConnectorCollection Empty
{
get => new ConnectorCollection();
}
}
Loading

0 comments on commit 822b2ed

Please sign in to comment.