BuWizz I / II - reuse OutputValuesGroup#226
Draft
vicocz wants to merge 1 commit into
Draft
Conversation
There was a problem hiding this comment.
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 inBuWizzDevicewith a singleOutputValuesGroup<int>that also includes the output-level slot. - Replaced manual
_outputValues+_lastOutputValues+ locking/retry state inBuWizz2DevicewithOutputValuesGroup<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(); | ||
| } |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.