diff --git a/examples/SharpBrick.PoweredUp.Examples/ExampleHubActions.cs b/examples/SharpBrick.PoweredUp.Examples/ExampleHubActions.cs new file mode 100644 index 0000000..3e39785 --- /dev/null +++ b/examples/SharpBrick.PoweredUp.Examples/ExampleHubActions.cs @@ -0,0 +1,30 @@ +using System.Threading.Tasks; +using SharpBrick.PoweredUp; + +namespace Example +{ + public static class ExampleHubActions + { + public static async Task ExecuteAsync() + { + var (host, serviceProvider, _) = ExampleHubDiscover.CreateHostAndDiscover(); + + using (var technicMediumHub = host.FindByType()) + { + await technicMediumHub.RgbLight.SetRgbColorsAsync(0x00, 0xff, 0xff); + + await Task.Delay(2000); + + await technicMediumHub.ActivateBusyIndicatorAsync(); // technic medium hub => blinking with color from above + + await Task.Delay(5000); + + await technicMediumHub.ResetBusyIndicatorAsync(); // stop blinking + + await Task.Delay(2000); + + await technicMediumHub.SwitchOffAsync(); + } + } + } +} \ No newline at end of file diff --git a/examples/SharpBrick.PoweredUp.Examples/Program.cs b/examples/SharpBrick.PoweredUp.Examples/Program.cs index 6d2b04d..67675af 100644 --- a/examples/SharpBrick.PoweredUp.Examples/Program.cs +++ b/examples/SharpBrick.PoweredUp.Examples/Program.cs @@ -10,7 +10,9 @@ static async Task Main(string[] args) //await Example.ExampleColors.ExecuteAsync(); //await Example.ExampleMotorControl.ExecuteAsync(); //await Example.ExampleMotorInputAbsolutePosition.ExecuteAsync(); - await Example.ExampleMotorVirtualPort.ExecuteAsync(); + //await Example.ExampleMotorVirtualPort.ExecuteAsync(); + + await Example.ExampleHubActions.ExecuteAsync(); } } } diff --git a/src/SharpBrick.PoweredUp/Hubs/Hub.cs b/src/SharpBrick.PoweredUp/Hubs/Hub.cs index 639d8df..d65eaa9 100644 --- a/src/SharpBrick.PoweredUp/Hubs/Hub.cs +++ b/src/SharpBrick.PoweredUp/Hubs/Hub.cs @@ -106,8 +106,11 @@ private void OnHubChange(PoweredUpMessage message) public async Task SwitchOffAsync() { - var request = new HubActionMessage { Action = HubAction.SwitchOffHub }; - await _protocol.SendMessageAsync(request); + await _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.SwitchOffHub + }); //TODO await response //TODO HubAction.HubWillSwitchOff @@ -117,18 +120,43 @@ public async Task SwitchOffAsync() public async Task DisconnectAsync() { - var request = new HubActionMessage { Action = HubAction.Disconnect }; - await _protocol.SendMessageAsync(request); + await _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.Disconnect + }); //TODO await response //TODO HubAction.HubWillDisconnect await _kernel.DisconnectAsync(); } - public Task VccPortControlOn() => throw new NotImplementedException(); - public Task VccPortControlOff() => throw new NotImplementedException(); - public Task ActivateBusyIndicatorAsync() => throw new NotImplementedException(); - public Task ResetBusyIndicatorAsync() => throw new NotImplementedException(); - // TODO: Action HubWillGoIntoBootMode (eventy) + public Task VccPortControlOnAsync() + => _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.VccPortControlOn, + }); + + + public Task VccPortControlOffAsync() + => _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.VccPortControlOff, + }); + + public Task ActivateBusyIndicatorAsync() + => _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.ActivateBusyIndication, + }); + public Task ResetBusyIndicatorAsync() + => _protocol.SendMessageAsync(new HubActionMessage + { + HubId = HubId, + Action = HubAction.ResetBusyIndication, + }); } } \ No newline at end of file