v1.0 CALIBRATION: visible LEDs (manual)


goes with protocol of same name
// Set our initial variables and conditions
var data = json.data_raw;
var output = {};   // location to save output variables
var lights = [1,2,3,4,7];   // define the lights to be calibrated
// set the DAC values (intensities) for each of the lights (lights 1 - 7)
var intensityArray1 = [0,0,0,20,40,60,80,100,120,140,180,500,800];
var intensityArray2 = [0,20,40,60,80,100,120,140,180,500,800,2000];
var intensityArray3 = [0,20,40,60,80,100,120,140,180,500,800];  
var intensityArray4 = [40,60,80,100,120,140,160,180,500,800,2000];
var intensityArray7 = [40,60,80,100,120,140,160,180,500,800,2000];
var intensities = [intensityArray1.length,intensityArray2.length,intensityArray3.length,intensityArray4.length,intensityArray7.length]; 

// First we get the user inputted PAR values from the LiCOR
var parValues = [];
for (var i = 0; i < json.message.length; i++) {
  parValues[i] = json.message[i][2];
}

output["parValues"] = parValues;

/*
output["length par"] = parValues.length;
output["length array"] = intensityArray1.length +intensityArray2.length +intensityArray3.length +intensityArray4.length +intensityArray7.length;
*/

// Then we need to break them apart for each light, based on the number of DAC values for each light
var parValues1 = parValues.slice(0,intensities[0]);
var parValues2 = parValues.slice(intensities[0],intensities[0]+intensities[1]);
var parValues3 = parValues.slice(intensities[0]+intensities[1],intensities[0]+intensities[1]+intensities[2]);
var parValues4 = parValues.slice(intensities[0]+intensities[1]+intensities[2],intensities[0]+intensities[1]+intensities[2]+intensities[3]);
var parValues7 = parValues.slice(intensities[0]+intensities[1]+intensities[2]+intensities[3],intensities[0]+intensities[1]+intensities[2]+intensities[3]+intensities[4]);

output["parValues"] = "";
output["parValues"] += parValues1;
output["parValues"] += ",";
output["parValues"] += parValues2;
output["parValues"] += ",";
output["parValues"] += parValues3;
output["parValues"] += ",";
output["parValues"] += parValues4;
output["parValues"] += ",";
output["parValues"] += parValues7;

output["dacValues"] = "";
output["dacValues"] += intensityArray1;
output["dacValues"] += ",";
output["dacValues"] += intensityArray2;
output["dacValues"] += ",";
output["dacValues"] += intensityArray3;
output["dacValues"] += ",";
output["dacValues"] += intensityArray4;
output["dacValues"] += ",";
output["dacValues"] += intensityArray7;

/*
output["length par1"] = parValues1.length
output["length array1"] = intensityArray1.length
output["length par2"] = parValues2.length
output["length array2"] = intensityArray2.length
output["length par3"] = parValues3.length
output["length array3"] = intensityArray3.length
output["length par4"] = parValues4.length
output["length array4"] = intensityArray4.length
output["length par7"] = parValues7.length
output["length array7"] = intensityArray7.length
*/

// Now we prepare an array for the polynomial fit in form [ [x1, y1], [x2, y2] ... ] for each light.
// Also eliminate any zero PAR values so they don't affect our fit

var modelArray1 = [];
for (var i = 0; i < parValues1.length; i++) {
  if (parValues1[i] != 0) {
    modelArray1.push([parValues1[i], intensityArray1[i]]);
  }
}
var modelArray2 = [];
for (var i = 0; i < parValues2.length; i++) {
  if (parValues2[i] != 0) {
  	modelArray2.push([parValues2[i], intensityArray2[i]]);
  }
}
var modelArray3 = [];
for (var i = 0; i < parValues3.length; i++) {
  if (parValues3[i] != 0) {
  	modelArray3.push([parValues3[i], intensityArray3[i]]);
  }
}
var modelArray4 = [];
for (var i = 0; i < parValues4.length; i++) {
  if (parValues4[i] != 0) {
    modelArray4.push([parValues4[i], intensityArray4[i]]);
  }
}
var modelArray7 = [];
for (var i = 0; i < parValues7.length; i++) {
  if (parValues7[i] != 0) {
    modelArray7.push([parValues7[i], intensityArray7[i]]);
  }
}

