EEPROM_save_restore_DMK


Download settings and calibrations for re-upload.
/**
 * Macro for saving and re-uploading MultispeQ EEPROM values
 * by: David M. Kramer
 * created: December 24, 2018 6:50 PM
 */
 


/* NOTEs: 

The code uses the JSON object output from print_memory.output

Note that in this version, I simply pasted a few of these I
obtained from version 1.0 and 2.0 devices using "print_memory". 

It produces the console commands to set the EEPROM values to
those downloaded.

It produces two versions of the console commands: 

1) separate commands for each section of the memory;
2) A single command string for all upload commands.

Note: The code does not currently check for errors in
the downloaded values. There is a separate protocol and 
macro calles "test_settings" that does this. 

The following are no longer used and will not be re-uploaded

"mag_x_offset":0.00,
"mag_y_offset":0.00,
"mag_z_offset":0.00,
"pix_pin" Note" pix_pin is now set at the level of compile options.

"mag_orientation" is set automatically in the firmware. No need to reset.output

*/

 // 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;
}
//s=json.recall.settings; // use this 

// Notes: In the commands, the use of "s+" sets the device into 
// "silient" mode, so that user queries, asing the user for information
// is suppressed. This makes it possible to set the settings using 
// only a command followed by a string of numbers, separated by 
// "+" and sometimes ending in "-1+".

// The following is the output from a device that was only partially
// calibrated.
/*
s={
"device_id":"01:06:09:91",                  //cannot be reset
"device_version":1,                         //cannot be reset
"compiled":["Sep 20 2018","09:27:33"],      //cannot be reset
"mag_x_scale":0.00,
"mag_y_scale":0.00,
"mag_z_scale":0.00,
"mag_x_offset":0.00,
"mag_y_offset":0.00,
"mag_z_offset":0.00,
"light_slope_all":[2.261],
"light_slope_r":[-1.895],
"light_slope_g":[-1.740],
"light_slope_b":[0.447],
"light_yint":[3.606],
"thickness_a":1435429.250,
"thickness_b":-103.131,
"thickness_c":1851903.375,
"mag_orientation":481.0,                      //cannot be reset; automatically detected and set by firmware
"open_position":436.000,
"closed_position":453.000,
"spad_scale":1587.500,
"blink_mode":1146765312,
"thickness_min":36525.398,
"thickness_max":38012.801,
"shutdown_time (s)":1800,
"usb_on":1145585664,
"pix_pin":1158713344,
"par_to_dac_slope1": [0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000],
"par_to_dac_slope2": [0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00],
"par_to_dac_slope3": [0.00,56200.00,-1900.00,333300.00,-4400.00,-53.05,-223.84,-11300.00,-292.89,-15805.74],
"par_method":0,
"par_tweek":38.738}; 
*/

//The following is from a PARTIALLY CALIBRATED V2.0 device
/*
s = {"device_id":"32:21:3c:ee","device_version":2,"compiled":["Jan  1 2019","19:41:42"],"device_mod":4294967295,"mag_x_scale":1864.00,
"mag_y_scale":-1586.00,
"mag_z_scale":-1277.00,
"light_slope_all":[-0.769],"light_slope_r":[-0.860],"light_slope_g":[0.439],"light_slope_b":[-9999.000],"light_yint":[0.807],"thickness_a":-1.430,
"thickness_b":40191.555,
"thickness_c":55597.398,
"mag_orientation":255.0,
"open_position":42573.000,
"closed_position":-1.000,
"spad_scale":0.000,
"blink_mode":7,
"thickness_min":37977.199,
"thickness_max":19570.154,
"shutdown_time (s)":4294967,
"usb_on":1800000,
"pix_pin":14,
"par_to_dac_slope1": [1.000,2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000],
"par_to_dac_slope2": [11.00,12.00,13.00,14.00,15.00,16.00,17.00,18.00,19.00,20.00],
"par_to_dac_slope3": [21.00,22.00,23.00,24.00,25.00,26.00,27.00,28.00,29.00,30.00],
"par_method":255,
"detector_offsets":[0,0,0,0],
"par_tweek":1.000};
*/

//The following is from a CALIBRATED V2.0 device

