From d69fcea21254d3ffc8538662df3f2fabde71bd87 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Fri, 29 Jan 2016 21:33:07 +0100 Subject: [PATCH] add some helpers --- nodejs/ar-com/arduino.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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;