Skip to content

Commit

Permalink
Add convience method to await button click (#78)
Browse files Browse the repository at this point in the history
- Add to steering calibration example

Closes #68 non-breaking
  • Loading branch information
tthiery authored Aug 17, 2020
1 parent d93e386 commit 2129aeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public override async Task ExecuteAsync()

var calibration = ServiceProvider.GetService<LinearMidCalibration>();
await calibration.ExecuteAsync(motor);
await technicMediumHub.WaitButtonClickAsync();

await Task.Delay(5000);
await motor.GotoAbsolutePositionAsync(CW * 50, 20, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile);
await Task.Delay(5000);
await technicMediumHub.WaitButtonClickAsync();

await motor.GotoAbsolutePositionAsync(CCW * 50, 20, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile);
await Task.Delay(5000);

Expand Down
14 changes: 14 additions & 0 deletions src/SharpBrick.PoweredUp/Hubs/Hub_Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ await Protocol.SendMessageAsync(new HubPropertyMessage()
await RequestHubPropertySingleUpdate(property);
}

public async Task WaitButtonClickAsync()
{
var awaitable = ButtonObservable
.Where(x => x == true)
.FirstAsync()
.GetAwaiter();

await SetupHubPropertyNotificationAsync(HubProperty.Button, true);

await awaitable;

await SetupHubPropertyNotificationAsync(HubProperty.Button, false);
}

private void OnHubPropertyMessage(HubPropertyMessage hubProperty)
{
if (hubProperty.Property == HubProperty.AdvertisingName && hubProperty is HubPropertyMessage<string> advData)
Expand Down

0 comments on commit 2129aeb

Please sign in to comment.