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

Possible issue with multiple devices using the same driver #38

Closed
peterhellberg opened this issue Nov 23, 2013 · 5 comments
Closed

Possible issue with multiple devices using the same driver #38

peterhellberg opened this issue Nov 23, 2013 · 5 comments
Labels

Comments

@peterhellberg
Copy link

Configured devices

Cylon.robot
  devices:
    [
      { name: 'green', pin: 12, driver: 'led' },
      { name: 'red', pin: 7, driver: 'led' }
    ]

Log output

Starting devices...
Starting device 'green' on pin 12
LED on pin 12 started
Starting device 'red' on pin 7
LED on pin 12 started

Problem

Only the first LED is initialized, if I reorder the lines, then the other LED is initialized instead.

@peterhellberg
Copy link
Author

Update

I wrote a (quite ugly) hack where I’m using the combined key driverName + opts.pin and it seems to be working for now. Is there a reason why each device loads the driver?

Key in Robot.prototype.requireDriver
this.robot.drivers[driverName + opts.pin]

@deadprogram
Copy link
Member

Each device is supposed to create an associated driver object of that type. However, I see some errors in how this is currently implemented. We will look into it in bit, thanks for reporting it!

@peterhellberg
Copy link
Author

Yes, it makes sense that each device has an instance of the driver. However, the driver probably shouldn’t need to be aware of the pin number, right?

Thank you for building all these frameworks, they made for a fun hackday project :)

@deadprogram
Copy link
Member

I believe the code in the https://github.com/hybridgroup/cylon/tree/correct-driver-arch branch should correct your issue, if you want to give it a try, @peterhellberg

@peterhellberg
Copy link
Author

Yes, I installed the code from the correct-driver-arch branch, and that did the trick.

This code is now doing what it should:

require('cylon').robot
  connection:
    name: 'arduino', adaptor: 'firmata', port: '/dev/cu.usbmodem1411'

  devices:
    [
      { name: 'red',   pin: 11, driver: 'led' },
      { name: 'green', pin: 10, driver: 'led' }
    ]

  work: (my) ->
    every 1.second(), -> my.red.toggle()
    every 2.second(), -> my.green.toggle()

.start()

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

No branches or pull requests

2 participants