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

How can I detect a device being connected #330

Open
coprea opened this issue Feb 9, 2016 · 5 comments
Open

How can I detect a device being connected #330

coprea opened this issue Feb 9, 2016 · 5 comments

Comments

@coprea
Copy link

coprea commented Feb 9, 2016

This is more of a question not an issue, I hope I can get some help.

As I've seen on the blog, Cylon 1.2 has the ability to register devices later. In my case the device is a Digispark. After a lot of fiddling I figured I need to start the connection and then the device, so my code now looks like:
`digisparkDevice: function() {
this.connection("digispark", { adaptor: "digispark" });
this.startConnection(this.connections.digispark, function() {});

this.device("red", {connection: "digispark", driver: "led", pin: 0});
this.startDevice(this.devices.red, function() {});
... more led devices here...

},`

Later in the work function I do:
my.digisparkDevice(); every((1).second(), function() { my.red.toggle(); });
and it works great when the Digispark is connected. If not connected, I get a Segmentation fault. I tried toggle() in a try/catch but still the same error. I looked at the device object and didn't notice any difference between Digispark connected and not (I was trying to find if there is something undefined that I could check for).

I want to be able to check somehow if the Digispark is connected and if not just be able to use the other devices connected to my robot. Is this possible?

I'd appreciate any help. Thank you!

@deadprogram
Copy link
Member

Hi, @coprea try doing this (from your example):

if (this.connections.digispark.connected) {
   console.log("We are connected");
}

Hope that helps!

@coprea
Copy link
Author

coprea commented Feb 11, 2016

This looks great, unfortunately .connected returns true even without the digispark connected so I run into the same issue. Thanks though, I didn't know about the .connected, maybe someday it will help.

@deadprogram
Copy link
Member

All connected currently indicates is that the connect() function was called, which apparently it was.

What is the correct behaviour in your desired case, do you think? I would imagine something not unlike the BLE scanning example, except in this case waiting for an HID to be inserted.

@coprea
Copy link
Author

coprea commented Feb 11, 2016

I am not sure what the behavior should be, I was kinda hoping there will be a isConnected() or deviceIsPresent() something that would help; unfortunately I have no idea how to check the presence of a USB device. I will look at the BLE example you mentioned though and dig on the web. Thanks!

@deadprogram
Copy link
Member

According to https://github.com/hybridgroup/cylon-digispark/blob/master/lib/digispark.js#L38 this should be returning an error when there is no digispark plugged in. However, that code is either not detecting this case, or it being ignored upstream by cylon core.

I will dig thru my pile of boards to find a Digispark to see if I can try this out myself.

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

No branches or pull requests

2 participants