s={"device_id":"32:11:48:2d",
"device_version":2,
"compiled":["Jan  1 2019","19:41:42"],
"device_mod":1,"mag_x_scale":83.50,
"mag_y_scale":-1381.00,
"mag_z_scale":-1454.00,
"light_slope_all":[0.528],
"light_slope_r":[-0.478],
"light_slope_g":[-0.542],
"light_slope_b":[0.262],
"light_yint":[0.421],
"thickness_a":-1.652,
"thickness_b":46559.777,
"thickness_c":56402.801,
"mag_orientation":255.0,
"open_position":40494.000,
"closed_position":41148.000,
"spad_scale":0.000,
"blink_mode":7,
"thickness_min":39216.602,
"thickness_max":7637.430,
"shutdown_time (s)":600,
"usb_on":1,
"pix_pin":14,
"par_to_dac_slope1": [227980.859,1613.694,18967.578,10000.000,10000.000,5103.874,10000.000,10000.000,10000.000,0.000],
"par_to_dac_slope2": [93748.48,2603.83,10501.24,2000.00,2000.00,10715.87,2000.00,2000.00,2000.00,0.00],
"par_to_dac_slope3": [-182.78,-43.92,-234.49,-200.00,-200.00,-61.90,-200.00,-200.00,-500.00,0.00],
"par_method":102,
"detector_offsets":[0,0,0, 14681],
"par_tweek":1.000};
//output.settings=JSON.stringify(s);

output.toDevice="";

output.reset_command_1="";

if ("thickness_a" in s) {
    output.reset_command_1 += "s+set_thickness+";
    output.reset_command_1 +=(s.thickness_a + "+");
    output.reset_command_1 +=(s.thickness_b + "+");
    output.reset_command_1 +=(s.thickness_c + "+");
    output.reset_command_1 +=(s.thickness_min + "+");
    output.reset_command_1 +=(s.thickness_max + "+");
}
output.reset_command_2="";
if ("mag_x_scale" in s){
    output.reset_command_2 += "s+mag_scale+";
    output.reset_command_2 +=(s.mag_x_scale + "+");
    output.reset_command_2 +=(s.mag_y_scale + "+");
}
output.reset_command_3="";
if ("spad_scale" in s) {
    output.reset_command_3 += "s+set_spad_scale+";
    output.reset_command_3 +=(s.spad_scale + "+");
}

output.reset_command_4="";
if ("detector_offsets" in s){ // Check if the current settings contain
  								// entries for "detector_offsets"

  for (var i=0; i<s.detector_offsets.length; i++){
  output.reset_command_4 += "s+set_detector_offset+";
  output.reset_command_4 += (i+1) + "+";
  output.reset_command_4 +=(s.detector_offsets[i] + "+");

  }
}


if ("par_to_dac_slope4" in s) {  // if the device sent par_to_dac_slope4,
  								 // it is using the old method for calibration
  								 // we will send these back using the "set_led_par"
  								// command.
  
 	var numLEDs=10;
	output.reset_command_5 += "s+set_par_to_dac_calibration+";
	//par_to_dac_slope1[led-1]
    for (var i=0; i<numLEDs; i++){
      output.reset_command_5 += (i+1)+ "+" + s.par_to_dac_slope1[i] + "+";
      output.reset_command_5 += s.par_to_dac_slope2[i] + "+";
      output.reset_command_5 += s.par_to_dac_slope3[i] + "+";        
      output.reset_command_5 += s.par_to_dac_slope4[i] + "+";        
	  output.reset_command_5 += s.yint[i] + "+";        

      //
      
    }
  output.reset_command_5 += "-1+";
 
} else {  // if par_to_dac_slope4 was not sent, it is a newer version using our new method

    output.reset_command_5="";
    if ("par_to_dac_slope1" in s) {
        var numLEDs=10;
        output.reset_command_5 += "s+set_par_to_dac_calibration+";
        //par_to_dac_slope1[led-1]
        for (var i=0; i<numLEDs; i++){
          output.reset_command_5 += (i+1) + "+";
          output.reset_command_5 += s.par_to_dac_slope1[i] + "+";
          output.reset_command_5 += s.par_to_dac_slope2[i] + "+";
          output.reset_command_5 += s.par_to_dac_slope3[i] + "+";        

          //par_to_dac_slope4

        }
	    output.reset_command_5 += "-1+";

}
}
output.reset_command_6="";
if ("light_slope_all" in s) {  // if there exists light_slope_all then 
  								// there are PAR sensor values to upload
	output.reset_command_6 += "s+set_par" + "+";
  	output.reset_command_6 += s.light_slope_all + "+";
  	output.reset_command_6 += s.light_slope_r + "+";
  	output.reset_command_6 += s.light_slope_g + "+";
  	output.reset_command_6 += s.light_slope_b + "+";
  	output.reset_command_6 += s.light_yint + "+";
}

