-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into issue-57-rampup
- Loading branch information
Showing
87 changed files
with
2,738 additions
and
350 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
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
71 changes: 71 additions & 0 deletions
71
examples/SharpBrick.PoweredUp.Examples/ExampleDuploTrainBase.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,71 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using SharpBrick.PoweredUp; | ||
|
||
namespace Example | ||
{ | ||
public class ExampleDuploTrainBase : BaseExample | ||
{ | ||
public override async Task ExecuteAsync() | ||
{ | ||
using (var train = Host.FindByType<DuploTrainBaseHub>()) | ||
{ | ||
await train.VerifyDeploymentModelAsync(modelBuilder => modelBuilder | ||
.AddHub<DuploTrainBaseHub>(hubBuilder => { }) | ||
); | ||
|
||
using var d1 = train.Voltage.VoltageSObservable.Subscribe(x => Log.LogWarning($"Voltage: {x.Pct}% / {x.SI}")); | ||
using var d2 = train.Motor.OnSecondsObservable.Subscribe(x => Log.LogWarning($"Seconds: {x}")); | ||
using var d3 = train.Speedometer.SpeedObservable.Subscribe(x => Log.LogWarning($"Speed: {x.Pct}% / {x.SI}")); | ||
using var d4 = train.Speedometer.CountObservable.Subscribe(x => Log.LogWarning($"Count: {x}")); | ||
using var d5 = train.ColorSensor.ColorObservable.Subscribe(x => Log.LogWarning($"Color: {x}")); | ||
using var d6 = train.ColorSensor.ColorTagObservable.Subscribe(x => Log.LogWarning($"Color Tag: {x}")); // does not work | ||
using var d7 = train.ColorSensor.ReflectionObservable.Subscribe(x => Log.LogWarning($"Reflection: {x}")); | ||
using var d8 = train.ColorSensor.RgbObservable.Subscribe(x => Log.LogWarning($"RGB {x.red}/{x.green}/{x.blue}")); | ||
|
||
await train.Voltage.SetupNotificationAsync(train.Voltage.ModeIndexVoltageS, true); | ||
|
||
// Motor: motor can either be queried for seconds active OR be instructed to run | ||
//await train.Motor.SetupNotificationAsync(train.Motor.ModeIndexOnSec, false); | ||
|
||
await train.Speedometer.TryLockDeviceForCombinedModeNotificationSetupAsync(train.Speedometer.ModeIndexSpeed, train.Speedometer.ModeIndexCount); | ||
await train.Speedometer.SetupNotificationAsync(train.Speedometer.ModeIndexSpeed, true, deltaInterval: 1); | ||
await train.Speedometer.SetupNotificationAsync(train.Speedometer.ModeIndexCount, true, deltaInterval: 1); | ||
await train.Speedometer.UnlockFromCombinedModeNotificationSetupAsync(true); | ||
|
||
// ColorSensor: either this combination | ||
// await train.ColorSensor.TryLockDeviceForCombinedModeNotificationSetupAsync(train.ColorSensor.ModeIndexColor, train.ColorSensor.ModeIndexReflection, train.ColorSensor.ModeIndexRgb); | ||
// await train.ColorSensor.SetupNotificationAsync(train.ColorSensor.ModeIndexColor, true, deltaInterval: 1); | ||
// await train.ColorSensor.SetupNotificationAsync(train.ColorSensor.ModeIndexReflection, true, deltaInterval: 1); | ||
// await train.ColorSensor.SetupNotificationAsync(train.ColorSensor.ModeIndexRgb, true, deltaInterval: 1); | ||
// await train.ColorSensor.UnlockFromCombinedModeNotificationSetupAsync(true); | ||
|
||
// ColorSensor: or standalone | ||
await train.ColorSensor.SetupNotificationAsync(train.ColorSensor.ModeIndexColorTag, true, deltaInterval: 1); | ||
|
||
await train.Speaker.PlaySoundAsync(DuploTrainBaseSound.Horn); | ||
await train.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Red); | ||
await Task.Delay(1_000); | ||
await train.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Yellow); | ||
await Task.Delay(1_000); | ||
await train.RgbLight.SetRgbColorNoAsync(PoweredUpColor.Green); | ||
await train.Speaker.PlaySoundAsync(DuploTrainBaseSound.StationDeparture); | ||
|
||
await train.Motor.StartPowerAsync(40); | ||
await Task.Delay(3_000); | ||
await train.Speaker.PlaySoundAsync(DuploTrainBaseSound.Steam); | ||
await train.Motor.StartPowerAsync(-40); | ||
await Task.Delay(3_000); | ||
await train.Speaker.PlaySoundAsync(DuploTrainBaseSound.Brake); | ||
await train.Motor.StopByFloatAsync(); | ||
await Task.Delay(1_000); | ||
await train.Speaker.PlaySoundAsync(DuploTrainBaseSound.WaterRefill); | ||
|
||
await Task.Delay(1_000); | ||
|
||
await train.SwitchOffAsync(); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/SharpBrick.PoweredUp.Examples/ExampleMarioAccelerometer.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,30 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using SharpBrick.PoweredUp; | ||
|
||
namespace Example | ||
{ | ||
public class ExampleMarioAccelerometer : BaseExample | ||
{ | ||
public override async Task ExecuteAsync() | ||
{ | ||
using (var mario = Host.FindByType<MarioHub>()) | ||
{ | ||
await mario.VerifyDeploymentModelAsync(modelBuilder => modelBuilder | ||
.AddHub<MarioHub>(hubBuilder => { }) | ||
); | ||
|
||
var d1 = mario.Accelerometer.GestureObservable.Subscribe(x => Log.LogWarning($"Gesture: {x[0]}/{x[1]}")); | ||
|
||
await mario.Accelerometer.SetupNotificationAsync(mario.Accelerometer.ModeIndexGesture, true); | ||
|
||
await Task.Delay(20_000); | ||
|
||
d1.Dispose(); | ||
|
||
await mario.SwitchOffAsync(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.