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 Matrix binding for HT16K33 #1916

Merged
merged 21 commits into from
Jan 5, 2023
Merged

Conversation

richlander
Copy link
Member

@richlander richlander commented Aug 31, 2022

This PR adds i2c-based bindings for the Adafruit matrices. It uses the same HT16K33 chip as is used in the Display folder.

Adafruit 8x8 0.8" LED Matrix + Backpack
Adafruit 8x8 1.2" LED Matrix + Backpack
Adafruit 8x8 1.2" bicolor LED Matrix + Backpack
Adafruit 16x8 1.2" LED Matrix + Backpack

Products:

I didn't implement any animation capabilities for this binding. Same with fonts. That should be implemented a layer higher, IMO. We can discuss that.

There is an open question on how to implement all the different capabilities:

  • Different sizes: 8x8 vs 16x8
  • Colors: single vs multi-color

The Adafruit implementation uses one type for matrix type. That seems like the way to go.

Note: I didn't use the Adafruit implementation as the basis for my implementation. I just used an empirical approach to determine which bytes affected which parts of the matrix and then designed the implementation to do same.

This will have merge conflicts with #1915. I'll resolve those once one of them gets merged.

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-device-bindings Device Bindings for audio, sensor, motor, and display hardware that can used with System.Device.Gpio label Aug 31, 2022
src/devices/Display/Matrix16x8.cs Outdated Show resolved Hide resolved
src/devices/Display/Matrix16x8.cs Outdated Show resolved Hide resolved
Co-authored-by: Günther Foidl <gue@korporal.at>
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.

Nice additions, few minor comments

/// <summary>
/// Writes bytes to matrix, row by row
/// </summary>
public void Write(ReadOnlySpan<byte> data)
Copy link
Member

Choose a reason for hiding this comment

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

why you need this function while you have the previous one?

rowIndex++;
}

if (BufferingEnabled)
Copy link
Member

Choose a reason for hiding this comment

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

as you have those 4 lines in many places, does it make sense to replace it by a simple function?
somthing like this?

private void FlushIfNeed() => BufferEnabled ? Flush(): return;

@@ -0,0 +1,128 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

Copy link
Member

Choose a reason for hiding this comment

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

maybe update the main README.md to add some of those elements?

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 idea. Will do that after the Bicolor PR merges.

@richlander richlander changed the title Add Matrix16x8 binding for HT16K33 Add Matrix binding for HT16K33 Sep 7, 2022
@Ellerbach
Copy link
Member

@richlander looking at the PR, don't you want to add the nice animated gif as well in the README? At least it shows how things looks like.

@pgrawehr
Copy link
Contributor

/azp run dotnet.iot

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@pgrawehr
Copy link
Contributor

@joperezr Any idea what's wrong with the MacOS build?

This is confusing:

2022-09-15T12:05:10.2083160Z Build FAILED.
2022-09-15T12:05:10.2184840Z     0 Warning(s)
2022-09-15T12:05:10.2252330Z     0 Error(s)

@joperezr
Copy link
Member

@joperezr Any idea what's wrong with the MacOS build?

This is confusing:

2022-09-15T12:05:10.2083160Z Build FAILED.
2022-09-15T12:05:10.2184840Z     0 Warning(s)
2022-09-15T12:05:10.2252330Z     0 Error(s)

Yes, this failed due to a failing unit test in Button.tests.csproj. There is a bug in VSTest that when test projects are run in parallel, not all of them will log out the failures into the console, but if you take the build's binlog and create a diagnostic log out of it, you'll see that:

12:05:10.012 277:5>Done building target "VSTest" in project "Button.tests.csproj" -- FAILED.: (TargetId:20063)
12:05:10.012 277:5>Done Building Project "/Users/runner/work/1/s/src/devices/Button/tests/Button.tests.csproj" (VSTest target(s)) -- FAILED.
12:05:10.014   3:7>Done executing task "MSBuild" -- FAILED. (TaskId:15340)
12:05:10.015   3:7>Done building target "Build" in project "build.proj" -- FAILED.: (TargetId:4401)
12:05:10.015   3:7>Done Building Project "/Users/runner/work/1/s/build.proj" (Build target(s)) -- FAILED.
12:05:10.022     1>Done executing task "MSBuild" -- FAILED. (TaskId:5048)
12:05:10.022     1>Done building target "Execute" in project "Build.proj" -- FAILED.: (TargetId:2)

@richlander
Copy link
Member Author

This PR should be ready to go now. I resolved conflicts with #1915, updated the README, and added a TPN entry.

@pgrawehr
Copy link
Contributor

This PR should be ready to go now. I resolved conflicts with #1915, updated the README, and added a TPN entry.

Thanks. We do need to find out what's wrong with the macos builds, though (certainly not related to the changes, but still weird)

@pgrawehr
Copy link
Contributor

/azp run dotnet.iot

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@richlander
Copy link
Member Author

richlander commented Nov 7, 2022

I merged main into this branch. Looks like some extra checks came in, including one for compat.

I broke compat with this change since I wanted to align this binding with the one I made just before this. Both have a bi-color capability, and they should share the same enum. How I break compat?

Changes in question are in BiColorBarGraph.cs: https://github.com/dotnet/iot/pull/1916/files#diff-b09b55d11cc73c84b4aa6b624800874abed3c1dd13f47f27edb611f2fd82a446

On that note, should I be using Color instead? Here, I have three colors: red, yellow, and green.

The markdown link check also failed, however, I can reach the link that failed. I'm guessing that's a one-off issue. It didn't fail in main.

@pgrawehr
Copy link
Contributor

pgrawehr commented Nov 7, 2022

@richlander We don't really care much about such changes in Iot.Device.Bindings. If the unification makes sense (and it seems to me it does) the breaking change is typically ok.

@richlander
Copy link
Member Author

/azp run dotnet.iot

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@joperezr
Copy link
Member

joperezr commented Nov 7, 2022

Hey @richlander, took the liberty to push the breaking changes suppressions as well as the broken link issue (which wasn't related to your PR). Hope that's ok with you.

@richlander
Copy link
Member Author

I just re-tested all the devices. I found and fixed one (off by one) sample bug.

Looks like the linter bug is the last one on this PR so I think we can merge this one.

@joperezr joperezr merged commit ae7b4af into dotnet:main Jan 5, 2023
@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.

5 participants