/*
output["modelArray1"] = modelArray1;
output["modelArray2"] = modelArray2;
output["modelArray3"] = modelArray3;
output["modelArray4"] = modelArray4;
output["modelArray7"] = modelArray7;
*/
                   
// now we need to fit the response from each LED to a polynomial fit, and output the results to the device
output["toDevice"] = "set_led_par+";

var model1 = MathPOLYREG(modelArray1,2);
output["toDevice"] += 1+"+"+MathROUND(model1.slopes[2],7)+"+"+MathROUND(model1.slopes[1],7)+"+"+MathROUND(model1.slopes[0],7)+"+";
output["light_1_a"] = MathROUND(model1.slopes[2],7);
output["light_1_b"] = MathROUND(model1.slopes[1],7);
output["light_1_yint"] = MathROUND(model1.slopes[0],7);

var model2 = MathPOLYREG(modelArray2,2);
output["toDevice"] += 2+"+"+MathROUND(model2.slopes[2],7)+"+"+MathROUND(model2.slopes[1],7)+"+"+MathROUND(model2.slopes[0],7)+"+";
output["light_2_a"] = MathROUND(model2.slopes[2],7);
output["light_2_b"] = MathROUND(model2.slopes[1],7);
output["light_2_yint"] = MathROUND(model2.slopes[0],7);

var model3 = MathPOLYREG(modelArray3,2);
output["toDevice"] += 3+"+"+MathROUND(model3.slopes[2],7)+"+"+MathROUND(model3.slopes[1],7)+"+"+MathROUND(model3.slopes[0],7)+"+";
output["light_3_a"] = MathROUND(model3.slopes[2],7);
output["light_3_b"] = MathROUND(model3.slopes[1],7);
output["light_3_yint"] = MathROUND(model3.slopes[0],7);

var model4 = MathPOLYREG(modelArray4,2);
output["toDevice"] += 4+"+"+MathROUND(model4.slopes[2],7)+"+"+MathROUND(model4.slopes[1],7)+"+"+MathROUND(model4.slopes[0],7)+"+";
output["light_4_a"] = MathROUND(model4.slopes[2],7);
output["light_4_b"] = MathROUND(model4.slopes[1],7);
output["light_4_yint"] = MathROUND(model4.slopes[0],7);

var model7 = MathPOLYREG(modelArray7,2);
output["toDevice"] += 7+"+"+MathROUND(model7.slopes[2],7)+"+"+MathROUND(model7.slopes[1],7)+"+"+MathROUND(model7.slopes[0],7)+"+";
output["light_7_a"] = MathROUND(model7.slopes[2],7);
output["light_7_b"] = MathROUND(model7.slopes[1],7);
output["light_7_yint"] = MathROUND(model7.slopes[0],7);

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

