1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-17 05:15:21 +03:00

Added dropdown for current and battery meter selection to configuration tab

This commit is contained in:
Bas Delfos 2016-12-07 23:29:17 +01:00
parent 7350ff9cba
commit 591d907016
7 changed files with 345 additions and 202 deletions

View file

@ -665,6 +665,9 @@
"configurationBatteryCurrent": {
"message": "Battery Current"
},
"configurationBatteryMeterType": {
"message": "Battery Meter Type"
},
"configurationBatteryMinimum": {
"message": "Minimum Cell Voltage"
},
@ -677,6 +680,9 @@
"configurationBatteryScale": {
"message": "Voltage Scale"
},
"configurationCurrentMeterType": {
"message": "Current Meter Type"
},
"configurationCurrent": {
"message": "Current Sensor"
},

View file

@ -74,7 +74,9 @@ var FC = {
board_align_pitch: 0,
board_align_yaw: 0,
currentscale: 0,
currentoffset: 0
currentoffset: 0,
currentmetertype: 0,
batterycapacity: 0,
};
LED_STRIP = [];
@ -199,7 +201,8 @@ var FC = {
vbatscale: 0,
vbatmincellvoltage: 0,
vbatmaxcellvoltage: 0,
vbatwarningcellvoltage: 0
vbatwarningcellvoltage: 0,
batterymetertype: 1, // 1=ADC, 2=ESC
};
_3D = {

View file

@ -16,6 +16,9 @@ var MSPCodes = {
MSP_MODE_RANGES: 34,
MSP_SET_MODE_RANGE: 35,
MSP_CURRENT_METER_CONFIG: 40,
MSP_SET_CURRENT_METER_CONFIG: 41,
MSP_RX_CONFIG: 44,
MSP_SET_RX_CONFIG: 45,
MSP_LED_COLORS: 46,
@ -27,6 +30,8 @@ var MSPCodes = {
MSP_SET_ADJUSTMENT_RANGE: 53,
MSP_CF_SERIAL_CONFIG: 54,
MSP_SET_CF_SERIAL_CONFIG: 55,
MSP_VOLTAGE_METER_CONFIG: 56,
MSP_SET_VOLTAGE_METER_CONFIG: 57,
MSP_SONAR: 58,
MSP_PID_CONTROLLER: 59,
MSP_SET_PID_CONTROLLER: 60,
@ -111,13 +116,13 @@ var MSPCodes = {
MSP_SET_WP: 209, // Not used
MSP_SELECT_SETTING: 210,
MSP_SET_HEAD: 211, // Not used
MSP_SET_SERVO_CONFIGURATION:212,
MSP_SET_SERVO_CONFIGURATION: 212,
MSP_SET_MOTOR: 214,
MSP_SET_3D: 217,
MSP_SET_RC_DEADBAND: 218,
MSP_SET_RESET_CURR_PID: 219,
MSP_SET_SENSOR_ALIGNMENT: 220,
MSP_SET_LED_STRIP_MODECOLOR:221,
MSP_SET_LED_STRIP_MODECOLOR: 221,
MSP_SET_ACC_TRIM: 239,
MSP_ACC_TRIM: 240,

View file

@ -203,6 +203,21 @@ MspHelper.prototype.process_data = function(dataHandler) {
MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50
MISC.vbatwarningcellvoltage = data.readU8() / 10; // 10-50
break;
case MSPCodes.MSP_VOLTAGE_METER_CONFIG:
MISC.vbatscale = data.readU8(); // 10-200
MISC.vbatmincellvoltage = data.readU8() / 10; // 10-50
MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50
MISC.vbatwarningcellvoltage = data.readU8() / 10; // 10-50
if (semver.gte(CONFIG.apiVersion, "1.23.0")) {
MISC.batteryMeterType = data.readU8();
}
break;
case MSPCodes.MSP_CURRENT_METER_CONFIG:
BF_CONFIG.currentscale = data.readU16();
BF_CONFIG.currentoffset = data.readU16();
BF_CONFIG.currentmetertype = data.readU8();
BF_CONFIG.batterycapacity = data.readU16();
break;
case MSPCodes.MSP_3D:
_3D.deadband3d_low = data.readU16();
_3D.deadband3d_high = data.readU16();
@ -342,6 +357,11 @@ MspHelper.prototype.process_data = function(dataHandler) {
case MSPCodes.MSP_EEPROM_WRITE:
console.log('Settings Saved in EEPROM');
break;
case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
console.log('Current Settings saved');
break;
case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG:
console.log('Voltage config saved');
case MSPCodes.MSP_DEBUG:
for (var i = 0; i < 4; i++)
SENSOR_DATA.debug[i] = data.read16();
@ -1006,7 +1026,21 @@ MspHelper.prototype.crunch = function(code) {
.push8(Math.round(MISC.vbatmaxcellvoltage * 10))
.push8(Math.round(MISC.vbatwarningcellvoltage * 10));
break;
case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG:
buffer.push8(MISC.vbatscale)
.push8(Math.round(MISC.vbatmincellvoltage * 10))
.push8(Math.round(MISC.vbatmaxcellvoltage * 10))
.push8(Math.round(MISC.vbatwarningcellvoltage * 10));
if (semver.gte(CONFIG.apiVersion, "1.23.0")) {
buffer.push8(MISC.batteryMeterType);
}
break;
case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
buffer.push16(BF_CONFIG.currentscale)
.push16(BF_CONFIG.currentoffset)
.push8(BF_CONFIG.currentmetertype)
.push16(BF_CONFIG.batterycapacity)
break;
case MSPCodes.MSP_SET_RX_CONFIG:
buffer.push8(RX_CONFIG.serialrx_provider)
.push16(RX_CONFIG.maxcheck)

View file

@ -295,6 +295,20 @@
width: 30px;
}
.tab-configuration .batterymetertype {
border: 1px solid silver;
margin-right: 5px;
float: left;
width: 150px;
}
.tab-configuration .currentmetertype {
border: 1px solid silver;
margin-right: 5px;
float: left;
width: 150px;
}
.tab-configuration .rssi td:nth-child(2) {
width: 30px;
}

View file

@ -339,6 +339,12 @@
<!-- table generated here -->
</tbody>
</table>
<div class="select">
<label>
<select class="batterymetertype"><!-- list generated here --></select>
<span i18n="configurationBatteryMeterType"></span>
</label>
</div>
<div class="number">
<label> <input type="number" name="mincellvoltage" step="0.1" min="1" max="5" /> <span
i18n="configurationBatteryMinimum"></span>
@ -383,6 +389,12 @@
<!-- table generated here -->
</tbody>
</table>
<div class="select">
<label>
<select class="currentmetertype"><!-- list generated here --></select>
<span i18n="configurationCurrentMeterType"></span>
</label>
</div>
<div class="number">
<label> <input type="number" name="currentscale" step="1" min="-16000" max="16000" /> <span
i18n="configurationCurrentScale"></span>

View file

@ -98,7 +98,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
function load_name() {
var next_callback = load_html;
var next_callback = load_battery;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
MSP.send_message(MSPCodes.MSP_NAME, false, false, next_callback);
} else {
@ -106,6 +106,24 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
}
function load_battery() {
var next_callback = load_current;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
MSP.send_message(MSPCodes.MSP_VOLTAGE_METER_CONFIG, false, false, next_callback);
} else {
next_callback();
}
}
function load_current() {
var next_callback = load_html;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
MSP.send_message(MSPCodes.MSP_CURRENT_METER_CONFIG, false, false, next_callback);
} else {
next_callback();
}
}
//Update Analog/Battery Data
function load_analog() {
@ -426,12 +444,45 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
$('input[name="mincommand"]').val(MISC.mincommand);
// fill battery
var batteryMeterTypes = [
'None', //Do not show in GUI
'Onboard ADC',
'ESC Sensor',
];
var batteryMeterType_e = $('select.batterymetertype');
for (i = 1; i < batteryMeterTypes.length; i++) {
batteryMeterType_e.append('<option value="' + i + '">' + batteryMeterTypes[i] + '</option>');
}
batteryMeterType_e.change(function () {
MISC.batterymetertype = parseInt($(this).val());
});
batteryMeterType_e.val(MISC.batterymetertype);
$('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage);
$('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage);
$('input[name="warningcellvoltage"]').val(MISC.vbatwarningcellvoltage);
$('input[name="voltagescale"]').val(MISC.vbatscale);
// fill current
var currentMeterTypes = [
'None', //Do not show in GUI
'Onboard ADC',
'Virtual',
'ESC Sensor',
];
var currentMeterType_e = $('select.currentmetertype');
for (i = 1; i < currentMeterTypes.length; i++) {
currentMeterType_e.append('<option value="' + i + '">' + currentMeterTypes[i] + '</option>');
}
currentMeterType_e.change(function () {
BF_CONFIG.currentmetertype = parseInt($(this).val());
});
currentMeterType_e.val(BF_CONFIG.currentmetertype);
$('input[name="currentscale"]').val(BF_CONFIG.currentscale);
$('input[name="currentoffset"]').val(BF_CONFIG.currentoffset);
$('input[name="multiwiicurrentoutput"]').prop('checked', MISC.multiwiicurrentoutput !== 0);
@ -621,7 +672,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
function save_name() {
var next_callback = save_to_eeprom;
var next_callback = save_battery;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {
CONFIG.name = $.trim($('input[name="vesselName"]').val());
@ -631,6 +682,24 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
}
function save_battery() {
var next_callback = save_current;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
MSP.send_message(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG), false, next_callback);
} else {
next_callback();
}
}
function save_current() {
var next_callback = save_to_eeprom;
if (CONFIG.flightControllerIdentifier == "BTFL" && semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, next_callback);
} else {
next_callback();
}
}
function save_to_eeprom() {
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, reboot);
}