Closed tamer1an closed 8 years ago
Hi @tamer1an
You are correct, there is some important info missing from the "New Hardware Support" page.
When implementing a module that includes Cylon.js drivers, you need to export a drivers
function, and a driver
function.
drivers()
should return all of the drivers contained within that module, for example https://github.com/hybridgroup/cylon-i2c/blob/master/index.js#L25
driver()
should return a new Driver object for a specific driver, just like https://github.com/hybridgroup/cylon-i2c/blob/master/index.js#L27-L33
Cylon.js will try to auto-require a module named cylon-drivername
where "drivername" is the name of the driver. If it can require this specially named module, it will try to call the driver()
function to instantiate a new Driver of the desired type.
The same is also true about "Adaptors", but you were specifically asking about Drivers.
Hope this helps!
I've added an issue on the Cylon.js website to update that page: https://github.com/hybridgroup/cylon-site/issues/124
Hello @deadprogram
My driver was written correctly, before open this Issue I has investigate different examples in src-code and after your answer now I am sure that is written it correctly.
But here what was registration problem that i want to solve. Your answer above also gave me the insight so i check that driver is working just fine but.
Here is the issue: Take a look at this project structure:
as always package.json has all dep
{
"dependencies": {
"cylon": "^1.3.0",
"cylon-firmata": "^0.24.0",
"cylon-gpio": "^0.29.0",
"cylon-i2c": "^0.26.1"
}
}
e.g. I install dependencies. Than i want to install my custom driver for now all custom is in folder drivers
here is the index.js /drivers/ultrasonic/lib/ultrasonic.js and the driver
here is the actual program that i am running
so i made following steps:
1) $ npm i
2)$ npm i ./drivers/ultrasonic
3)$ node src/js/ultrasonic
4) and i get Cannot find the 'cylon-ultrasonic' module. This problem might be fixed by installing it with 'npm install cylon-ultrasonic' and trying again.
if i add my driver here: .\node_modules\cylon-i2c\lib\ultrasonic.js
and add it to the index.js file .\node_modules\cylon-i2c\index.js
var Drivers = {
// ...
"ultrasonic": require("./lib/ultrasonic")
};
I generate a driver using cylon-cli
How to register it for futher usage?
As i understand i need to instal it as npm module? i did it.
Has installed a just generated driver using
npm i ./mydriver
than i require it in my program
and i get Cannot find the 'cylon-mymodule' module. This problem might be fixed by installing it with 'npm install cylon-ultrasonic' and trying again.
cand find any instruction on that topic here: https://cylonjs.com/documentation/adding-new-hardware-support/
and irc is also silent
please help
Regards Andrii