return output;
{
  "time_offset": 240,
  "time": 1477406836691,
  "device_version": "1",
  "device_id": "d4:f5:00:00:00:05",
  "device_battery": 91,
  "device_firmware": "1.10",
  "firmware_version": "1.10",
  "device_time": 1476357752,
  "sample": [
    [
      {
        "time": 1477406836716,
        "protocol_id": 1,
        "message": [
          [
            "0",
            "0",
            ""
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "9.77"
          ],
          [
            "prompt",
            "enter par",
            "87.14"
          ],
          [
            "prompt",
            "enter par",
            "169.26"
          ],
          [
            "prompt",
            "enter par",
            "247.8"
          ],
          [
            "prompt",
            "enter par",
            "323.9"
          ],
          [
            "prompt",
            "enter par",
            "400"
          ],
          [
            "prompt",
            "enter par",
            "546.7"
          ],
          [
            "prompt",
            "enter par",
            "1507"
          ],
          [
            "prompt",
            "enter par",
            "2216"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            ".04"
          ],
          [
            "prompt",
            "enter par",
            "24.16"
          ],
          [
            "prompt",
            "enter par",
            "68.74"
          ],
          [
            "prompt",
            "enter par",
            "117.14"
          ],
          [
            "prompt",
            "enter par",
            "168"
          ],
          [
            "prompt",
            "enter par",
            "274.4"
          ],
          [
            "prompt",
            "enter par",
            "1122.7"
          ],
          [
            "prompt",
            "enter par",
            "1914.8"
          ],
          [
            "prompt",
            "enter par",
            "5058"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "5.66"
          ],
          [
            "prompt",
            "enter par",
            "25.6"
          ],
          [
            "prompt",
            "enter par",
            "50.2"
          ],
          [
            "prompt",
            "enter par",
            "76.6"
          ],
          [
            "prompt",
            "enter par",
            "103.28"
          ],
          [
            "prompt",
            "enter par",
            "155.82"
          ],
          [
            "prompt",
            "enter par",
            "207.7"
          ],
          [
            "prompt",
            "enter par",
            "596"
          ],
          [
            "prompt",
            "enter par",
            "862"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "6.2"
          ],
          [
            "prompt",
            "enter par",
            "45.06"
          ],
          [
            "prompt",
            "enter par",
            "94.37"
          ],
          [
            "prompt",
            "enter par",
            "146.6"
          ],
          [
            "prompt",
            "enter par",
            "201"
          ],
          [
            "prompt",
            "enter par",
            "1138"
          ],
          [
            "prompt",
            "enter par",
            "1993"
          ],
          [
            "prompt",
            "enter par",
            "5159"
          ],
          [
            "prompt",
            "move LiCOR and enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "0"
          ],
          [
            "prompt",
            "enter par",
            "19.07"
          ],
          [
            "prompt",
            "enter par",
            "62.76"
          ],
          [
            "prompt",
            "enter par",
            "110.5"
          ],
          [
            "prompt",
            "enter par",
            "160.2"
          ],
          [
            "prompt",
            "enter par",
            "211"
          ],
          [
            "prompt",
            "enter par",
            "262.6"
          ],
          [
            "prompt",
            "enter par",
            "1108"
          ],
          [
            "prompt",
            "enter par",
            "1902"
          ],
          [
            "prompt",
            "enter par",
            "4999"
          ]
        ],
        "data_raw": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          1,
          1,
          0,
          2,
          0,
          5,
          2,
          7,
          5,
          8,
          6,
          6,
          9,
          7,
          10,
          9,
          11,
          10,
          13,
          11,
          11,
          11,
          10,
          11,
          11,
          11,
          9,
          12,
          11,
          9,
          11,
          9,
          11,
          10,
          12,
          10,
          11,
          10,
          12,
          11,
          9,
          11,
          10,
          12,
          10,
          12,
          11,
          12,
          11,
          9,
          12,
          10,
          12,
          11,
          12,
          11,
          13,
          10,
          10,
          11,
          10,
          11,
          10,
          11,
          10,
          13,
          10,
          11,
          10,
          10,
          11,
          10,
          11,
          10,
          12,
          9,
          12,
          11,
          10,
          12,
          10,
          11,
          12,
          13,
          12,
          13,
          14,
          14,
          15,
          13,
          14,
          13,
          14,
          14,
          13,
          13,
          14,
          15,
          13,
          15,
          14,
          15,
          15,
          13,
          15,
          17,
          13,
          14,
          14,
          14,
          14,
          14,
          14,
          14,
          13,
          15,
          15,
          15,
          15,
          15,
          16,
          15,
          14,
          15,
          15,
          15,
          14,
          13,
          15,
          15,
          14,
          17,
          15,
          14,
          17,
          15,
          15,
          14,
          15,
          17,
          15,
          15,
          15,
          15,
          15,
          17,
          15,
          15,
          15,
          15,
          15,
          14,
          16,
          14,
          15,
          15,
          15,
          15,
          19,
          15,
          15,
          15,
          17,
          17,
          18,
          17,
          15,
          18,
          17,
          16,
          14,
          15,
          20,
          21,
          21,
          21,
          22,
          21,
          20,
          23,
          20,
          21,
          24,
          25,
          25,
          25,
          26,
          25,
          25,
          25,
          26,
          23,
          23,
          15,
          13,
          13,
          14,
          13,
          13,
          15,
          13,
          15,
          13,
          13,
          13,
          13,
          12,
          13,
          15,
          13,
          14,
          14,
          13,
          14,
          17,
          13,
          13,
          17,
          13,
          13,
          15,
          13,
          14,
          15,
          13,
          14,
          14,
          14,
          14,
          15,
          14,
          14,
          13,
          15,
          15,
          14,
          14,
          15,
          14,
          14,
          14,
          13,
          15,
          13,
          13,
          15,
          15,
          14,
          15,
          13,
          14,
          14,
          14,
          15,
          13,
          14,
          16,
          13,
          14,
          14,
          14,
          15,
          13,
          14,
          14,
          14,
          14,
          15,
          17,
          13,
          14,
          15,
          15,
          15,
          17,
          13,
          14,
          15,
          14,
          13,
          17,
          13,
          17,
          17,
          15,
          16,
          17,
          15,
          15,
          16,
          18,
          17,
          19,
          18,
          18,
          20,
          18,
          19,
          19,
          19,
          18,
          19,
          28,
          25,
          25,
          25,
          25,
          26,
          25,
          27,
          26,
          25,
          26,
          14,
          13,
          13,
          13,
          15,
          14,
          17,
          13,
          14,
          14,
          15,
          14,
          14,
          15,
          15,
          15,
          14,
          15,
          14,
          14,
          15,
          13,
          15,
          15,
          14,
          14,
          13,
          16,
          13,
          15,
          15,
          13,
          14,
          15,
          15,
          13,
          13,
          14,
          14,
          15,
          13,
          15,
          15,
          17,
          13,
          15,
          15,
          15,
          15,
          14,
          17,
          15,
          15,
          17,
          15,
          14,
          15,
          16,
          15,
          15,
          17,
          17,
          14,
          15,
          16,
          15,
          15,
          15,
          17,
          17,
          18,
          15,
          15,
          17,
          15,
          15,
          15,
          17,
          15,
          16,
          19,
          15,
          15,
          18,
          17,
          15,
          17,
          17,
          15,
          23,
          21,
          22,
          22,
          21,
          19,
          21,
          23,
          20,
          21,
          26,
          26,
          27,
          23,
          27,
          25,
          27,
          25,
          27,
          27,
          25,
          14,
          14,
          15,
          13,
          14,
          14,
          14,
          15,
          13,
          13,
          15,
          13,
          15,
          13,
          14,
          15,
          17,
          13,
          14,
          15,
          15,
          15,
          14,
          15,
          13,
          13,
          14,
          15,
          13,
          13,
          15,
          15,
          14,
          14,
          15,
          15,
          14,
          15,
          15,
          15,
          15,
          15,
          13,
          15,
          14,
          15,
          14,
          14,
          14,
          14,
          15,
          15,
          19,
          14,
          14,
          15,
          15,
          15,
          14,
          14,
          15,
          15,
          17,
          14,
          14,
          15,
          15,
          14,
          15,
          14,
          14,
          15,
          17,
          13,
          14,
          15,
          17,
          15,
          16,
          19,
          15,
          18,
          18,
          17,
          17,
          18,
          18,
          15,
          17,
          23,
          19,
          19,
          20,
          22,
          20,
          20,
          21,
          20,
          20,
          31,
          28,
          28,
          29,
          30,
          27,
          29,
          29,
          30,
          27,
          30,
          12,
          13,
          13,
          15,
          12,
          14,
          15,
          15,
          14,
          15,
          22,
          16,
          15,
          14,
          11,
          13,
          17,
          21,
          13,
          16,
          39,
          25,
          15,
          23,
          42,
          15,
          29,
          41,
          16,
          31,
          15,
          18,
          31,
          12,
          13,
          21,
          11,
          17,
          29,
          15,
          13,
          137,
          13,
          15,
          111,
          20,
          17,
          69,
          12,
          23,
          14,
          14,
          30,
          18,
          17,
          22,
          15,
          12,
          21,
          15,
          39,
          12,
          219,
          31,
          17,
          277,
          34,
          15,
          250,
          15,
          17,
          38,
          17,
          13,
          19,
          15,
          14,
          10,
          17,
          49,
          26,
          19,
          283,
          19,
          15,
          223,
          19,
          18,
          214,
          17,
          31,
          26,
          20,
          35,
          25,
          19,
          27,
          19,
          17,
          26,
          26,
          29,
          26,
          27,
          28,
          27,
          25,
          31,
          27,
          23,
          151,
          17,
          15,
          79,
          17,
          12,
          71,
          14,
          13
        ]
      }
    ]
  ],
  "app_os": "linux",
  "app_name": "PhotosynQ",
  "app_version": "0.3.5",
  "app_device": "x86-64",
  "location": [
    "42.3080784",
    "-83.7141260"
  ],
  "ConsoleMacro": "250"
}
012409 pbi 160 low low res headshot
Created by

Greg Austic


Protocol connections:
1
Latest Update:
Oct 2016