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

Adds basic LED functionality #52

Merged
merged 1 commit into from Jul 1, 2015
Merged

Adds basic LED functionality #52

merged 1 commit into from Jul 1, 2015

Conversation

johnnyman727
Copy link
Contributor

This PR adds the ability to blink the four LEDs on T2. There are a couple of things to note:

  1. With Tessel 1, the LEDs were also part of the PIN class because they could utilize the same sort of interrupt functionality. That's not the case here so I made a distinct LED class
  2. There are some LED properties/methods from T2 that aren't implemented here because they don't make sense like pull resistors.
  3. I added a color property because I thought that would be useful for some people.
  4. I'm not sure how using these LEDs will affect any pre-existing triggers (like WLAN) or how to change them back if that is the case.
  5. The old API returned an instance of the Pin object to change calls. I didn't do that here because all of the calls are async. We could consider making sync versions of the calls that you can chain together.

@kevinmehall can you check it out?

@@ -15,6 +16,13 @@ function Tessel() {
};
this.port = this.ports;

this.led = [
new LED('red', '/sys/devices/leds/leds/tessel:red:error/brightness'),
new LED('amber', '/sys/devices/leds/leds/tessel:amber:wlan//brightness'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct? wlan//brightness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I should remove that extra slash. Somehow it still worked :)

@kevinmehall
Copy link
Member

lgtm

@johnnyman727
Copy link
Contributor Author

@kevinmehall can you comment on point 4 above?

@kevinmehall
Copy link
Member

It doesn't change the triggers, so I don't think it will do anything with the WLAN LED and won't be able to add triggers . To modify the triggers, you write to the trigger file in the LED directory. I don' think trigger support is critical for now. You may want to remove the WLAN LED from this PR because of this.

@johnnyman727
Copy link
Contributor Author

So if I understand you correctly, network traffic will continue to manipulate the WLAN LED after it's been "manually" set to one state or the other?

@kevinmehall
Copy link
Member

Also, when designing APIs that manipulate triggers, we need to to figure out whether to write to sysfs directly, or use UCI (/etc/config/system). sysfs will not persist across reboots, but the UCI LED settings are appled at boot.

@kevinmehall
Copy link
Member

I think so, yes.

@johnnyman727
Copy link
Contributor Author

👍 Will merge as is.

johnnyman727 added a commit that referenced this pull request Jul 1, 2015
Adds basic LED functionality
@johnnyman727 johnnyman727 merged commit 686dc86 into master Jul 1, 2015
return
}
else {
throw new Error("Invalid state returned by LED:" + value);
Copy link
Contributor

Choose a reason for hiding this comment

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

@johnnyman727 why throw _ instead of callback(_)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because it's not a recoverable error or one that is expected to ever happen during normal use. My hope is that if this does get hit, the user reports it so we can fix any unknown bugs.

Copy link
Contributor

Choose a reason for hiding this comment

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

In what way is it not a recoverable error? I agree that it's not something that is expected to ever happen, but that dosen't necessarily mean that throwing is the correct thing to do.

According to Joyent's "Error Handling in Nodejs" this is an operational error in an asynchronous function, and thus it should deliver the error thru the callback.

I'm sorry to be such a pain in the arse but I think it's important that best practices be followed in such a large project as this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry to be such a pain in the arse but I think it's important that best practices be followed in such a large project as this :)

No apologies necessary! Please continue to point out questionable code - it helps the project and the programmers (like myself!) improve.

In what way is it not a recoverable error?

I was on the fence about this because it seems like if you can't use an LED for visual indication as expected, you are out of luck. I suppose you can turn on another LED to indicate that something went wrong.

In any case, I think you're right that, for consistency sake, this should be provided in the callback. Thanks for looking through this! Another PR coming soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@Frijol Frijol deleted the jon-leds branch August 15, 2015 19:14
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