Skip to content

Commit 2129aeb

Browse files
authored
Add convience method to await button click (sharpbrick#78)
- Add to steering calibration example Closes sharpbrick#68 non-breaking
1 parent d93e386 commit 2129aeb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

examples/SharpBrick.PoweredUp.Examples/ExampleCalibrationSteering.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public override async Task ExecuteAsync()
1616

1717
var calibration = ServiceProvider.GetService<LinearMidCalibration>();
1818
await calibration.ExecuteAsync(motor);
19+
await technicMediumHub.WaitButtonClickAsync();
1920

20-
await Task.Delay(5000);
2121
await motor.GotoAbsolutePositionAsync(CW * 50, 20, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile);
22-
await Task.Delay(5000);
22+
await technicMediumHub.WaitButtonClickAsync();
23+
2324
await motor.GotoAbsolutePositionAsync(CCW * 50, 20, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile);
2425
await Task.Delay(5000);
2526

src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,20 @@ await Protocol.SendMessageAsync(new HubPropertyMessage()
160160
await RequestHubPropertySingleUpdate(property);
161161
}
162162

163+
public async Task WaitButtonClickAsync()
164+
{
165+
var awaitable = ButtonObservable
166+
.Where(x => x == true)
167+
.FirstAsync()
168+
.GetAwaiter();
169+
170+
await SetupHubPropertyNotificationAsync(HubProperty.Button, true);
171+
172+
await awaitable;
173+
174+
await SetupHubPropertyNotificationAsync(HubProperty.Button, false);
175+
}
176+
163177
private void OnHubPropertyMessage(HubPropertyMessage hubProperty)
164178
{
165179
if (hubProperty.Property == HubProperty.AdvertisingName && hubProperty is HubPropertyMessage<string> advData)

0 commit comments

Comments
 (0)