output.reset_command_7="";
if ("thickness_a" in s) {
   output.reset_command_7 += "s+set_thickness" + "+";
   output.reset_command_7 += s.thickness_a + "+";
   output.reset_command_7 += s.thickness_b + "+";
   output.reset_command_7 += s.thickness_c + "+";
   output.reset_command_7 += s.thickness_min + "+";
   output.reset_command_7 += s.thickness_max + "+";
  
}

output.reset_command_8="";
if ("open_position" in s) {
 	output.reset_command_8 += "s+setocbr" + "+";  // NOTE: this is a new command that sets the open closed positions directy
   	output.reset_command_8 += s.open_position + "+";
   	output.reset_command_8 += s.closed_position + "+";
}

output.reset_command_9="";
if ("blink_mode" in s) {
	output.reset_command_9 += "s+set_blink_mode+" + s.blink_mode + "+";  
}

output.reset_command_10="";
if ("usb_on" in s) {
  output.reset_command_10 += "s+usb_on+" + s.usb_on + "+";
}

output.reset_command_11="";
if ("par_tweek" in s) {
 	output.reset_command_11 += "s+par_tweek+" + s.par_tweek + "+"; 
}

if ("par_method" in s) {
 	output.reset_command_11 += "s+par_method+" + s.par_method + "+"; 
}
output.reset_command_12="";
if ("device_mod" in s) {
 	output.reset_command_12 += "s+device_mod+" + s.device_mod + "+"; 
}

output.toDevice+= output.reset_command_1;
output.toDevice+= output.reset_command_2;
output.toDevice+= output.reset_command_3;
output.toDevice+= output.reset_command_4;
output.toDevice+= output.reset_command_5;
output.toDevice+= output.reset_command_6;
output.toDevice+= output.reset_command_7;
output.toDevice+= output.reset_command_8;
output.toDevice+= output.reset_command_9;
output.toDevice+= output.reset_command_10;
output.toDevice+= output.reset_command_11;
output.toDevice+= output.reset_command_12;

return output;



/* NOTE: the following are no longer used and will not be re-uploaded

"mag_x_offset":0.00,
"mag_y_offset":0.00,
"mag_z_offset":0.00,
"pix_pin" Note" pix_pin is now set at the level of compile options.

"mag_orientation" is set automatically in the firmware. No need to reset.output

*/
{
  "time": 1545792855098,
  "device_name": "MultispeQ",
  "device_version": "2",
  "device_id": "32:21:3c:e9",
  "device_battery": 106,
  "device_firmware": 2.0056,
  "sample": [
    [
      {
        "time": 1545792855116,
        "protocol_id": 1,
        "recall": {
          "time": 1545792855116,
          "settings": {
            "time": 1545792855116,
            "device_id": "32:21:3c:e9",
            "device_version": 2,
            "compiled": [
              "Dec 26 2018",
              "11:43:27"
            ],
            "device_mod": 4294967295,
            "mag_x_scale": -9999,
            "mag_y_scale": -9999,
            "mag_z_scale": -9999,
            "light_slope_all": [
              0.499
            ],
            "light_slope_r": [
              -0.453
            ],
            "light_slope_g": [
              -0.566
            ],
            "light_slope_b": [
              0.365
            ],
            "light_yint": [
              1.635
            ],
            "thickness_a": 13924.67,
            "thickness_b": -1.516,
            "thickness_c": 41221.461,
            "mag_orientation": 255,
            "open_position": 39879,
            "closed_position": 41820,
            "spad_scale": 1,
            "blink_mode": 7,
            "thickness_min": 52102.199,
            "thickness_max": 36746.199,
            "shutdown_time (s)": 600,
            "usb_on": 0,
            "pix_pin": 14,
            "par_to_dac_slope1": [
              8834.318,
              203029.953,
              2504.805,
              16723.625,
              10000,
              10000,
              561875.125,
              10000,
              10000,
              10000
            ],
            "par_to_dac_slope2": [
              3848.96,
              61157.99,
              2616.52,
              7247.14,
              2000,
              2000,
              337086.56,
              2000,
              2000,
              2000
            ],
            "par_to_dac_slope3": [
              -139.2,
              -226.44,
              -59.06,
              -253.58,
              -200,
              -200,
              -136.84,
              -200,
              -200,
              -500
            ],
            "par_method": 1,
            "detector_offsets": [
              71,
              0,
              9,
              0
            ],
            "par_tweek": 1
          }
        },
        "data_raw": [

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

David M. Kramer


Protocol connections:
0
Latest Update:
Jan 2019