Skip to content

Commit

Permalink
Add Mario's Tag Sensor
Browse files Browse the repository at this point in the history
-  RGB Sensor
- Tag Sensor

#91 non-breaking
  • Loading branch information
tthiery committed Oct 4, 2020
1 parent 1b8ddd6 commit 662f2fb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/SharpBrick.PoweredUp/Devices/MarioHubTagSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,33 @@ namespace SharpBrick.PoweredUp
{
public class MarioHubTagSensor : Device, IPoweredUpDevice
{
protected MultiValueMode<short> _tagMode;
protected MultiValueMode<sbyte> _rgbMode;

public byte ModeIndexTag { get; protected set; } = 0;
public byte ModeIndexRgb { get; protected set; } = 1;


public MarioBarcode Barcode => (MarioBarcode)_tagMode.SI[0];
public MarioColor ColorNo => (MarioColor)_tagMode.SI[1];
public IObservable<MarioBarcode> BarcodeObservable => _tagMode.Observable.Select(x => (MarioBarcode)x.SI[0]);
public IObservable<MarioColor> ColorNoObservable => _tagMode.Observable.Select(x => (MarioColor)x.SI[1]);

public (byte red, byte green, byte blue) RgbColor => ((byte)_rgbMode.SI[0], (byte)_rgbMode.SI[1], (byte)_rgbMode.SI[2]);
public IObservable<(byte red, byte green, byte blue)> RgbColorObservable => _rgbMode.Observable.Select(x => ((byte)x.SI[0], (byte)x.SI[1], (byte)x.SI[2]));

public MarioHubTagSensor()
{ }

public MarioHubTagSensor(ILegoWirelessProtocol protocol, byte hubId, byte portId)
: base(protocol, hubId, portId)
{
_tagMode = MultiValueMode<short>(ModeIndexTag);
_rgbMode = MultiValueMode<sbyte>(ModeIndexRgb);

ObserveForPropertyChanged(_tagMode.Observable, nameof(Barcode));
ObserveForPropertyChanged(_tagMode.Observable, nameof(ColorNo));
ObserveForPropertyChanged(_rgbMode.Observable, nameof(RgbColor));
}

public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion)
Expand Down
14 changes: 14 additions & 0 deletions src/SharpBrick.PoweredUp/Enums/MarioBarcode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace SharpBrick.PoweredUp
{
public enum MarioBarcode : ushort
{
None = 0xFFFF,
Thwomp = 0x0002,
Refresh = 0x0014,
Question = 0x0029,
Cloud = 0x002E,
BowserJr = 0x0099,
BowserGoal = 0x00B7,
Pipe = 0x00B8,
}
}
17 changes: 17 additions & 0 deletions src/SharpBrick.PoweredUp/Enums/MarioColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace SharpBrick.PoweredUp
{
public enum MarioColor : ushort
{
None = 0xFFFF,
White = 0x0013,
Red = 0x0015,
Blue = 0x0017,
Yellow = 0x0018,
Black = 0x001A,
Green = 0x0025,
Brown = 0x006A,
Unknown1 = 0x010C,
Unknown2 = 0x0138,
Cyan = 0x0142,
}
}

0 comments on commit 662f2fb

Please sign in to comment.