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

First version of a driver for WS2801 #78

Closed
wants to merge 1 commit into from

Conversation

sistr22
Copy link

@sistr22 sistr22 commented Nov 10, 2017

No description provided.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@sistr22
Copy link
Author

sistr22 commented Nov 10, 2017 via email

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@proppy
Copy link
Contributor

proppy commented Nov 13, 2017

It'd be nice to consolidate with #11 and #76.

Also see the design discussion in #14 where we discuss how we can converge the API with what we already have for apa102 LEDs.
https://github.com/androidthings/contrib-drivers/blob/master/apa102/src/main/java/com/google/android/things/contrib/driver/apa102/Apa102.java

@sistr22
Copy link
Author

sistr22 commented Nov 15, 2017

I've taken a look to both driver.
Generally speaking, I like "lightweight" driver as much as possible.
The more code a driver has the more likely a bug will arise and it'll be harder to debug.
I also like the idea of "1 hardware, 1 driver" but I understand that many dev prefer to consolidate code to avoid duplication, I think both approach have pros & cans and are viable.
Seeing a small driver, easily readable, also avoid other potential contributor to be scare to write their own driver for a new hardware.

spi_device.setDelay(1000);
}

public void SetColor(int position, int red, int green, int blue) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

google code conventions state methods should start with a lowercase letter

https://source.android.com/setup/code-style

public class Ws2801 {
private SpiDevice spi_device;
private byte[] data;
private int nb_leds;
Copy link
Contributor

Choose a reason for hiding this comment

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

if you call this numberOfLeds it makes the code much more understandable


public void SetColor(int position, int color) {
if(position > nb_leds)
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

might be better to throw an exception so a user gets instant feedback that they have done something unexpected

SetColor(position, Color.rgb(red, green, blue));
}

public void SetColor(int position, int color) {
Copy link
Contributor

@proppy proppy Nov 16, 2017

Choose a reason for hiding this comment

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

What about exposing a write(android.graphics.Color[]) method like the apa driver instead?

Even if we end up with distinct drivers for each variant of LED strips, it would be nice if they were sharing some convention.

@sistr22 sistr22 closed this Nov 16, 2017
@sistr22
Copy link
Author

sistr22 commented Nov 16, 2017

I changed my driver too much (now most of it is in C++ using JNI) to update the pull request and fix the remark :/

@proppy
Copy link
Contributor

proppy commented Nov 16, 2017

@WhiteSEEKER Do you see improved performance? I wouldn't expect much since the NDK API calls for Peripheral manager still go thru the same IPC route as the Java one.

@sistr22
Copy link
Author

sistr22 commented Nov 16, 2017

It actually has worse perf due to the JNI calls I guess (which is unfortunate).
But it's easier to maintain for me, and the rest of my code is all C (to be cross platform, the project I'm working on initially started on RasberryPi).
It would de nice to have a high perf C++ api to write driver (like the spi class) to make it a better experience porting project from arduino / rasberry pi or supporting all platforms.
The driver implementation would still be different on each platform (but hopefully the header could be the same), but everything else would be written in C/C++ and be cross platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants