diff --git a/README.md b/README.md index 1e93d9c..8bb064d 100644 --- a/README.md +++ b/README.md @@ -338,6 +338,7 @@ DI Container Elements - [X] Technic Large Angular Motor (Grey) - [X] Technic Color Sensor - [X] Technic Distance Sensor + - [X] Motor WeDo 2.0 Medium (21980) - .. other devices depend on availability of hardware / contributions - Protocol - [X] Message Encoding (98% [spec coverage](docs/specification/coverage.md)) diff --git a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs index 53afdb6..715d2fe 100644 --- a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs +++ b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs @@ -30,6 +30,7 @@ public IPoweredUpDevice CreateConnected(DeviceType deviceType, ILegoWirelessProt public Type GetTypeFromDeviceType(DeviceType deviceType) => deviceType switch { + DeviceType.Motor => typeof(SimpleMediumLinearMotor), DeviceType.Voltage => typeof(Voltage), DeviceType.Current => typeof(Current), DeviceType.RgbLight => typeof(RgbLight), @@ -65,6 +66,7 @@ public Type GetTypeFromDeviceType(DeviceType deviceType) public static DeviceType GetDeviceTypeFromType(Type type) => type.Name switch // fuzzy but will work { + nameof(SimpleMediumLinearMotor) => DeviceType.Motor, nameof(Voltage) => DeviceType.Voltage, nameof(Current) => DeviceType.Current, nameof(RgbLight) => DeviceType.RgbLight, diff --git a/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs new file mode 100644 index 0000000..3c589c5 --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp; + +/// +/// SimpleMediumLinearMotor, advertised as Motor, only supports power mode, this works for the WoDo 2.0 Medium (LPF2-MMOTOR) +/// +public class SimpleMediumLinearMotor : BasicMotor, IPoweredUpDevice +{ + public SimpleMediumLinearMotor() + : base() + { } + public SimpleMediumLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId) + : base(protocol, hubId, portId) + { } + + public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType) + // Dump taken from LEGO 6290182 - 21980 - Electric, Motor WeDo 2.0 Medium which reports as 'LPF2-MMOTOR'. + => @" +0B-00-43-02-01-01-01-00-00-01-00 +05-00-43-02-02 +11-00-44-02-00-00-4C-50-46-32-2D-4D-4D-4F-54-4F-52 +0E-00-44-02-00-01-00-00-C8-C2-00-00-C8-42 +0E-00-44-02-00-02-00-00-C8-C2-00-00-C8-42 +0E-00-44-02-00-03-00-00-C8-C2-00-00-C8-42 +0A-00-44-02-00-04-00-00-00-00 +08-00-44-02-00-05-00-10 +0A-00-44-02-00-80-01-00-04-00 +".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); +}