Skip to content

BuWizz I / II - reuse OutputValuesGroup#226

Draft
vicocz wants to merge 1 commit into
defaultfrom
local/buwizz-handle-send-attempts
Draft

BuWizz I / II - reuse OutputValuesGroup#226
vicocz wants to merge 1 commit into
defaultfrom
local/buwizz-handle-send-attempts

Conversation

@vicocz
Copy link
Copy Markdown
Owner

@vicocz vicocz commented May 21, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors BuWizz I and BuWizz II output handling to reuse the shared OutputValuesGroup<T> helper instead of maintaining per-device arrays/locks and retry counters, aiming to unify and simplify output state tracking and resend behavior.

Changes:

  • Replaced manual _outputValues/locking/retry state in BuWizzDevice with a single OutputValuesGroup<int> that also includes the output-level slot.
  • Replaced manual _outputValues + _lastOutputValues + locking/retry state in BuWizz2Device with OutputValuesGroup<int> for motor outputs, keeping output-level sending as a separate path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
BrickController2/BrickController2/DeviceManagement/BuwizzDevice.cs Uses OutputValuesGroup<int> for the 4 motor channels plus output level, simplifying output processing.
BrickController2/BrickController2/DeviceManagement/BuWizz2Device.cs Uses OutputValuesGroup<int> for motor outputs and simplifies the send loop around group change detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +174 to 186
if (lastSentOutputLevelValue != _outputLevelValue)
{
if (await SendOutputLevelValueAsync(_outputLevelValue, token))
{
_lastSentOutputLevelValue = _outputLevelValue;
lastSentOutputLevelValue = _outputLevelValue;
}
}
else
else if (_outputGroup.TryGetValues(out var values))
{
int v0, v1, v2, v3, sendAttemptsLeft;

lock (_outputLock)
{
v0 = _outputValues[0];
v1 = _outputValues[1];
v2 = _outputValues[2];
v3 = _outputValues[3];
sendAttemptsLeft = _sendAttemptsLeft;
_sendAttemptsLeft = sendAttemptsLeft > 0 ? sendAttemptsLeft - 1 : 0;
}

if (v0 != _lastOutputValues[0] || v1 != _lastOutputValues[1] || v2 != _lastOutputValues[2] || v3 != _lastOutputValues[3] || sendAttemptsLeft > 0)
if (await SendOutputValuesAsync(values[0], values[1], values[2], values[3], token).ConfigureAwait(false))
{
if (await SendOutputValuesAsync(v0, v1, v2, v3, token).ConfigureAwait(false))
{
_lastOutputValues[0] = v0;
_lastOutputValues[1] = v1;
_lastOutputValues[2] = v2;
_lastOutputValues[3] = v3;
}
}
else
{
await Task.Delay(10, token).ConfigureAwait(false);
_outputGroup.Commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants