Skip to content

Instantly share code, notes, and snippets.

@Shadow6363
Created February 20, 2013 00:21
Show Gist options
  • Save Shadow6363/4991578 to your computer and use it in GitHub Desktop.
Save Shadow6363/4991578 to your computer and use it in GitHub Desktop.
/*
var eepromConfigDefinition = {
eepromConfigDefinition: {
version: 'uint8',
calibrateESC: 'uint8',
ACCEL_BIAS: ['array', 'int16', 3],
PID_YAW_c: ['array', 'float32', 4],
PID_PITCH_c: ['array', 'float32', 4],
PID_ROLL_c: ['array', 'float32', 4],
PID_YAW_m: ['array', 'float32', 4],
PID_PITCH_m: ['array', 'float32', 4],
PID_ROLL_m: ['array', 'float32', 4],
PID_BARO: ['array', 'float32', 4],
PID_SONAR: ['array', 'float32', 4],
PID_GPS: ['array', 'float32', 4]
}
};
*/
var eepromConfig = {
version: 0,
calibrateESC: 0,
ACCEL_BIAS: [0, 0, 0],
PID_YAW_c: [0.0, 0.0, 0.0, 0],
PID_PITCH_c: [0.0, 0.0, 0.0, 0],
PID_ROLL_c: [0.0, 0.0, 0.0, 0],
PID_YAW_m: [0.0, 0.0, 0.0, 0],
PID_PITCH_m: [0.0, 0.0, 0.0, 0],
PID_ROLL_m: [0.0, 0.0, 0.0, 0],
PID_BARO: [0.0, 0.0, 0.0, 0],
PID_SONAR: [0.0, 0.0, 0.0, 0],
PID_GPS: [0.0, 0.0, 0.0, 0],
};
DataView.prototype.getString = function(str_length, byteOffset) {
var value = '';
for (var i = 0; i < str_length; ++i) {
var char = this.getUint8(byteOffset + i);
value += String.fromCharCode(char > 127 ? 65533 : char);
}
return value;
}
DataView.prototype.getChar = function(byteOffset) {
return this.getString(1, byteOffset);
}
DataView.prototype.parse = function (structure) {
var needle = 0;
structure.version = this.getUint8(needle);
structure.calibrateESC = this.getUint8(needle++);
for (var i = 0; i < structure.ACCEL_BIAS.length; i++) {
structure.ACCEL_BIAS[i] = this.getInt16(needle);
needle += 2;
}
for (var i = 0; i < structure.PID_YAW_c.length; i++) {
structure.PID_YAW_c[i] = this.getFloat32(needle);
needle += 4;
}
console.log(eepromConfig);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment