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

add rcServo,rcIMU,rcBMP functions #178

Merged
merged 2 commits into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"i2c": "0.2.3",
"epoll": "0.1.18",
"pi-spi": "1.0.2",
"roboticscape": "0.0.6",
"roboticscape": "0.0.8",
"ffi": "2.2.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var autorun = require('./autorun');
var server = require('./server');
var socketHandlers = require('./socket_handlers');
var ffi = require('./ffiimp');
//var rc = require('./rc');
var rc = require('./rc');
Copy link
Owner

Choose a reason for hiding this comment

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

Requires an package.json update to 0.0.8.

Copy link
Owner

Choose a reason for hiding this comment

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

Also, can we use the optional require here in case the package doesn't install nice?


var debug = process.env.DEBUG ? true : false;

Expand Down Expand Up @@ -773,9 +773,9 @@ for (var x in socketHandlers) {
for (var x in ffi) {
f[x] = ffi[x];
}
/*for(var x in rc) {
exports[x] = rc[x];
}*/
for (var x in rc) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you handle the condition that the library isn't installed nice?

f[x] = rc[x];
}


var alreadyRan = false;
Expand Down
37 changes: 35 additions & 2 deletions src/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,45 @@ if (rc.exists) {
rcOn.args = ['event', 'callback'];

var rcMotor = function (motor, value, callback) {
if (typeof motor !== 'undefined') {
if (typeof value !== 'undefined') {
rc.motor(motor, value);
} else {
rc.motor(value);
rc.motor(motor);
}
if (callback) callback();
};
rcMotor.args = ['motor', 'value', 'callback'];

var rcServo = function (option, value, callback) {
if (typeof value !== 'undefined') {
rc.servo(option, value);
} else {
rc.servo(option);
}
if (callback) callback();
};
rcServo.args = ['option', 'value', 'callback'];

var rcBMP = function (option, callback) {
var value
if (typeof option !== 'undefined') {
value = rc.bmp(option);
}
if (callback) callback(null, value);
else return value;
};
rcBMP.args = ['option', 'callback'];

var rcIMU = function (option, callback) {
var value
if (typeof option !== 'undefined') {
value = rc.imu(option);
}
if (callback) callback(null, value);
else return value;
};
rcIMU.args = ['option', 'callback'];

var rcEncoder = function (encoder, value, callback) {
var x = {};
x.encoder = encoder;
Expand All @@ -76,6 +106,9 @@ if (rc.exists) {
rcLED: rcLED,
rcOn: rcOn,
rcMotor: rcMotor,
rcServo: rcServo,
rcBMP: rcBMP,
rcIMU: rcIMU,
rcEncoder: rcEncoder
};
}