Skip to content

Commit

Permalink
Add MarioHub and related devices
Browse files Browse the repository at this point in the history
- Devices are empty shells currently

#91 non-breaking
  • Loading branch information
tthiery committed Oct 4, 2020
1 parent 4c95bd0 commit f1bce21
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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,
};
}
Expand Down
24 changes: 24 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/MarioHubAccelerometer.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion)
=> @"
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}
24 changes: 24 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/MarioHubDebug.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion)
=> @"
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}
24 changes: 24 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/MarioHubPants.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion)
=> @"
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}
24 changes: 24 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/MarioHubTagSensor.cs
Original file line number Diff line number Diff line change
@@ -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<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion)
=> @"
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s));
}
}
4 changes: 4 additions & 0 deletions src/SharpBrick.PoweredUp/Enums/DeviceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 2 additions & 0 deletions src/SharpBrick.PoweredUp/Hubs/HubFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ public static Type GetTypeFromSystemType(SystemType systemType)
=> systemType switch
{
SystemType.LegoTechnic_MediumHub => typeof(TechnicMediumHub),
SystemType.LegoSystem_Mario => typeof(MarioHub),
_ => throw new NotSupportedException(),
};

public static SystemType GetSystemTypeFromType(Type type)
=> type.Name switch
{
nameof(TechnicMediumHub) => SystemType.LegoTechnic_MediumHub,
nameof(MarioHub) => SystemType.LegoSystem_Mario,
_ => throw new NotSupportedException(),
};
}
Expand Down
26 changes: 26 additions & 0 deletions src/SharpBrick.PoweredUp/Hubs/MarioHub.cs
Original file line number Diff line number Diff line change
@@ -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<MarioHub> 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<MarioHubAccelerometer>();
public MarioHubTagSensor TagSensor => Port(1).GetDevice<MarioHubTagSensor>();
public MarioHubPants Pants => Port(2).GetDevice<MarioHubPants>();
public MarioHubDebug Debug => Port(3).GetDevice<MarioHubDebug>();
public Voltage Voltage => Port(6).GetDevice<Voltage>();
}
}
1 change: 1 addition & 0 deletions src/SharpBrick.PoweredUp/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static IServiceCollection AddPoweredUp(this IServiceCollection self)

// hubs
.AddTransient<TechnicMediumHub>()
.AddTransient<MarioHub>()

// functions
.AddTransient<DiscoverPorts>()
Expand Down

0 comments on commit f1bce21

Please sign in to comment.