diff --git a/nodejs/ar-com/arduino.js b/nodejs/ar-com/arduino.js index 15c624d..2dfdbd5 100644 --- a/nodejs/ar-com/arduino.js +++ b/nodejs/ar-com/arduino.js @@ -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;