non PAR LED calibration DMK


generate nonpar led test values
/**
 * Macro for data evaluation on PhotosynQ.org
 * by: David M. Kramer
 * created: January 4, 2019 9:02 PM
 */

 // Define the output object here
var output = {};

// Check if the key time exists in json
if (json.time !== undefined){
    // Add key time and value to output
    output.time = json.time;
} 

//10000+3000+-200
var satV=15000;
var vals =[]; 
     
var tauV = [1000,2000, 3000, 4000, 6000];
var offsetV = [-100,-200,-300,-500];
  
var _par=5000;

var max_adc=50000;
output.toDevice="";

var dac_values=[];
var tau_vals=[];
var offsetV_vals=[];
for (var ii=0; ii<offsetV.length; ii++){
for (var i=0; i<tauV.length; i++){
    
	dac_values.push(-1*MathROUND(tauV[i]/(satV/(_par-offsetV[ii]) - 1),0));
    tau_vals.push(tauV[i]);
    offsetV_vals.push(offsetV[ii]); //, satV]);
}
}
output.dac_values=dac_values.join();
output.tau_vals=tau_vals.join();
output.offsetV_vals=offsetV_vals.join();
 
var leds=json.v_arrays[0];
output.leds=leds;

test_data=[]
for (var ledi=0; ledi<leds.length;ledi++){
  output["r" + leds[ledi]]=[];
  var testvals=GetProtocolByLabel( leds[ledi], json );
  test_datum=[]
  for (ledii=0;ledii<testvals.length;ledii++){
     //output["testvals" + leds[ledi] +"-"+ ledii]=testvals[ledii].data_raw[0];;
    test_datum.push(testvals[ledii].data_raw[0]);
  }
  	test_data.push(test_datum);
    output["r" + leds[ledi]]+=test_datum

  
  
    var index_to_optimum=0;
    var curr_best=0; 

    for (var i=0; i<test_datum.length; i++){
      if ((test_datum[i]<max_adc) && (test_datum[i]>curr_best)){
        curr_best=test_datum[i];
            index_to_optimum=i;
      }
    }
 
    output["index_to_optimum " + leds[ledi]]=index_to_optimum;
    output["curr_best " + leds[ledi]] = curr_best;
    opt_tau_val=tau_vals[index_to_optimum];
    output["opt_tau_val " + leds[ledi]]=tau_vals[index_to_optimum];
    opt_offsetV_val=offsetV_vals[index_to_optimum];
    output["opt_offsetV_val "+ leds[ledi]]=opt_offsetV_val;

    // Return data
    output.toDevice += "s+set_par_to_dac_calibration+";
    output.toDevice += + leds[ledi] + "+";
    output.toDevice += satV + "+";
    output.toDevice += opt_tau_val + "+";
    output.toDevice += opt_offsetV_val + "+-1+";
  
  
  
  
}

return output;
//find the settings with the ADC values that are highest, but 
//not above mac_adc
var index_to_optimum=0;
var curr_best=0;

for (var i=0; i<testvals.data_raw.length; i++){
  if ((testvals.data_raw[i]<max_adc) && (testvals.data_raw[i]>curr_best)){
	curr_best=testvals.data_raw[i];
    	index_to_optimum=i;
  }
}

output.index_to_optimum=index_to_optimum;
output.curr_best=curr_best;
opt_tau_val=tau_vals[index_to_optimum];
output.opt_tau_val=tau_vals[index_to_optimum];
opt_offsetV_val=offsetV_vals[index_to_optimum];
output.opt_offsetV_val=opt_offsetV_val;

// Return data
output.toDevice += "s+set_par_to_dac_calibration+";
output.toDevice += "10+";
output.toDevice += satV + "+";
output.toDevice += opt_tau_val + "+";
output.toDevice += opt_offsetV_val + "+-1+";
  
