Skip to content

Commit

Permalink
Implement Activate/ResetBusyIndicator
Browse files Browse the repository at this point in the history
- Also implemented VccPortControlOn/OffAsync exposing bug #24

#25
  • Loading branch information
tthiery committed Jun 15, 2020
1 parent 386d84b commit 6ceaa0c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
30 changes: 30 additions & 0 deletions examples/SharpBrick.PoweredUp.Examples/ExampleHubActions.cs
Original file line number Diff line number Diff line change
@@ -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<TechnicMediumHub>())
{
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();
}
}
}
}
4 changes: 3 additions & 1 deletion examples/SharpBrick.PoweredUp.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
46 changes: 37 additions & 9 deletions src/SharpBrick.PoweredUp/Hubs/Hub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
});
}
}

0 comments on commit 6ceaa0c

Please sign in to comment.