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

Add LED matrix bindings for IS31FL3731 driver #1926

Merged
merged 44 commits into from
Jan 16, 2023

Conversation

@ghost ghost added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Sep 17, 2022
@richlander richlander changed the title Add LED matrix bindings for ISs31FL3731 driver Add LED matrix bindings for IS31FL3731 driver Sep 19, 2022
Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Couple of comments. Also, we should have a discussion regarding simple things like Color. With changes in the graphic libs, we need to come with something simple we can use anywhere for consistency

src/devices/Is31fl3731/Bonnet16x8.cs Show resolved Hide resolved
/// <param name="r">Red brightness value 0->255.</param>
/// <param name="g">Green brightness value 0->255.</param>
/// <param name="b">Blue brightness value 0->255.</param>
public void WritePixelRgb(int x, int y, int r, int g, int b)
Copy link
Member

Choose a reason for hiding this comment

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

I know we are switching our graphic lib but we've been using Color in other bindings to pass colors. I would like to see that because of the predefined colors for example

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

// Command register
// Points pages one to nine
// table 2 in datasheet
private const byte COMMAND_REGISTER = 0xFD;
Copy link
Member

Choose a reason for hiding this comment

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

I'm a big fan of having all those in a Registers.cs file as an internal enum. It's much cleaner than using constants

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about that. It's gonna make the code look pretty ugly without target typed enums.

Let's take a look.

This line:

Write(FUNCTION_REGISTER, DISPLAY_REGISTER, (byte)value);

Will turn into:

Write(Registers.FUNCTION_REGISTER, Registers.DISPLAY_REGISTER, (byte)value);

Right? I think that makes the C# look worse as compared to the Python code I read. Seems like this is trading cleanup at the top of the file for worse readability within the core logic.

Copy link
Member

Choose a reason for hiding this comment

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

I really prefer to use enums because they avoid problems. You can group them. And in this case have 2 different enums, one for the register and one for the command.
Short term const seems super nice. Then when it comes to maintenance, they are not good at all. Enums forces you to use the right one. Here on the Write function, I can use the wrong one very easilly.

So most likely your write will turn out like with 2 different enums. And when you have possibility to mix elements, it's much easier for maintenance and readability with enums:

Write(Function.FUNCTION_REGISTER, Register.DISPLAY_REGISTER, (byte)value);

Copy link
Member Author

Choose a reason for hiding this comment

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

I get it now. Thanks for explanation. Basically "type safety".

src/devices/Is31fl3731/Is31Fl3731.cs Outdated Show resolved Hide resolved
src/devices/Is31fl3731/Is31Fl3731.cs Outdated Show resolved Hide resolved
src/devices/Is31fl3731/Is31Fl3731.cs Outdated Show resolved Hide resolved
src/devices/Is31fl3731/Is31Fl3731.cs Outdated Show resolved Hide resolved
src/devices/Is31fl3731/Is31Fl3731.cs Outdated Show resolved Hide resolved
(21, 0) => 15,
(_, 0) => x - 14,
// y == 1
(<2, 1) => 69 - x,
Copy link
Member

Choose a reason for hiding this comment

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

you're missing some spaces in the following lines

Copy link
Member Author

@richlander richlander Nov 7, 2022

Choose a reason for hiding this comment

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

Fixed.

/// <param name="r">Red brightness value 0->255.</param>
/// <param name="g">Green brightness value 0->255.</param>
/// <param name="b">Blue brightness value 0->255.</param>
public void WritePixelRgb(int x, int r, int g, int b)
Copy link
Member

Choose a reason for hiding this comment

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

Same feedback as for the other one: usage of Color

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@richlander
Copy link
Member Author

I need to re-test all the devices and then I'll switch this PR to "Ready for review".

// Command register
// Points pages one to nine
// table 2 in datasheet
private const byte COMMAND_REGISTER = 0xFD;
Copy link
Member

Choose a reason for hiding this comment

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

rather than private const, a nice enum is always preferable especially in that case where you have quite a lot of them.

Copy link
Member Author

@richlander richlander Nov 7, 2022

Choose a reason for hiding this comment

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

I raised a concern on that. What are your thoughts? This is the official Python implementation: https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731/blob/main/adafruit_is31fl3731/__init__.py

#1926 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

I commented then on the other comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I took your advice.

I first tried enums. That looked pretty rough to me since I had to add a cast at every callsite: f3c7b63

I then switched to static classes. That resolved the issue: ecd652f

I left the API signatures as byte. The reason is that there are multiple registers and their values overlap. Also, one of the registers takes values 0-7 for 8 pages of data. Forcing the use of an enum or static class to iterate from 0..7 doesn't make much sense.

Seem better?

@richlander
Copy link
Member Author

This link seems to consistently fail.

image

@richlander richlander marked this pull request as ready for review November 30, 2022 02:17
/// </summary>
// Enables pages one to nine
// Table 2 in datasheet
public static class CommandRegister
Copy link
Member

Choose a reason for hiding this comment

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

why public cstatic lasses and not enums? you don't seem to override them or anything like this.

// https://www.adafruit.com/product/2974
using I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, Backpack16x9.DefaultI2cAddress));
Backpack16x9 matrix = new(i2cDevice);
// For 16x8 matrix Charlieplex bonet
Copy link
Member

Choose a reason for hiding this comment

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

maybe itroduce an empty line between each block of matrix? you can as well use 4 slash or dashes or anything to make it more redable

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. Done.

Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

Very minor comments, all look very nice :-) mpatient to buy few of those and find time to use them :-)

Copy link
Contributor

@pgrawehr pgrawehr left a comment

Choose a reason for hiding this comment

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

Few comments that (I think) explain the build failures.

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Contributor

Choose a reason for hiding this comment

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

Please put all sample projects into separate folder (samples\sample1, samples\sample2, etc.). Having multiple .csproj files in the same folder causes problems on macos due to a compiler bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe that there are multiple bindings that have that problem. Is this our new policy?

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net60</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

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

TFM must be net6.0

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net60</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

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

TFM must be net6.0.

@ghost ghost added the Needs: Author Feedback We are waiting for author to react to feedback (action required) label Dec 4, 2022
@ghost
Copy link

ghost commented Dec 11, 2022

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days.

@ghost ghost removed Needs: Author Feedback We are waiting for author to react to feedback (action required) Status: No Recent Activity labels Dec 13, 2022
@richlander
Copy link
Member Author

I just looked through the logs. None of the errors seem related to this PR.

@pgrawehr
Copy link
Contributor

This needs a conflict resolution.

@richlander richlander merged commit 2580229 into dotnet:main Jan 16, 2023
@richlander richlander deleted the Is31Fl3731 branch January 16, 2023 20:40
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants