diff --git a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs index ccf4754..b747c52 100644 --- a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs +++ b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs @@ -40,6 +40,10 @@ public Type GetTypeFromDeviceType(DeviceType deviceType) DeviceType.TechnicMediumHubGyroSensor => typeof(TechnicMediumHubGyroSensor), DeviceType.TechnicMediumHubTiltSensor => typeof(TechnicMediumHubTiltSensor), DeviceType.TechnicMediumHubTemperatureSensor => typeof(TechnicMediumHubTemperatureSensor), + DeviceType.MarioHubAccelerometer => typeof(MarioHubAccelerometer), + DeviceType.MarioHubTagSensor => typeof(MarioHubTagSensor), + DeviceType.MarioHubPants => typeof(MarioHubPants), + DeviceType.MarioHubDebug => typeof(MarioHubDebug), _ => null, }; @@ -56,6 +60,10 @@ public static DeviceType GetDeviceTypeFromType(Type type) nameof(TechnicMediumHubGyroSensor) => DeviceType.TechnicMediumHubGyroSensor, nameof(TechnicMediumHubTiltSensor) => DeviceType.TechnicMediumHubTiltSensor, nameof(TechnicMediumHubTemperatureSensor) => DeviceType.TechnicMediumHubTemperatureSensor, + nameof(MarioHubAccelerometer) => DeviceType.MarioHubAccelerometer, + nameof(MarioHubTagSensor) => DeviceType.MarioHubTagSensor, + nameof(MarioHubPants) => DeviceType.MarioHubPants, + nameof(MarioHubDebug) => DeviceType.MarioHubDebug, _ => DeviceType.Unknown, }; } diff --git a/src/SharpBrick.PoweredUp/Devices/MarioHubAccelerometer.cs b/src/SharpBrick.PoweredUp/Devices/MarioHubAccelerometer.cs new file mode 100644 index 0000000..331c8cd --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/MarioHubAccelerometer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp +{ + public class MarioHubAccelerometer : Device, IPoweredUpDevice + { + public MarioHubAccelerometer() + { } + + public MarioHubAccelerometer(ILegoWirelessProtocol protocol, byte hubId, byte portId) + : base(protocol, hubId, portId) + { + } + + public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion) + => @" +".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); + } +} \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Devices/MarioHubDebug.cs b/src/SharpBrick.PoweredUp/Devices/MarioHubDebug.cs new file mode 100644 index 0000000..f45d86b --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/MarioHubDebug.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp +{ + public class MarioHubDebug : Device, IPoweredUpDevice + { + public MarioHubDebug() + { } + + public MarioHubDebug(ILegoWirelessProtocol protocol, byte hubId, byte portId) + : base(protocol, hubId, portId) + { + } + + public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion) + => @" +".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); + } +} \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Devices/MarioHubPants.cs b/src/SharpBrick.PoweredUp/Devices/MarioHubPants.cs new file mode 100644 index 0000000..5ba181c --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/MarioHubPants.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp +{ + public class MarioHubPants : Device, IPoweredUpDevice + { + public MarioHubPants() + { } + + public MarioHubPants(ILegoWirelessProtocol protocol, byte hubId, byte portId) + : base(protocol, hubId, portId) + { + } + + public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion) + => @" +".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); + } +} \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Devices/MarioHubTagSensor.cs b/src/SharpBrick.PoweredUp/Devices/MarioHubTagSensor.cs new file mode 100644 index 0000000..3d103b0 --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/MarioHubTagSensor.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp +{ + public class MarioHubTagSensor : Device, IPoweredUpDevice + { + public MarioHubTagSensor() + { } + + public MarioHubTagSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId) + : base(protocol, hubId, portId) + { + } + + public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion) + => @" +".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); + } +} \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Enums/DeviceType.cs b/src/SharpBrick.PoweredUp/Enums/DeviceType.cs index 04c58c1..b1f9ac5 100644 --- a/src/SharpBrick.PoweredUp/Enums/DeviceType.cs +++ b/src/SharpBrick.PoweredUp/Enums/DeviceType.cs @@ -37,5 +37,9 @@ public enum DeviceType : ushort TechnicColorSensor = 0x003D, // UNSPECED, TECHNIC_COLOR_SENSOR (Spike Prime) TechnicDistanceSensor = 0x003E, // UNSPECED, TECHNIC_DISTANCE_SENSOR (Spike Prime) TechnicForceSensor = 0x003F, // UNSPECED, TECHNIC_FORCE_SENSOR (Spike Prime) + MarioHubAccelerometer = 0x0040, // UNSPCED, https://github.com/bricklife/LEGO-Mario-Reveng (Lego Mario) + MarioHubTagSensor = 0x041, // UNSPCED, https://github.com/bricklife/LEGO-Mario-Reveng (Lego Mario) + MarioHubPants = 0x0042, // UNSPCED, https://github.com/bricklife/LEGO-Mario-Reveng (Lego Mario) + MarioHubDebug = 0x0043, // UNSPCED, https://github.com/bricklife/LEGO-Mario-Reveng (Lego Mario) } } \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/Hubs/HubFactory.cs b/src/SharpBrick.PoweredUp/Hubs/HubFactory.cs index 796a9dc..9c6d39d 100644 --- a/src/SharpBrick.PoweredUp/Hubs/HubFactory.cs +++ b/src/SharpBrick.PoweredUp/Hubs/HubFactory.cs @@ -38,6 +38,7 @@ public static Type GetTypeFromSystemType(SystemType systemType) => systemType switch { SystemType.LegoTechnic_MediumHub => typeof(TechnicMediumHub), + SystemType.LegoSystem_Mario => typeof(MarioHub), _ => throw new NotSupportedException(), }; @@ -45,6 +46,7 @@ public static SystemType GetSystemTypeFromType(Type type) => type.Name switch { nameof(TechnicMediumHub) => SystemType.LegoTechnic_MediumHub, + nameof(MarioHub) => SystemType.LegoSystem_Mario, _ => throw new NotSupportedException(), }; } diff --git a/src/SharpBrick.PoweredUp/Hubs/MarioHub.cs b/src/SharpBrick.PoweredUp/Hubs/MarioHub.cs new file mode 100644 index 0000000..b1157a2 --- /dev/null +++ b/src/SharpBrick.PoweredUp/Hubs/MarioHub.cs @@ -0,0 +1,26 @@ +using System; +using Microsoft.Extensions.Logging; +using SharpBrick.PoweredUp.Devices; +using SharpBrick.PoweredUp.Protocol; + +namespace SharpBrick.PoweredUp +{ + public class MarioHub : Hub + { + public MarioHub(ILegoWirelessProtocol protocol, IDeviceFactory deviceFactory, ILogger logger, IServiceProvider serviceProvider = default) + : base(protocol, deviceFactory, logger, serviceProvider, new Port[] { + new Port(0, string.Empty, false, expectedDevice: DeviceType.MarioHubAccelerometer), + new Port(1, string.Empty, false, expectedDevice: DeviceType.MarioHubTagSensor), + new Port(2, string.Empty, false, expectedDevice: DeviceType.MarioHubPants), + new Port(3, string.Empty, false, expectedDevice: DeviceType.MarioHubDebug), + new Port(6, string.Empty, false, expectedDevice: DeviceType.Voltage), + }) + { } + + public MarioHubAccelerometer Accelerometer => Port(0).GetDevice(); + public MarioHubTagSensor TagSensor => Port(1).GetDevice(); + public MarioHubPants Pants => Port(2).GetDevice(); + public MarioHubDebug Debug => Port(3).GetDevice(); + public Voltage Voltage => Port(6).GetDevice(); + } +} \ No newline at end of file diff --git a/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs b/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs index a95094f..565b141 100644 --- a/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs +++ b/src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs @@ -22,6 +22,7 @@ public static IServiceCollection AddPoweredUp(this IServiceCollection self) // hubs .AddTransient() + .AddTransient() // functions .AddTransient()