1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 19:40:22 +03:00

Add support for MSP_SENSOR_STATUS if firmware version is gte 1.5

This commit is contained in:
Konstantin Sharlaimov (DigitalEntity) 2016-12-12 14:07:17 +10:00
parent c631b33fda
commit 2946004ccf
16 changed files with 153 additions and 63 deletions

View file

@ -41,6 +41,7 @@ var ADVANCED_CONFIG;
var INAV_PID_CONFIG;
var PID_ADVANCED;
var FILTER_CONFIG;
var SENSOR_STATUS;
var FC = {
isRatesInDps: function () {
@ -51,6 +52,18 @@ var FC = {
}
},
resetState: function() {
SENSOR_STATUS = {
isHardwareHealthy: 0,
gyroHwStatus: 0,
accHwStatus: 0,
magHwStatus: 0,
baroHwStatus: 0,
gpsHwStatus: 0,
rangeHwStatus: 0,
speedHwStatus: 0,
flowHwStatus: 0,
};
CONFIG = {
apiVersion: "0.0.0",
flightControllerIdentifier: '',

View file

@ -80,6 +80,7 @@ var MSP_codes = {
MSP_SENSOR_ALIGNMENT: 126,
MSP_LED_STRIP_MODECOLOR:127,
MSP_STATUS_EX: 150,
MSP_SENSOR_STATUS: 151,
MSP_SET_RAW_RC: 200,
MSP_SET_RAW_GPS: 201,
@ -269,6 +270,7 @@ var MSP = {
CONFIG.msp_version = data.getUint8(2);
CONFIG.capability = data.getUint32(3, 1);
break;
case MSP_codes.MSP_STATUS:
CONFIG.cycleTime = data.getUint16(0, 1);
CONFIG.i2cError = data.getUint16(2, 1);
@ -277,10 +279,15 @@ var MSP = {
CONFIG.profile = data.getUint8(10);
$('select[name="profilechange"]').val(CONFIG.profile);
sensor_status(CONFIG.activeSensors);
// Only update sensors via MSP_STATUS if earlier than 1.5
if (semver.lt(CONFIG.flightControllerVersion, "1.5.0")) {
sensor_status(CONFIG.activeSensors);
}
$('span.i2c-error').text(CONFIG.i2cError);
$('span.cycle-time').text(CONFIG.cycleTime);
break;
case MSP_codes.MSP_STATUS_EX:
CONFIG.cycleTime = data.getUint16(0, 1);
CONFIG.i2cError = data.getUint16(2, 1);
@ -289,12 +296,29 @@ var MSP = {
CONFIG.profile = data.getUint8(10);
CONFIG.cpuload = data.getUint16(11, 1);
sensor_status(CONFIG.activeSensors);
// Only update sensors via MSP_STATUS if earlier than 1.5
if (semver.lt(CONFIG.flightControllerVersion, "1.5.0")) {
sensor_status(CONFIG.activeSensors);
}
$('span.i2c-error').text(CONFIG.i2cError);
$('span.cycle-time').text(CONFIG.cycleTime);
$('span.cpu-load').text(chrome.i18n.getMessage('statusbar_cpu_load', [CONFIG.cpuload]));
break;
case MSP_codes.MSP_SENSOR_STATUS:
SENSOR_STATUS.isHardwareHealthy = data.getUint8(0);
SENSOR_STATUS.gyroHwStatus = data.getUint8(1);
SENSOR_STATUS.accHwStatus = data.getUint8(2);
SENSOR_STATUS.magHwStatus = data.getUint8(3);
SENSOR_STATUS.baroHwStatus = data.getUint8(4);
SENSOR_STATUS.gpsHwStatus = data.getUint8(5);
SENSOR_STATUS.rangeHwStatus = data.getUint8(6);
SENSOR_STATUS.speedHwStatus = data.getUint8(7);
SENSOR_STATUS.flowHwStatus = data.getUint8(8);
sensor_status_ex(SENSOR_STATUS);
break;
case MSP_codes.MSP_RAW_IMU:
// 512 for mpu6050, 256 for mma
// currently we are unable to differentiate between the sensor types, so we are goign with 512

View file

@ -305,78 +305,72 @@ function read_serial(info) {
}
}
function sensor_status(sensors_detected) {
// initialize variable (if it wasn't)
if (!sensor_status.previous_sensors_detected) {
sensor_status.previous_sensors_detected = -1; // Otherwise first iteration will not be run if sensors_detected == 0
}
function sensor_status_ex(hw_status)
{
var statusHash = sensor_status_hash(hw_status);
// update UI (if necessary)
if (sensor_status.previous_sensors_detected == sensors_detected) {
if (sensor_status_ex.previousHash == statusHash) {
return;
}
// set current value
sensor_status.previous_sensors_detected = sensors_detected;
sensor_status_ex.previousHash = statusHash;
sensor_status_update_icon('.gyro', '.gyroicon', hw_status.gyroHwStatus);
sensor_status_update_icon('.accel', '.accicon', hw_status.accHwStatus);
sensor_status_update_icon('.mag', '.magicon', hw_status.magHwStatus);
sensor_status_update_icon('.baro', '.baroicon', hw_status.baroHwStatus);
sensor_status_update_icon('.gps', '.gpsicon', hw_status.gpsHwStatus);
sensor_status_update_icon('.sonar', '.sonaricon', hw_status.rangeHwStatus);
sensor_status_update_icon('.airspeed', '.airspeedicon', hw_status.speedHwStatus);
sensor_status_update_icon('.opflow', '.opflowicon', hw_status.flowHwStatus);
}
function sensor_status_update_icon(sensId, sensIconId, status)
{
var e_sensor_status = $('#sensor-status');
if (have_sensor(sensors_detected, 'acc')) {
$('.accel', e_sensor_status).addClass('on');
$('.accicon', e_sensor_status).addClass('active');
} else {
$('.accel', e_sensor_status).removeClass('on');
$('.accicon', e_sensor_status).removeClass('active');
if (status == 0) {
$(sensId, e_sensor_status).removeClass('on');
$(sensIconId, e_sensor_status).removeClass('active');
$(sensIconId, e_sensor_status).removeClass('error');
}
if (have_sensor(sensors_detected, 'gyro')) {
$('.gyro', e_sensor_status).addClass('on');
$('.gyroicon', e_sensor_status).addClass('active');
} else {
$('.gyro', e_sensor_status).removeClass('on');
$('.gyroicon', e_sensor_status).removeClass('active');
else if (status == 1) {
$(sensId, e_sensor_status).addClass('on');
$(sensIconId, e_sensor_status).addClass('active');
$(sensIconId, e_sensor_status).removeClass('error');
}
if (have_sensor(sensors_detected, 'baro')) {
$('.baro', e_sensor_status).addClass('on');
$('.baroicon', e_sensor_status).addClass('active');
} else {
$('.baro', e_sensor_status).removeClass('on');
$('.baroicon', e_sensor_status).removeClass('active');
else {
$(sensId, e_sensor_status).removeClass('on');
$(sensIconId, e_sensor_status).removeClass('active');
$(sensIconId, e_sensor_status).addClass('error');
}
}
if (have_sensor(sensors_detected, 'mag')) {
$('.mag', e_sensor_status).addClass('on');
$('.magicon', e_sensor_status).addClass('active');
} else {
$('.mag', e_sensor_status).removeClass('on');
$('.magicon', e_sensor_status).removeClass('active');
}
function sensor_status_hash(hw_status)
{
return "S" +
hw_status.isHardwareHealthy +
hw_status.gyroHwStatus +
hw_status.accHwStatus +
hw_status.magHwStatus +
hw_status.baroHwStatus +
hw_status.gpsHwStatus +
hw_status.rangeHwStatus +
hw_status.speedHwStatus +
hw_status.flowHwStatus;
}
if (have_sensor(sensors_detected, 'gps')) {
$('.gps', e_sensor_status).addClass('on');
$('.gpsicon', e_sensor_status).addClass('active');
} else {
$('.gps', e_sensor_status).removeClass('on');
$('.gpsicon', e_sensor_status).removeClass('active');
}
if (have_sensor(sensors_detected, 'sonar')) {
$('.sonar', e_sensor_status).addClass('on');
$('.sonaricon', e_sensor_status).addClass('active');
} else {
$('.sonar', e_sensor_status).removeClass('on');
$('.sonaricon', e_sensor_status).removeClass('active');
}
if (have_sensor(sensors_detected, 'opflow')) {
$('.opflow', e_sensor_status).addClass('on');
$('.opflowicon', e_sensor_status).addClass('active');
} else {
$('.opflow', e_sensor_status).removeClass('on');
$('.opflowicon', e_sensor_status).removeClass('active');
}
function sensor_status(sensors_detected) {
SENSOR_STATUS.isHardwareHealthy = 1;
SENSOR_STATUS.gyroHwStatus = have_sensor(sensors_detected, 'gyro') ? 1 : 0;
SENSOR_STATUS.accHwStatus = have_sensor(sensors_detected, 'acc') ? 1 : 0;
SENSOR_STATUS.magHwStatus = have_sensor(sensors_detected, 'mag') ? 1 : 0;
SENSOR_STATUS.baroHwStatus = have_sensor(sensors_detected, 'baro') ? 1 : 0;
SENSOR_STATUS.gpsHwStatus = have_sensor(sensors_detected, 'gps') ? 1 : 0;
SENSOR_STATUS.rangeHwStatus = have_sensor(sensors_detected, 'sonar') ? 1 : 0;
SENSOR_STATUS.speedHwStatus = have_sensor(sensors_detected, 'airspeed') ? 1 : 0;
SENSOR_STATUS.flowHwStatus = have_sensor(sensors_detected, 'opflow') ? 1 : 0;
sensor_status_ex(SENSOR_STATUS);
}
function have_sensor(sensors_detected, sensor_code) {
@ -394,6 +388,8 @@ function have_sensor(sensors_detected, sensor_code) {
return bit_check(sensors_detected, 4);
case 'opflow':
return bit_check(sensors_detected, 5);
case 'airspeed':
return bit_check(sensors_detected, 6);
}
return false;
}

View file

@ -280,6 +280,10 @@ TABS.adjustments.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function () {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -293,6 +293,10 @@ TABS.auxiliary.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function () {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -813,6 +813,10 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.interval_add('config_load_analog', load_analog, 250, true); // 4 fps
GUI.content_ready(callback);

View file

@ -375,6 +375,10 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -114,6 +114,10 @@ TABS.gps.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);

View file

@ -147,6 +147,10 @@ TABS.modes.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -456,7 +456,16 @@ TABS.motors.initialize = function (callback) {
function get_status() {
// status needed for arming flag
MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_motor_data);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_sensor_status);
}
else {
MSP.send_message(MSP_codes.MSP_STATUS, false, false, get_motor_data);
}
}
function get_sensor_status() {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS, false, false, get_motor_data);
}
function get_motor_data() {

View file

@ -222,6 +222,10 @@ TABS.ports.initialize = function (callback, scrollPosition) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -486,6 +486,10 @@ TABS.receiver.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -446,6 +446,10 @@ TABS.sensors.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -190,6 +190,10 @@ TABS.servos.initialize = function (callback) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function () {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);

View file

@ -172,6 +172,10 @@ TABS.setup.initialize = function (callback) {
function get_slow_data() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
MSP.send_message(MSP_codes.MSP_ANALOG, false, false, function () {
bat_voltage_e.text(chrome.i18n.getMessage('initialSetupBatteryValue', [ANALOG.voltage]));
bat_mah_drawn_e.text(chrome.i18n.getMessage('initialSetupBatteryMahValue', [ANALOG.mAhdrawn]));

View file

@ -94,6 +94,10 @@ TABS.transponder.initialize = function (callback, scrollPosition) {
// status data pulled via separate timer with static speed
GUI.interval_add('status_pull', function status_pull() {
MSP.send_message(MSP_codes.MSP_STATUS);
if (semver.gte(CONFIG.flightControllerVersion, "1.5.0")) {
MSP.send_message(MSP_codes.MSP_SENSOR_STATUS);
}
}, 250, true);
GUI.content_ready(callback);