add some helpers

This commit is contained in:
Shannon Sterz 2016-01-29 21:33:07 +01:00
parent 55238b846e
commit d69fcea212

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;