Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TechnicMotor TestScript #162

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ await technicMediumHub.VerifyDeploymentModelAsync(mb => mb
await dynamicDeviceWhichIsAMotor.UnlockFromCombinedModeNotificationSetupAsync(true);

// get the individual modes for input and output
var powerMode = dynamicDeviceWhichIsAMotor.SingleValueMode<sbyte>(0);
var posMode = dynamicDeviceWhichIsAMotor.SingleValueMode<int>(2);
var aposMode = dynamicDeviceWhichIsAMotor.SingleValueMode<short>(3);
var powerMode = dynamicDeviceWhichIsAMotor.SingleValueMode<sbyte, sbyte>(0);
var posMode = dynamicDeviceWhichIsAMotor.SingleValueMode<int, int>(2);
var aposMode = dynamicDeviceWhichIsAMotor.SingleValueMode<short, short>(3);

// use their observables to report values
using var disposable = posMode.Observable.Subscribe(x => Log.LogWarning($"Position: {x.SI} / {x.Pct}"));
Expand Down
17 changes: 16 additions & 1 deletion powered-up.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
MinimumVisualStudioVersion = 15.0.26124.0
Expand All @@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpBrick.PoweredUp.Mobile
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpBrick.PoweredUp.BlueGigaBLE", "src\SharpBrick.PoweredUp.BlueGigaBLE\SharpBrick.PoweredUp.BlueGigaBLE.csproj", "{E0DC0096-D7F1-4995-833D-9A6C0C3F8F98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpBrick.PoweredUp.TestScript", "test\SharpBrick.PoweredUp.TestScript\SharpBrick.PoweredUp.TestScript.csproj", "{EED1D80A-4083-46B3-843F-1B584FDB6862}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -104,6 +106,18 @@ Global
{F66A2B09-84B6-477D-9B15-926E771C7D80}.Release|x64.Build.0 = Release|Any CPU
{F66A2B09-84B6-477D-9B15-926E771C7D80}.Release|x86.ActiveCfg = Release|Any CPU
{F66A2B09-84B6-477D-9B15-926E771C7D80}.Release|x86.Build.0 = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|x64.ActiveCfg = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|x64.Build.0 = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|x86.ActiveCfg = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Debug|x86.Build.0 = Debug|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|Any CPU.Build.0 = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|x64.ActiveCfg = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|x64.Build.0 = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|x86.ActiveCfg = Release|Any CPU
{EED1D80A-4083-46B3-843F-1B584FDB6862}.Release|x86.Build.0 = Release|Any CPU
{E0DC0096-D7F1-4995-833D-9A6C0C3F8F98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0DC0096-D7F1-4995-833D-9A6C0C3F8F98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0DC0096-D7F1-4995-833D-9A6C0C3F8F98}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -127,6 +141,7 @@ Global
{D82C23F2-86B4-4847-B2BD-7F194279FD43} = {F4D84196-5E85-41FE-9C39-38BD8F78E84D}
{E2D7D98D-9F20-4761-B507-D379A530E77D} = {62C31C3D-8ACF-4ED3-A3D8-225536F3AC6D}
{F66A2B09-84B6-477D-9B15-926E771C7D80} = {62C31C3D-8ACF-4ED3-A3D8-225536F3AC6D}
{EED1D80A-4083-46B3-843F-1B584FDB6862} = {39B30145-497F-4AEB-A014-BBF27DA0651A}
{E0DC0096-D7F1-4995-833D-9A6C0C3F8F98} = {62C31C3D-8ACF-4ED3-A3D8-225536F3AC6D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
12 changes: 12 additions & 0 deletions src/SharpBrick.PoweredUp/Deployment/HubExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static async Task VerifyDeploymentModelAsync(this Hub self, Action<Deploy

var model = BuildModel(configure);

await VerifyDeploymentModelAsync(self, model);
}

/// <summary>
/// Verifies the deployment model and waits till it reaches zero deployment errors.
/// </summary>
/// <param name="self"></param>
/// <param name="configure">Builder infrastructure for the deployment model</param>
/// <returns></returns>
public static async Task VerifyDeploymentModelAsync(this Hub self, DeploymentModel model)
{

var awaitable = self.VerifyObservable(model)
.Do(LogErrors(self))
.Where(x => x.Length == 0)
Expand Down
6 changes: 3 additions & 3 deletions src/SharpBrick.PoweredUp/Devices/AbsoluteMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace SharpBrick.PoweredUp
{
public abstract class AbsoluteMotor : TachoMotor
{
protected SingleValueMode<short> _absoluteMode;
protected SingleValueMode<short, short> _absoluteMode;
public byte ModeIndexAbsolutePosition { get; protected set; } = 3;

public short AbsolutePosition => _absoluteMode.SI;
public short AbsolutePositionPct => _absoluteMode.Pct;
public IObservable<Value<short>> AbsolutePositionObservable => _absoluteMode.Observable;
public IObservable<Value<short, short>> AbsolutePositionObservable => _absoluteMode.Observable;

public AbsoluteMotor()
{ }

protected AbsoluteMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_absoluteMode = SingleValueMode<short>(ModeIndexAbsolutePosition);
_absoluteMode = SingleValueMode<short, short>(ModeIndexAbsolutePosition);

ObserveForPropertyChanged(_absoluteMode.Observable, nameof(AbsolutePosition), nameof(AbsolutePositionPct));
}
Expand Down
6 changes: 3 additions & 3 deletions src/SharpBrick.PoweredUp/Devices/BasicMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace SharpBrick.PoweredUp
{
public abstract class BasicMotor : Device
{
protected SingleValueMode<sbyte> _powerMode;
protected SingleValueMode<sbyte, sbyte> _powerMode;
public byte ModeIndexPower { get; protected set; } = 0;

public sbyte Power => _powerMode.SI;
public sbyte PowerPct => _powerMode.Pct;
public IObservable<Value<sbyte>> PowerObservable => _powerMode.Observable;
public IObservable<Value<sbyte, sbyte>> PowerObservable => _powerMode.Observable;

public BasicMotor()
{ }

public BasicMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_powerMode = SingleValueMode<sbyte>(ModeIndexPower);
_powerMode = SingleValueMode<sbyte, sbyte>(ModeIndexPower);

ObserveForPropertyChanged(_powerMode.Observable, nameof(Power), nameof(PowerPct));
}
Expand Down
106 changes: 53 additions & 53 deletions src/SharpBrick.PoweredUp/Devices/ColorDistanceSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@

namespace SharpBrick.PoweredUp
{
public class ColorDistanceSensor : Device, IPoweredUpDevice
{
protected SingleValueMode<sbyte> _colorMode;
protected SingleValueMode<sbyte> _proximityMode;
protected SingleValueMode<int> _countMode;
protected SingleValueMode<sbyte> _reflectionMode;
protected SingleValueMode<sbyte> _ambientLightMode;
protected SingleValueMode<sbyte> _lightMode;
protected MultiValueMode<short> _rgbMode;
public class ColorDistanceSensor : Device, IPoweredUpDevice
{
protected SingleValueMode<sbyte, sbyte> _colorMode;
protected SingleValueMode<sbyte, sbyte> _proximityMode;
protected SingleValueMode<int, int> _countMode;
protected SingleValueMode<sbyte, sbyte> _reflectionMode;
protected SingleValueMode<sbyte, sbyte> _ambientLightMode;
protected SingleValueMode<sbyte, sbyte> _lightMode;
protected MultiValueMode<short, short> _rgbMode;

public byte ModeIndexColor { get; protected set; } = 0;
public byte ModeIndexProximity { get; protected set; } = 1;
public byte ModeIndexCount { get; protected set; } = 2;
public byte ModeIndexReflection { get; protected set; } = 3;
public byte ModeIndexAmbientLight { get; protected set; } = 4;
public byte ModeIndexLight { get; protected set; } = 5;
public byte ModeIndexRgb { get; protected set; } = 6;
public byte ModeIndexIRTx { get; protected set; } = 7;
public byte ModeIndexSPEC1 { get; protected set; } = 8;
public byte ModeIndexDebug { get; protected set; } = 9;
public byte ModeIndexCalibration { get; protected set; } = 10;
public byte ModeIndexColor { get; protected set; } = 0;
public byte ModeIndexProximity { get; protected set; } = 1;
public byte ModeIndexCount { get; protected set; } = 2;
public byte ModeIndexReflection { get; protected set; } = 3;
public byte ModeIndexAmbientLight { get; protected set; } = 4;
public byte ModeIndexLight { get; protected set; } = 5;
public byte ModeIndexRgb { get; protected set; } = 6;
public byte ModeIndexIRTx { get; protected set; } = 7;
public byte ModeIndexSPEC1 { get; protected set; } = 8;
public byte ModeIndexDebug { get; protected set; } = 9;
public byte ModeIndexCalibration { get; protected set; } = 10;

public TechnicColor Color => (TechnicColor)_colorMode.SI;
public IObservable<TechnicColor> ColorObservable => _colorMode.Observable.Select(v => (TechnicColor)v.SI);
public IObservable<sbyte> ProximityObservable => _proximityMode.Observable.Select(v => v.SI);
public IObservable<int> CountObservable => _countMode.Observable.Select(v => v.SI);
public IObservable<sbyte> ReflectionObservable => _reflectionMode.Observable.Select(v => v.SI);
public IObservable<sbyte> AmbientLightObservable => _ambientLightMode.Observable.Select(v => v.SI);
public IObservable<(short red, short green, short blue)> RgbObservable => _rgbMode.Observable.Select(v => (v.SI[0], v.SI[1], v.SI[2]));
public TechnicColor Color => (TechnicColor)_colorMode.SI;
public IObservable<TechnicColor> ColorObservable => _colorMode.Observable.Select(v => (TechnicColor)v.SI);
public IObservable<sbyte> ProximityObservable => _proximityMode.Observable.Select(v => v.SI);
public IObservable<int> CountObservable => _countMode.Observable.Select(v => v.SI);
public IObservable<sbyte> ReflectionObservable => _reflectionMode.Observable.Select(v => v.SI);
public IObservable<sbyte> AmbientLightObservable => _ambientLightMode.Observable.Select(v => v.SI);
public IObservable<(short red, short green, short blue)> RgbObservable => _rgbMode.Observable.Select(v => (v.SI[0], v.SI[1], v.SI[2]));

public ColorDistanceSensor()
{ }
public ColorDistanceSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_colorMode = SingleValueMode<sbyte>(ModeIndexColor);
_proximityMode = SingleValueMode<sbyte>(ModeIndexProximity);
_countMode = SingleValueMode<int>(ModeIndexCount);
_reflectionMode = SingleValueMode<sbyte>(ModeIndexReflection);
_ambientLightMode = SingleValueMode<sbyte>(ModeIndexAmbientLight);
_lightMode = SingleValueMode<sbyte>(ModeIndexLight);
_rgbMode = MultiValueMode<short>(ModeIndexRgb);
}
public ColorDistanceSensor()
{ }
public ColorDistanceSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_colorMode = SingleValueMode<sbyte, sbyte>(ModeIndexColor);
_proximityMode = SingleValueMode<sbyte, sbyte>(ModeIndexProximity);
_countMode = SingleValueMode<int, int>(ModeIndexCount);
_reflectionMode = SingleValueMode<sbyte, sbyte>(ModeIndexReflection);
_ambientLightMode = SingleValueMode<sbyte, sbyte>(ModeIndexAmbientLight);
_lightMode = SingleValueMode<sbyte, sbyte>(ModeIndexLight);
_rgbMode = MultiValueMode<short, short>(ModeIndexRgb);
}

protected override uint GetDefaultDeltaInterval(byte modeIndex)
=> modeIndex switch
{
0 => 1,
2 => 1,
_ => base.GetDefaultDeltaInterval(modeIndex),
};
protected override uint GetDefaultDeltaInterval(byte modeIndex)
=> modeIndex switch
{
0 => 1,
2 => 1,
_ => base.GetDefaultDeltaInterval(modeIndex),
};

public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType)
=> ((softwareVersion, hardwareVersion, systemType) switch
{
(_, _, _) => @"
public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType)
=> ((softwareVersion, hardwareVersion, systemType) switch
{
(_, _, _) => @"
0B-00-43-01-01-07-0B-5F-06-A0-00
07-00-43-01-02-4F-00
12-00-44-01-00-00-43-4F-4C-4F-52-00-00-00-00-00-00-00
Expand Down Expand Up @@ -145,6 +145,6 @@ public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Ve
08-00-44-01-0A-05-10-00
0A-00-44-01-0A-80-08-01-05-00
"
}).Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}).Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}
12 changes: 6 additions & 6 deletions src/SharpBrick.PoweredUp/Devices/Current.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ namespace SharpBrick.PoweredUp
{
public class Current : Device, IPoweredUpDevice
{
protected SingleValueMode<short> _currentLMode;
protected SingleValueMode<short> _currentSMode;
protected SingleValueMode<short, short> _currentLMode;
protected SingleValueMode<short, short> _currentSMode;
public byte ModeIndexCurrentL { get; protected set; } = 0x00;
public byte ModeIndexCurrentS { get; protected set; } = 0x01;

public short CurrentL => _currentLMode.SI;
public short CurrentLPct => _currentLMode.Pct;
public IObservable<Value<short>> CurrentLObservable => _currentLMode.Observable;
public IObservable<Value<short, short>> CurrentLObservable => _currentLMode.Observable;

public short CurrentS => _currentSMode.SI;
public short CurrentSPct => _currentSMode.Pct;
public IObservable<Value<short>> CurrentSObservable => _currentSMode.Observable;
public IObservable<Value<short, short>> CurrentSObservable => _currentSMode.Observable;

public Current()
{ }

public Current(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_currentLMode = SingleValueMode<short>(ModeIndexCurrentL);
_currentSMode = SingleValueMode<short>(ModeIndexCurrentS);
_currentLMode = SingleValueMode<short, short>(ModeIndexCurrentL);
_currentSMode = SingleValueMode<short, short>(ModeIndexCurrentS);

ObserveForPropertyChanged(_currentLMode.Observable, nameof(CurrentL), nameof(CurrentLPct));
ObserveForPropertyChanged(_currentSMode.Observable, nameof(CurrentS), nameof(CurrentSPct));
Expand Down
8 changes: 4 additions & 4 deletions src/SharpBrick.PoweredUp/Devices/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public Device(ILegoWirelessProtocol protocol, byte hubId, byte portId)
BuildModes();
}

public SingleValueMode<TPayload> SingleValueMode<TPayload>(byte modeIndex)
=> _modes.TryGetValue(modeIndex, out var mode) ? mode as SingleValueMode<TPayload> : default;
public MultiValueMode<TPayload> MultiValueMode<TPayload>(byte modeIndex)
=> _modes.TryGetValue(modeIndex, out var mode) ? mode as MultiValueMode<TPayload> : default;
public SingleValueMode<TDatasetType, TOutputType> SingleValueMode<TDatasetType, TOutputType>(byte modeIndex)
=> _modes.TryGetValue(modeIndex, out var mode) ? mode as SingleValueMode<TDatasetType, TOutputType> : default;
public MultiValueMode<TDatasetType, TOutputType> MultiValueMode<TDatasetType, TOutputType>(byte modeIndex)
=> _modes.TryGetValue(modeIndex, out var mode) ? mode as MultiValueMode<TDatasetType, TOutputType> : default;

protected void BuildModes()
{
Expand Down
16 changes: 8 additions & 8 deletions src/SharpBrick.PoweredUp/Devices/DuploTrainBaseColorSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace SharpBrick.PoweredUp
{
public class DuploTrainBaseColorSensor : Device, IPoweredUpDevice
{
protected SingleValueMode<sbyte> _colorMode;
protected SingleValueMode<sbyte> _colorTagMode;
protected SingleValueMode<sbyte> _reflectionMode;
protected MultiValueMode<short> _rgbMode;
protected SingleValueMode<sbyte, sbyte> _colorMode;
protected SingleValueMode<sbyte, sbyte> _colorTagMode;
protected SingleValueMode<sbyte, sbyte> _reflectionMode;
protected MultiValueMode<short, short> _rgbMode;

public byte ModeIndexColor { get; protected set; } = 0;
public byte ModeIndexColorTag { get; protected set; } = 1;
Expand All @@ -37,10 +37,10 @@ public DuploTrainBaseColorSensor()
public DuploTrainBaseColorSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_colorMode = SingleValueMode<sbyte>(ModeIndexColor);
_colorTagMode = SingleValueMode<sbyte>(ModeIndexColorTag);
_reflectionMode = SingleValueMode<sbyte>(ModeIndexReflection);
_rgbMode = MultiValueMode<short>(ModeIndexRgb);
_colorMode = SingleValueMode<sbyte, sbyte>(ModeIndexColor);
_colorTagMode = SingleValueMode<sbyte, sbyte>(ModeIndexColorTag);
_reflectionMode = SingleValueMode<sbyte, sbyte>(ModeIndexReflection);
_rgbMode = MultiValueMode<short, short>(ModeIndexRgb);

ObserveForPropertyChanged(_colorMode.Observable, nameof(Color));
ObserveForPropertyChanged(_colorTagMode.Observable, nameof(ColorTag));
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp/Devices/DuploTrainBaseMotor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SharpBrick.PoweredUp
{
public class DuploTrainBaseMotor : Device, IPoweredUpDevice
{
public SingleValueMode<int> _onSecMode;
public SingleValueMode<int, int> _onSecMode;

public byte ModeIndexMotor { get; protected set; } = 0;
public byte ModeIndexOnSec { get; protected set; } = 1;
Expand All @@ -26,7 +26,7 @@ public DuploTrainBaseMotor()
public DuploTrainBaseMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_onSecMode = SingleValueMode<int>(ModeIndexOnSec);
_onSecMode = SingleValueMode<int, int>(ModeIndexOnSec);

ObserveForPropertyChanged(_onSecMode.Observable, nameof(OnSeconds));
}
Expand Down
4 changes: 2 additions & 2 deletions src/SharpBrick.PoweredUp/Devices/DuploTrainBaseSpeaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SharpBrick.PoweredUp

public class DuploTrainBaseSpeaker : Device, IPoweredUpDevice
{
protected SingleValueMode<sbyte> _soundMode;
protected SingleValueMode<sbyte, sbyte> _soundMode;

public byte ModeIndexTone { get; protected set; } = 0;
public byte ModeIndexSound { get; protected set; } = 1;
Expand All @@ -23,7 +23,7 @@ public DuploTrainBaseSpeaker()
public DuploTrainBaseSpeaker(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_soundMode = SingleValueMode<sbyte>(ModeIndexSound);
_soundMode = SingleValueMode<sbyte, sbyte>(ModeIndexSound);
}

public async Task<PortFeedback> PlaySoundAsync(DuploTrainBaseSound sound)
Expand Down
Loading