// set_par_to_dac_calibration+10+10000+2000+-700+-1+
return output;
{
  "time": 1546716749286,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "32:31:36:b3",
  "device_battery": 96,
  "device_firmware": 2.006,
  "sample": [
    [
      {
        "time": 1546716749286,
        "v_arrays": [
          [
            "6",
            "8",
            "9",
            "10"
          ],
          [
            "1",
            "1",
            "1",
            "1"
          ],
          [
            "-471",
            "-941",
            "-1412",
            "-1882",
            "-2353",
            "-456",
            "-913",
            "-1369",
            "-1825",
            "-2282",
            "-442",
            "-885",
            "-1327",
            "-1769",
            "-2212",
            "-429",
            "-857",
            "-1286",
            "-1714",
            "-2143",
            "-415",
            "-830",
            "-1245",
            "-1660",
            "-2075"
          ],
          [
            "5000",
            "2250",
            "2250",
            "2250"
          ]
        ],
        "set_repeats": 4,
        "protocol_id": 1,
        "set": [
          {
            "time": 1546716749286,
            "label": "6",
            "data_raw": [
              85
            ]
          },
          {
            "time": 1546716749286,
            "label": "6",
            "data_raw": [
              5861
            ]
          },
          {
            "time": 1546716749286,
            "label": "6",
            "data_raw": [
              12584
            ]
          },
          {
            "time": 1546716749286,
            "label": "6",
            "data_raw": [
              19829
            ]
          },
          {
            "time": 1546716749286,
            "label": "6",
            "data_raw": [
              27365
            ]
          },
          {
            "time": 1546716749289,
            "label": "6",
            "data_raw": [
              33
            ]
          },
          {
            "time": 1546716749296,
            "label": "6",
            "data_raw": [
              5487
            ]
          },
          {
            "time": 1546716749307,
            "label": "6",
            "data_raw": [
              11969
            ]
          },
          {
            "time": 1546716749309,
            "label": "6",
            "data_raw": [
              18945
            ]
          },
          {
            "time": 1546716749316,
            "label": "6",
            "data_raw": [
              26207
            ]
          },
          {
            "time": 1546716749323,
            "label": "6",
            "data_raw": [
              8
            ]
          },
          {
            "time": 1546716749328,
            "label": "6",
            "data_raw": [
              5122
            ]
          },
          {
            "time": 1546716749335,
            "label": "6",
            "data_raw": [
              11384
            ]
          },
          {
            "time": 1546716749341,
            "label": "6",
            "data_raw": [
              18101
            ]
          },
          {
            "time": 1546716749347,
            "label": "6",
            "data_raw": [
              25079
            ]
          },
          {
            "time": 1546716749355,
            "label": "6",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749361,
            "label": "6",
            "data_raw": [
              4755
            ]
          },
          {
            "time": 1546716749367,
            "label": "6",
            "data_raw": [
              10800
            ]
          },
          {
            "time": 1546716749375,
            "label": "6",
            "data_raw": [
              17249
            ]
          },
          {
            "time": 1546716749380,
            "label": "6",
            "data_raw": [
              23985
            ]
          },
          {
            "time": 1546716749388,
            "label": "6",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749393,
            "label": "6",
            "data_raw": [
              4386
            ]
          },
          {
            "time": 1546716749401,
            "label": "6",
            "data_raw": [
              10197
            ]
          },
          {
            "time": 1546716749407,
            "label": "6",
            "data_raw": [
              16427
            ]
          },
          {
            "time": 1546716749414,
            "label": "6",
            "data_raw": [
              22895
            ]
          },
          {
            "time": 1546716749421,
            "label": "8",
            "data_raw": [
              5
            ]
          },
          {
            "time": 1546716749426,
            "label": "8",
            "data_raw": [
              5583
            ]
          },
          {
            "time": 1546716749434,
            "label": "8",
            "data_raw": [
              12819
            ]
          },
          {
            "time": 1546716749440,
            "label": "8",
            "data_raw": [
              20457
            ]
          },
          {
            "time": 1546716749447,
            "label": "8",
            "data_raw": [
              28553
            ]
          },
          {
            "time": 1546716749453,
            "label": "8",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749460,
            "label": "8",
            "data_raw": [
              5173
            ]
          },
          {
            "time": 1546716749467,
            "label": "8",
            "data_raw": [
              12137
            ]
          },
          {
            "time": 1546716749474,
            "label": "8",
            "data_raw": [
              19515
            ]
          },
          {
            "time": 1546716749479,
            "label": "8",
            "data_raw": [
              27304
            ]
          },
          {
            "time": 1546716749486,
            "label": "8",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749492,
            "label": "8",
            "data_raw": [
              4765
            ]
          },
          {
            "time": 1546716749499,
            "label": "8",
            "data_raw": [
              11495
            ]
          },
          {
            "time": 1546716749507,
            "label": "8",
            "data_raw": [
              18606
            ]
          },
          {
            "time": 1546716749513,
            "label": "8",
            "data_raw": [
              26095
            ]
          },
          {
            "time": 1546716749519,
            "label": "8",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749526,
            "label": "8",
            "data_raw": [
              4361
            ]
          },
          {
            "time": 1546716749532,
            "label": "8",
            "data_raw": [
              10857
            ]
          },
          {
            "time": 1546716749539,
            "label": "8",
            "data_raw": [
              17713
            ]
          },
          {
            "time": 1546716749545,
            "label": "8",
            "data_raw": [
              24918
            ]
          },
          {
            "time": 1546716749552,
            "label": "8",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749558,
            "label": "8",
            "data_raw": [
              3957
            ]
          },
          {
            "time": 1546716749565,
            "label": "8",
            "data_raw": [
              10215
            ]
          },
          {
            "time": 1546716749573,
            "label": "8",
            "data_raw": [
              16855
            ]
          },
          {
            "time": 1546716749578,
            "label": "8",
            "data_raw": [
              23743
            ]
          },
          {
            "time": 1546716749585,
            "label": "9",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749592,
            "label": "9",
            "data_raw": [
              3363
            ]
          },
          {
            "time": 1546716749598,
            "label": "9",
            "data_raw": [
              7793
            ]
          },
          {
            "time": 1546716749605,
            "label": "9",
            "data_raw": [
              12563
            ]
          },
          {
            "time": 1546716749611,
            "label": "9",
            "data_raw": [
              17407
            ]
          },
          {
            "time": 1546716749618,
            "label": "9",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749625,
            "label": "9",
            "data_raw": [
              3112
            ]
          },
          {
            "time": 1546716749630,
            "label": "9",
            "data_raw": [
              7387
            ]
          },
          {
            "time": 1546716749638,
            "label": "9",
            "data_raw": [
              11961
            ]
          },
          {
            "time": 1546716749644,
            "label": "9",
            "data_raw": [
              16665
            ]
          },
          {
            "time": 1546716749650,
            "label": "9",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749658,
            "label": "9",
            "data_raw": [
              2853
            ]
          },
          {
            "time": 1546716749662,
            "label": "9",
            "data_raw": [
              7005
            ]
          },
          {
            "time": 1546716749672,
            "label": "9",
            "data_raw": [
              11392
            ]
          },
          {
            "time": 1546716749677,
            "label": "9",
            "data_raw": [
              15955
            ]
          },
          {
            "time": 1546716749683,
            "label": "9",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749690,
            "label": "9",
            "data_raw": [
              2595
            ]
          },
          {
            "time": 1546716749696,
            "label": "9",
            "data_raw": [
              6616
            ]
          },
          {
            "time": 1546716749705,
            "label": "9",
            "data_raw": [
              10830
            ]
          },
          {
            "time": 1546716749709,
            "label": "9",
            "data_raw": [
              15235
            ]
          },
          {
            "time": 1546716749715,
            "label": "9",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749722,
            "label": "9",
            "data_raw": [
              2338
            ]
          },
          {
            "time": 1546716749729,
            "label": "9",
            "data_raw": [
              6219
            ]
          },
          {
            "time": 1546716749750,
            "label": "9",
            "data_raw": [
              10305
            ]
          },
          {
            "time": 1546716749752,
            "label": "9",
            "data_raw": [
              14512
            ]
          },
          {
            "time": 1546716749752,
            "label": "10",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749755,
            "label": "10",
            "data_raw": [
              415
            ]
          },
          {
            "time": 1546716749762,
            "label": "10",
            "data_raw": [
              8489
            ]
          },
          {
            "time": 1546716749768,
            "label": "10",
            "data_raw": [
              19241
            ]
          },
          {
            "time": 1546716749775,
            "label": "10",
            "data_raw": [
              31073
            ]
          },
          {
            "time": 1546716749781,
            "label": "10",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749788,
            "label": "10",
            "data_raw": [
              226
            ]
          },
          {
            "time": 1546716749795,
            "label": "10",
            "data_raw": [
              7611
            ]
          },
          {
            "time": 1546716749801,
            "label": "10",
            "data_raw": [
              17893
            ]
          },
          {
            "time": 1546716749808,
            "label": "10",
            "data_raw": [
              29243
            ]
          },
          {
            "time": 1546716749813,
            "label": "10",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749821,
            "label": "10",
            "data_raw": [
              103
            ]
          },
          {
            "time": 1546716749827,
            "label": "10",
            "data_raw": [
              6793
            ]
          },
          {
            "time": 1546716749833,
            "label": "10",
            "data_raw": [
              16597
            ]
          },
          {
            "time": 1546716749841,
            "label": "10",
            "data_raw": [
              27473
            ]
          },
          {
            "time": 1546716749847,
            "label": "10",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749854,
            "label": "10",
            "data_raw": [
              41
            ]
          },
          {
            "time": 1546716749860,
            "label": "10",
            "data_raw": [
              5984
            ]
          },
          {
            "time": 1546716749867,
            "label": "10",
            "data_raw": [
              15304
            ]
          },
          {
            "time": 1546716749875,
            "label": "10",
            "data_raw": [
              25707
            ]
          },
          {
            "time": 1546716749880,
            "label": "10",
            "data_raw": [
              0
            ]
          },
          {
            "time": 1546716749887,
            "label": "10",
            "data_raw": [
              15
            ]
          },
          {
            "time": 1546716749893,
            "label": "10",
            "data_raw": [
              5183
            ]
          },
          {
            "time": 1546716749900,
            "label": "10",
            "data_raw": [
              14091
            ]
          },
          {
            "time": 1546716749906,
            "label": "10",
            "data_raw": [
              23932
            ]
          }
        ],
        "data_raw": [

        ]
      }
    ]
  ],
  "app_os": "macOS 17.7.0",
  "app_name": "PhotosynQ",
  "app_version": "1.1.0",
  "app_device": "x64",
  "location": false,
  "time_offset": "America/New_York"
}
Dave in cap img 4615
Created by

David M. Kramer


Protocol connections:
1
Latest Update:
Jan 2019