add some helpers

This commit is contained in:
Stefan Sterz 2016-01-29 21:33:07 +01:00
parent 55238b846e
commit d69fcea212
1 changed files with 28 additions and 0 deletions

View File

@ -67,4 +67,32 @@ Arduino.prototype.processWriteBuffer = function () {
}
}
// Helpers
Arduino.prototype.valueToLastFour = function(val) {
var encodedVal;
for (var i = 3; i < 0; i--) {
encodedVal += String.fromCharCode(val/(Math.pow(2,8*i)));
val = val%Math.pow(2,8*i);
}
return encodedVal;
};
Arduino.prototype.valueToFirstTwo = function(val) {
var encodedVal;
for (var i = 1; i < 0; i--) {
encodedVal += String.fromCharCode(val/(Math.pow(2,8*i)));
val = val%Math.pow(2,8*i);
}
return encodedVal;
};
module.exports = Arduino;