From aef357612551193eb70e6a86ee4f0000de38d134 Mon Sep 17 00:00:00 2001 From: Menno Lodder Date: Sun, 14 Jan 2024 16:28:11 +0100 Subject: [PATCH 1/4] Created SimpleMediumLinearMotor --- .../Devices/DeviceFactory.cs | 1 + .../Devices/SimpleMediumLinearMotor.cs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs diff --git a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs index 53afdb6..6bedcc7 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), diff --git a/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs new file mode 100644 index 0000000..fc60a0c --- /dev/null +++ b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SharpBrick.PoweredUp.Protocol; +using SharpBrick.PoweredUp.Utils; + +namespace SharpBrick.PoweredUp; + +// TODO which motor to extend here. ? +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) + => @" +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)); +} From 6aab246ca94fdeef7c26fff5b23684be33908c53 Mon Sep 17 00:00:00 2001 From: Menno Lodder Date: Sun, 14 Jan 2024 21:43:09 +0100 Subject: [PATCH 2/4] Added explanation --- src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs index fc60a0c..b140d34 100644 --- a/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs @@ -16,7 +16,8 @@ public SimpleMediumLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte : base(protocol, hubId, portId) { } - public IEnumerable GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType) + 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 From 5a582b50d929379a0ed3fd9639274fc710dd47a7 Mon Sep 17 00:00:00 2001 From: Menno Lodder Date: Mon, 15 Jan 2024 20:17:30 +0100 Subject: [PATCH 3/4] Added last reference needed for new motor type --- src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs | 1 + src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs index 6bedcc7..715d2fe 100644 --- a/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs +++ b/src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs @@ -66,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 index b140d34..3c589c5 100644 --- a/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs +++ b/src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs @@ -6,7 +6,9 @@ namespace SharpBrick.PoweredUp; -// TODO which motor to extend here. ? +/// +/// 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() From 3578d1696cbce463b2c6941d79b401f0dbd31e9d Mon Sep 17 00:00:00 2001 From: mennolodder <7911897+mennolodder@users.noreply.github.com> Date: Mon, 15 Jan 2024 20:59:30 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) 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))