CALIBRATION: Baseline


This macro generates all values needed to send to the device to save baseline calibration information. The output object "toDevice" should be sent directly to the device.
//Define your variables here...
var data = json.data_raw;
var output = {"toDevice":"1014+"};
var lights = [15,16,20,14,15,16,20,14];
var pulses = 100;
var count = [];

//go get the values from the data json (4 lights repeated twice)
for (i = 0;i<lights.length/2;i++) {
	var low = MathMEAN(data.slice((i*pulses+10),(i*pulses+90)));
	var high = MathMEAN(data.slice(((i+lights.length/2)*pulses+10),((i+lights.length/2)*pulses+90)));
	var slope = high - low;	
	var yint = high;	

	output[lights[i]+"_low"] = low;
	output[lights[i]+"_high"] = high;
	output[lights[i]+"_difference"] = MathROUND(high-low,2);  
  
    output["toDevice"] += lights[i] + "+"; 
    output["toDevice"] += MathROUND(slope,2) + "+"; 
//    output["toDevice"] += MathROUND(low,2) + "+";
    output["toDevice"] += MathROUND(yint,2) + "+";
}

output["toDevice"] += "-1+";

//Return data
return output;
{
  "time_offset": 240,
  "time": 1405608944393,
  "device_id": 21,
  "firmware_version": "0.10",
  "sample": [
    [
      {
        "time": 1405608944393,
        "protocol_id": 1,
        "data_raw": [
          176,
          -116,
          -33,
          -69,
          -15,
          -14,
          -18,
          -21,
          -13,
          -19,
          -26,
          -39,
          31,
          -35,
          -27,
          -38,
          -21,
          -29,
          -6,
          -29,
          -34,
          -9,
          -32,
          -34,
          -78,
          -34,
          -22,
          -29,
          -25,
          -45,
          -18,
          -7,
          -38,
          -33,
          -5,
          -10,
          -4,
          -23,
          -3,
          -24,
          -52,
          -74,
          -48,
          -36,
          -18,
          -65,
          -60,
          -8,
          -21,
          4,
          -21,
          -16,
          -25,
          -29,
          -13,
          -24,
          19,
          -21,
          -1,
          -35,
          -28,
          -6,
          -13,
          9,
          -16,
          -31,
          -37,
          -35,
          -36,
          -21,
          2,
          -7,
          -17,
          -20,
          -40,
          -24,
          -12,
          -22,
          -18,
          -13,
          -22,
          -17,
          -21,
          11,
          -22,
          -35,
          -87,
          -20,
          -22,
          -19,
          -24,
          -37,
          -23,
          -59,
          21,
          -18,
          -31,
          -25,
          -27,
          -1,
          -23,
          -15,
          -1,
          -26,
          -14,
          -45,
          -43,
          -29,
          7,
          8,
          3,
          -61,
          -38,
          -8,
          -32,
          -3,
          -44,
          -28,
          -35,
          -27,
          -36,
          -26,
          -13,
          -25,
          -24,
          -45,
          -45,
          -25,
          64,
          -81,
          -20,
          -22,
          -44,
          -8,
          3,
          -54,
          -110,
          -25,
          -47,
          -11,
          -22,
          -13,
          -11,
          -29,
          -28,
          -9,
          -39,
          -37,
          -41,
          -44,
          -33,
          -41,
          -19,
          -23,
          -25,
          -40,
          0,
          -21,
          -21,
          -39,
          -29,
          -24,
          -6,
          -55,
          -30,
          -17,
          -25,
          27,
          -45,
          -6,
          -14,
          -41,
          -82,
          -23,
          -26,
          -38,
          -31,
          -33,
          -34,
          -39,
          -31,
          -6,
          -23,
          -16,
          -29,
          -25,
          -13,
          -22,
          -23,
          -24,
          -29,
          -19,
          -27,
          -28,
          -26,
          -15,
          -27,
          -13,
          -37,
          -30,
          29,
          0,
          23,
          13,
          -1,
          3,
          14,
          -4,
          15,
          4,
          18,
          27,
          22,
          27,
          -4,
          -10,
          28,
          21,
          36,
          6,
          10,
          -3,
          4,
          10,
          43,
          14,
          14,
          25,
          10,
          11,
          6,
          9,
          84,
          24,
          23,
          38,
          -19,
          -45,
          21,
          14,
          18,
          25,
          12,
          34,
          20,
          32,
          20,
          -5,
          31,
          1,
          42,
          2,
          0,
          -7,
          5,
          5,
          5,
          0,
          -9,
          24,
          13,
          11,
          -4,
          21,
          24,
          30,
          31,
          26,
          30,
          60,
          13,
          9,
          21,
          -67,
          4,
          18,
          32,
          13,
          -89,
          36,
          27,
          15,
          25,
          1,
          11,
          -7,
          19,
          7,
          2,
          18,
          2,
          39,
          4,
          -21,
          18,
          -3,
          12,
          -10,
          -1,
          13,
          570,
          572,
          554,
          573,
          558,
          564,
          594,
          599,
          588,
          570,
          579,
          573,
          568,
          600,
          583,
          575,
          578,
          616,
          582,
          569,
          574,
          586,
          590,
          587,
          585,
          573,
          589,
          582,
          578,
          550,
          575,
          577,
          554,
          591,
          596,
          578,
          580,
          581,
          594,
          588,
          578,
          561,
          562,
          582,
          573,
          552,
          591,
          587,
          556,
          578,
          588,
          599,
          590,
          579,
          570,
          578,
          580,
          567,
          568,
          595,
          578,
          606,
          584,
          504,
          586,
          591,
          605,
          575,
          606,
          593,
          542,
          589,
          599,
          610,
          608,
          578,
          575,
          565,
          602,
          585,
          593,
          588,
          582,
          597,
          594,
          598,
          615,
          613,
          585,
          582,
          586,
          568,
          582,
          579,
          577,
          594,
          586,
          595,
          548,
          602,
          114,
          151,
          110,
          115,
          33,
          104,
          103,
          92,
          104,
          111,
          124,
          136,
          106,
          110,
          89,
          124,
          130,
          152,
          109,
          120,
          92,
          118,
          119,
          95,
          119,
          106,
          115,
          112,
          94,
          135,
          84,
          109,
          118,
          94,
          29,
          101,
          126,
          114,
          57,
          92,
          111,
          122,
          100,
          85,
          137,
          124,
          106,
          103,
          96,
          88,
          47,
          127,
          112,
          113,
          104,
          109,
          98,
          103,
          94,
          121,
          116,
          94,
          115,
          33,
          43,
          103,
          98,
          107,
          122,
          114,
          134,
          118,
          113,
          94,
          127,
          78,
          116,
          82,
          87,
          128,
          123,
          135,
          103,
          115,
          139,
          117,
          133,
          109,
          122,
          111,
          141,
          92,
          128,
          126,
          98,
          157,
          87,
          97,
          99,
          102,
          810,
          850,
          915,
          862,
          796,
          842,
          838,
          864,
          868,
          882,
          870,
          869,
          864,
          860,
          858,
          853,
          879,
          799,
          850,
          840,
          857,
          890,
          867,
          882,
          885,
          892,
          845,
          869,
          872,
          858,
          847,
          887,
          848,
          881,
          869,
          850,
          861,
          876,
          863,
          879,
          868,
          884,
          857,
          861,
          881,
          874,
          838,
          855,
          864,
          879,
          880,
          873,
          864,
          883,
          860,
          856,
          869,
          840,
          879,
          862,
          859,
          860,
          797,
          890,
          866,
          877,
          850,
          844,
          875,
          813,
          858,
          857,
          861,
          842,
          879,
          851,
          856,
          861,
          869,
          800,
          888,
          826,
          875,
          879,
          870,
          835,
          844,
          866,
          874,
          871,
          880,
          815,
          866,
          869,
          823,
          866,
          876,
          866,
          862,
          869,
          128,
          109,
          107,
          124,
          100,
          126,
          108,
          104,
          93,
          115,
          104,
          100,
          123,
          110,
          134,
          134,
          106,
          120,
          119,
          92,
          97,
          111,
          108,
          50,
          106,
          109,
          134,
          127,
          122,
          142,
          87,
          116,
          95,
          102,
          121,
          107,
          107,
          100,
          88,
          102,
          63,
          106,
          115,
          96,
          108,
          121,
          101,
          120,
          99,
          127,
          102,
          100,
          68,
          86,
          98,
          101,
          88,
          86,
          137,
          112,
          112,
          92,
          118,
          121,
          98,
          103,
          108,
          85,
          113,
          120,
          101,
          95,
          120,
          110,
          118,
          87,
          89,
          114,
          82,
          117,
          105,
          88,
          102,
          146,
          105,
          118,
          25,
          114,
          102,
          107,
          110,
          107,
          97,
          52,
          97,
          109,
          101,
          90,
          100,
          108,
          4393,
          4352,
          4438,
          4448,
          4461,
          4465,
          4452,
          4441,
          4430,
          4404,
          4474,
          4439,
          4400,
          4443,
          4415,
          4416,
          4414,
          4389,
          4460,
          4441,
          4424,
          4417,
          4423,
          4440,
          4456,
          4421,
          4366,
          4400,
          4452,
          4370,
          4458,
          4432,
          4425,
          4432,
          4429,
          4429,
          4450,
          4418,
          4388,
          4493,
          4462,
          4416,
          4388,
          4429,
          4390,
          4381,
          4437,
          4430,
          4427,
          4420,
          4362,
          4388,
          4418,
          4437,
          4400,
          4431,
          4445,
          4349,
          4458,
          4438,
          4367,
          4443,
          4389,
          4383,
          4399,
          4424,
          4478,
          4456,
          4424,
          4424,
          4397,
          4418,
          4472,
          4416,
          4440,
          4406,
          4373,
          4411,
          4416,
          4467,
          4425,
          4423,
          4389,
          4375,
          4406,
          4413,
          4398,
          4346,
          4464,
          4341,
          4485,
          4429,
          4393,
          4457,
          4404,
          4417,
          4415,
          4469,
          4467,
          4442
        ]
      }
    ]
  ]
}
012409 pbi 160 low low res headshot
Created by

Greg Austic


Protocol connections:
1
Latest Update:
Jun 2016