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

Pullrequest/wedo2 #198

Merged
merged 4 commits into from
Jan 15, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/DeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/SimpleMediumLinearMotor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SharpBrick.PoweredUp.Protocol;
using SharpBrick.PoweredUp.Utils;

namespace SharpBrick.PoweredUp;

/// <summary>
/// SimpleMediumLinearMotor, advertised as Motor, only supports power mode, this works for the WoDo 2.0 Medium (LPF2-MMOTOR)
/// </summary>
public class SimpleMediumLinearMotor : BasicMotor, IPoweredUpDevice
{
public SimpleMediumLinearMotor()
: base()
{ }
public SimpleMediumLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{ }

public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType)
// Dump taken from LEGO 6290182 - 21980 - Electric, Motor WeDo 2.0 Medium which reports as 'LPF2-MMOTOR'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, the motor is not reporting that but your MediumTechnicHub describes the motor. The Lego Wireless Protocol is a Bluetooth protocol, not a wire protocol between the hub and the motor. It could though, but I am not aware of any details there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but of course we communicate with the Hub, but I think the data essentially comes from the motor and is translated and passed on by the hub, don't all motors work with all hubs? All hubs would have to know all device types then.

=> @"
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));
}
Loading