-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow direct connection to known device
- Extended PoweredUpHost with Create method. - Add example - Refactored BaseExample to allow alternatives to discovery #52
- Loading branch information
Showing
6 changed files
with
101 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
42 changes: 42 additions & 0 deletions
42
examples/SharpBrick.PoweredUp.Examples/ExampleBluetoothByKnownAddress.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using SharpBrick.PoweredUp; | ||
|
||
namespace Example | ||
{ | ||
public class ExampleBluetoothByKnownAddress : BaseExample | ||
{ | ||
public const ulong ChangeMe_BluetoothAddress = 158897336311065; | ||
public TechnicMediumHub DirectlyConnectedHub { get; private set; } | ||
|
||
// device needs to be switched on! | ||
public override void Discover(bool enableTrace) | ||
{ | ||
var hub = host.Create<TechnicMediumHub>(ChangeMe_BluetoothAddress); | ||
|
||
selectedHub = DirectlyConnectedHub = hub; | ||
|
||
hub.ConnectAsync().Wait(); | ||
} | ||
|
||
public override async Task ExecuteAsync() | ||
{ | ||
using (var technicMediumHub = DirectlyConnectedHub) | ||
{ | ||
await technicMediumHub.RgbLight.SetRgbColorsAsync(0xff, 0x00, 0x00); | ||
|
||
await Task.Delay(2000); | ||
|
||
await technicMediumHub.RgbLight.SetRgbColorsAsync(0x00, 0xff, 0x00); | ||
|
||
await Task.Delay(2000); | ||
|
||
await technicMediumHub.RgbLight.SetRgbColorsAsync(0xff, 0xff, 0x00); | ||
|
||
await Task.Delay(2000); | ||
|
||
await technicMediumHub.SwitchOffAsync(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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