Skip to content

Commit

Permalink
Add support for Micro Dot pHat
Browse files Browse the repository at this point in the history
  • Loading branch information
richlander committed Dec 17, 2022
1 parent 5b8c341 commit 0d1e95f
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 252 deletions.
61 changes: 0 additions & 61 deletions src/devices/Is31fl3730/Bonnet5x7x6.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@ namespace Iot.Device.Display
/// <summary>
/// Represents LED Dot Matrix driven by IS31FL3730.
/// </summary>
public class Matrix3730
public class DotMatrix5x7
{
private readonly Is31fl3730 _is31fl3730;
private readonly int _matrix;

/// <summary>
/// Initialize IS31FL3730 device
/// Initialize Dot Matrix IS31FL3730 device.
/// </summary>
/// <param name="is31fl3730">The <see cref="Iot.Device.Display.Is31fl3730"/> to create with.</param>
/// <param name="matrix">The index of the matrix (of a pair).</param>
public Matrix3730(Is31fl3730 is31fl3730, int matrix)
public DotMatrix5x7(Is31fl3730 is31fl3730, int matrix)
{
_is31fl3730 = is31fl3730;
Matrix = matrix;
_matrix = matrix;
}

/// <summary>
/// Indexer for matrix.
/// Indexer for matrix. x: 0..4; y: 0..6.
/// </summary>
public int this[int x, int y]
{
get => _is31fl3730.ReadLed(Matrix, x, y);
set => _is31fl3730.WriteLed(Matrix, x, y, value);
get => _is31fl3730.Read(_matrix, x, y);
set => _is31fl3730.Write(_matrix, x, y, value);
}

/// <summary>
Expand All @@ -45,19 +46,14 @@ public Matrix3730(Is31fl3730 is31fl3730, int matrix)
/// </summary>
public readonly int Height = 7;

/// <summary>
/// Identification of matrix (of 2).
/// </summary>
public readonly int Matrix = 0;

/// <summary>
/// Fill matrix (0 is dark; 1 is lit).
/// </summary>
public void Fill(int value) => _is31fl3730.Fill(Matrix, value);
public void Fill(int value) => _is31fl3730.Fill(_matrix, value);

/// <summary>
/// Fill matrix (0 is dark; 1 is lit).
/// </summary>
public void UpdateDecimalPoint(int value) => _is31fl3730.UpdateDecimalPoint(Matrix, value);
public void WriteDecimalPoint(int value) => _is31fl3730.WriteDecimalPoint(_matrix, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,43 @@ namespace Iot.Device.Display
// Datasheet: https://cdn-shop.adafruit.com/product-files/3017/31FL3730.pdf
// Product: https://shop.pimoroni.com/products/led-dot-matrix-breakout
// Related repo: https://github.com/pimoroni/microdot-phat
public class BreakoutPair5x7
public class DotMatrixBreakout10x7
{
private readonly Matrix3730[] _pair;
private readonly DotMatrix5x7[] _matrices;
private Is31fl3730 _is31fl3730;

/// <summary>
/// Initialize IS31FL3730 device
/// Initialize Dot Matrix Breakout IS31FL3730 device.
/// </summary>
/// <param name="i2cDevice">The <see cref="System.Device.I2c.I2cDevice"/> to create with.</param>
public BreakoutPair5x7(I2cDevice i2cDevice)
public DotMatrixBreakout10x7(I2cDevice i2cDevice)
{
i2cDevice = i2cDevice ?? throw new ArgumentException($"{nameof(i2cDevice)} is null.");
_is31fl3730 = new(i2cDevice);
_is31fl3730.DisplayMode = DisplayMode.MatrixOneAndTwo;
_is31fl3730.Initialize();
_pair = new Matrix3730[]
_matrices = new DotMatrix5x7[]
{
new Matrix3730(_is31fl3730, 0),
new Matrix3730(_is31fl3730, 1)
new DotMatrix5x7(_is31fl3730, 0),
new DotMatrix5x7(_is31fl3730, 1)
};
}

/// <summary>
/// Initialize IS31FL3730 device
/// Initialize Dot Matrix Breakout IS31FL3730 device.
/// </summary>
/// <param name="is31fl3730">The <see cref="Iot.Device.Display.Is31fl3730"/> to create with.</param>
public BreakoutPair5x7(Is31fl3730 is31fl3730)
public DotMatrixBreakout10x7(Is31fl3730 is31fl3730)
{
is31fl3730 = is31fl3730 ?? throw new ArgumentException($"{nameof(is31fl3730)} is null.");
_is31fl3730 = is31fl3730;
_pair = new Matrix3730[]
_matrices = new DotMatrix5x7[]
{
new Matrix3730(_is31fl3730, 0),
new Matrix3730(_is31fl3730, 1)
new DotMatrix5x7(_is31fl3730, 0),
new DotMatrix5x7(_is31fl3730, 1)
};
}

/// <summary>
/// Indexer for matrix pair.
/// </summary>
public Matrix3730 this[int matrix]
{
get => _pair[matrix];
}

/// <summary>
/// Default I2C address for device.
/// </summary>
Expand All @@ -76,13 +68,41 @@ public BreakoutPair5x7(Is31fl3730 is31fl3730)
public readonly int Height = 7;

/// <summary>
/// Identification of matrix (of 2).
/// Indexer for matrices.
/// </summary>
public readonly int Matrix = 0;
public DotMatrix5x7 this[int matrix] => _matrices[matrix];

/// <summary>
/// Indexer for matrix pair.
/// </summary>
public int this[int x, int y]
{
get => x switch
{
< 5 => this[0][x, y],
< 10 => this[1][x - 5, y],
_ => throw new ArgumentException($"{nameof(x)} value out of range")
};
set
{
if (x < 5)
{
this[0][x, y] = value;
}
else if (x < 10)
{
this[1][x - 5, y] = value;
}
else
{
throw new ArgumentException($"{nameof(x)} value out of range");
}
}
}

/// <summary>
/// Fill All LEDs.
/// </summary>
public void Fill(int value) => _is31fl3730.FillAll(value);
public void Fill(int value) => _is31fl3730.Fill(value);
}
}

0 comments on commit 0d1e95f

Please sign in to comment.