Skip to content

Some improvements for Arduino Binding, new value filter classes added - #2588

Open
pgrawehr wants to merge 8 commits into
dotnet:mainfrom
pgrawehr:ArduinoPlayground1
Open

Some improvements for Arduino Binding, new value filter classes added#2588
pgrawehr wants to merge 8 commits into
dotnet:mainfrom
pgrawehr:ArduinoPlayground1

Conversation

@pgrawehr

@pgrawehr pgrawehr commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Including some new features to the test application

Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service Bot added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Jul 3, 2026

@krwq krwq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot do other libraries have this abstraction already? maybe even in dotnet framework somewhere

_holdingState = ButtonHoldingState.Completed;
Holding?.Invoke(this, new ButtonHoldingEventArgs { HoldingState = ButtonHoldingState.Completed });
}
else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local agent review:
ButtonBase.Press semantics changed silently (src/devices/Button/ButtonBase.cs:132-142). Press used to fire on every release; the PR moves it into an else of the hold-check, so consumers subscribing only to Press stop getting events after a long press. Public event on a widely used binding, no doc/test/PR-notes for the change.

/// <typeparam name="TResult">The result of the filtering. Can be a single value (e.g. for an averaging filter)
/// or a list of TSource</typeparam>
/// <remarks>This class is thread safe. Concrete implementations should maintain that.</remarks>
public abstract class ValueFilter<TSourceElement, TResult>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local agent comment:

ValueFilter<T> thread-safety claim is overstated (ValueFilter.cs:38-45, 55-71, 95-104). AddElement/Clear skip _readLock; CurrentValue releases and re-takes the lock between RemoveOldElements and ToArray, so a racing Clear can drop elements the peek didn't observe. Either tighten the locking or drop the "thread safe" remark.

/// </summary>
/// <param name="values">The values to average over</param>
/// <returns>The return value</returns>
public static T? AverageFilter(List<T> values)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local agent comment:

TimeSliceFilter<T>.AverageFilter assumes default(T) is additive identity (TimeSliceFilter.cs:132-148). Safe for BCL primitives, wrong for UnitsNet-style struct wrappers. Seed the sum from values[0] like the sibling Min/Max filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants