1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-18 22:05:13 +03:00

Finishing Power & Battery tab

This commit is contained in:
Bas Delfos 2017-07-15 08:26:15 +02:00
parent 667c4d5af3
commit 3ee2884d62
5 changed files with 219 additions and 125 deletions

View file

@ -2007,7 +2007,7 @@
"message": "Warning Cell Voltage" "message": "Warning Cell Voltage"
}, },
"powerVoltageHead": { "powerVoltageHead": {
"message": "Voltage" "message": "Voltage Meter"
}, },
"powerVoltageValue": { "powerVoltageValue": {
"message": "$1 V" "message": "$1 V"
@ -2016,7 +2016,7 @@
"message": "$1 A" "message": "$1 A"
}, },
"powerVoltageId10": { "powerVoltageId10": {
"message": "Battery" "message": "Onboard ADC"
}, },
"powerVoltageId20": { "powerVoltageId20": {
"message": "5V" "message": "5V"
@ -2097,10 +2097,10 @@
}, },
"powerAmperageHead": { "powerAmperageHead": {
"message": "Amperage" "message": "Amperage Meter"
}, },
"powerAmperageId10": { "powerAmperageId10": {
"message": "Battery" "message": "Onboard ADC"
}, },
"powerAmperageId50": { "powerAmperageId50": {
"message": "ESC Combined" "message": "ESC Combined"
@ -2149,15 +2149,18 @@
}, },
"powerAmperageScale": { "powerAmperageScale": {
"message": "Scale the output voltage to milliamps [1/10th mV/A]" "message": "Scale"
}, },
"powerAmperageOffset": { "powerAmperageOffset": {
"message": "Offset in millivolt steps" "message": "Offset in milliampere steps"
}, },
"powerBatteryHead": { "powerBatteryHead": {
"message": "Battery" "message": "Battery"
}, },
"powerStateHead": {
"message": "Power State"
},
"powerBatteryConnected": { "powerBatteryConnected": {
"message": "Connected" "message": "Connected"
}, },

View file

@ -1245,22 +1245,47 @@ MspHelper.prototype.crunch = function(code) {
.push8(BATTERY_CONFIG.voltageMeterSource) .push8(BATTERY_CONFIG.voltageMeterSource)
.push8(BATTERY_CONFIG.currentMeterSource); .push8(BATTERY_CONFIG.currentMeterSource);
break; break;
// FIXME - Needs updating before it can be used.
// case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG: case MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG:
// buffer.push8(MISC.vbatscale) if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
// .push8(Math.round(BATTERY_CONFIG.vbatmincellvoltage * 10)) buffer.push8(VOLTAGE_METER_CONFIGS.length)
// .push8(Math.round(BATTERY_CONFIG.vbatmaxcellvoltage * 10)) for (var i = 0; i < VOLTAGE_METER_CONFIGS.length; i++) {
// .push8(Math.round(BATTERY_CONFIG.vbatwarningcellvoltage * 10)); buffer.push8(4) // subframe length
// if (semver.gte(CONFIG.apiVersion, "1.23.0")) { .push8(VOLTAGE_METER_CONFIGS[i].id)
// buffer.push8(BATTERY_CONFIG.voltageMeterSource); .push8(VOLTAGE_METER_CONFIGS[i].vbatscale)
// } .push8(VOLTAGE_METER_CONFIGS[i].vbatresdivval)
// break; .push8(VOLTAGE_METER_CONFIGS[i].vbatresdivmultiplier);
// case MSPCodes.MSP_SET_CURRENT_METER_CONFIG: }
// buffer.push16(BF_CONFIG.currentscale) }
// .push16(BF_CONFIG.currentoffset) else {
// .push8(BATTERY_CONFIG.currentMeterSource) buffer
// .push16(BF_CONFIG.batterycapacity) .push8(MISC.vbatscale)
// break; .push8(Math.round(BATTERY_CONFIG.vbatmincellvoltage * 10))
.push8(Math.round(BATTERY_CONFIG.vbatmaxcellvoltage * 10))
.push8(Math.round(BATTERY_CONFIG.vbatwarningcellvoltage * 10));
if (semver.gte(CONFIG.apiVersion, "1.23.0")) {
buffer.push8(BATTERY_CONFIG.voltageMeterSource);
}
}
break;
case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
if (semver.gte(CONFIG.apiVersion, "1.36.0")) {
buffer.push8(CURRENT_METER_CONFIGS.length)
for (var i = 0; i < CURRENT_METER_CONFIGS.length; i++) {
buffer.push8(5) // subframe length
.push8(CURRENT_METER_CONFIGS[i].id)
.push16(CURRENT_METER_CONFIGS[i].scale)
.push16(CURRENT_METER_CONFIGS[i].offset);
}
}
else {
buffer.push16(BF_CONFIG.currentscale)
.push16(BF_CONFIG.currentoffset)
.push8(BATTERY_CONFIG.currentMeterSource)
.push16(BF_CONFIG.batterycapacity)
}
break;
case MSPCodes.MSP_SET_RX_CONFIG: case MSPCodes.MSP_SET_RX_CONFIG:
buffer.push8(RX_CONFIG.serialrx_provider) buffer.push8(RX_CONFIG.serialrx_provider)
.push16(RX_CONFIG.stick_max) .push16(RX_CONFIG.stick_max)

View file

@ -2,11 +2,20 @@
display: none; display: none;
} }
.tab-power .leftWrapper {
float: left;
width:calc(50% - 20px)
}
.tab-power .rightWrapper {
float: left;
width: calc(50% - 0px);
margin: 0 0 10px 20px;
}
.tab-power td.configuration { .tab-power td.configuration {
padding-top: 5px; padding-top: 5px;
text-align: left; text-align: left;
width: 50%;
padding-left: 20px;
} }
.tab-power .battery-state .configuration { .tab-power .battery-state .configuration {
@ -18,6 +27,10 @@
width: 20%; width: 20%;
} }
.tab-power .label {
width: 25%;
}
.tab-power .number input { .tab-power .number input {
width: 50px; width: 50px;
padding-left: 3px; padding-left: 3px;
@ -32,11 +45,7 @@
} }
.tab-power .spacer_box {
padding-bottom: 10px;
float: left;
width: calc(100% - 20px);
}
.tab-power .number, .tab-power .number,
.tab-power .select .tab-power .select

View file

@ -1,5 +1,5 @@
<div class="tab-power toolbar_fixed_bottom"> <div class="tab-power toolbar_fixed_bottom">
<div class="content_wrapper initialstyle"> <div class="content_wrapper">
<!-- should be the first DIV on each tab --> <!-- should be the first DIV on each tab -->
<div class="cf_column spacerbottom"> <div class="cf_column spacerbottom">
<div class="tab_title" i18n="tabPower">Power</div> <div class="tab_title" i18n="tabPower">Power</div>
@ -7,19 +7,46 @@
<a id="button-documentation" href="" target="_blank"></a> <a id="button-documentation" href="" target="_blank"></a>
</div> </div>
</div> </div>
<div class="require-support">
<table style="width:100%">
<tr>
<td>
<div class="leftWrapper">
<div class="gui_box grey"> <div class="gui_box grey">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="powerBatteryHead"></div> <div class="spacer_box_title" i18n="powerBatteryHead"></div>
</div> </div>
<div class="spacer_box battery"> <div class="spacer_box battery">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="cf_table"> <table border="0" cellpadding="0" cellspacing="0" class="cf_table">
<tbody class="battery-config">
<td class="configuration" rowspan="4"></td>
</tbody>
</table>
</div>
</div>
</div>
<div class="rightWrapper">
<div class="gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="powerStateHead"></div>
</div>
<div class="spacer_box battery">
<table border="0" cellpadding="0" cellspacing="0" class="cf_table">
<tbody class="battery-state"> <tbody class="battery-state">
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
<div class="gui_box grey"> </div>
</td>
</tr>
</table>
<table style="width:100%">
<tr>
<td>
<div class="leftWrapper">
<div class="gui_box grey boxVoltageConfiguration">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="powerVoltageHead"></div> <div class="spacer_box_title" i18n="powerVoltageHead"></div>
</div> </div>
@ -30,7 +57,17 @@
</table> </table>
</div> </div>
</div> </div>
<div class="gui_box grey"> </div>
</td>
</tr>
</table>
<table style="width:100%">
<tr>
<td>
<div class="leftWrapper">
<div class="gui_box grey boxAmperageConfiguration">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title" i18n="powerAmperageHead"></div> <div class="spacer_box_title" i18n="powerAmperageHead"></div>
</div> </div>
@ -42,12 +79,18 @@
</div> </div>
</div> </div>
</div> </div>
</td>
</tr>
</table>
<div class="note require-upgrade"> <div class="note require-upgrade">
<div class="note_spacer"> <div class="note_spacer">
<p i18n="powerFirmwareUpgradeRequired"></p> <p i18n="powerFirmwareUpgradeRequired"></p>
</div> </div>
</div> </div>
</div> </div>
<div class="content_toolbar"> <div class="content_toolbar">
<div class="btn save_btn"> <div class="btn save_btn">
<a class="save" href="#" i18n="powerButtonSave"></a> <a class="save" href="#" i18n="powerButtonSave"></a>
@ -76,12 +119,11 @@
</tbody> </tbody>
</table> </table>
<table class="battery-states"> <table class="battery-state">
<tbody class="battery-state"> <tbody class="battery-state">
<tr class="connection-state"> <tr class="connection-state">
<td i18n="powerBatteryConnected"></td> <td i18n="powerBatteryConnected"></td>
<td class="value">?</td> <td class="value">?</td>
<td class="configuration" rowspan="4"></td>
</tr> </tr>
<tr class="voltage"> <tr class="voltage">
<td i18n="powerBatteryVoltage"></td> <td i18n="powerBatteryVoltage"></td>

View file

@ -65,6 +65,9 @@ TABS.power.initialize = function (callback) {
var template = $('#tab-power-templates .voltage-meters .voltage-meter'); var template = $('#tab-power-templates .voltage-meters .voltage-meter');
var destination = $('.tab-power .voltage-meters'); var destination = $('.tab-power .voltage-meters');
if (BATTERY_CONFIG.voltageMeterSource == 0)
$('.boxVoltageConfiguration').hide();
for (var index = 0; index < VOLTAGE_METERS.length; index++) { for (var index = 0; index < VOLTAGE_METERS.length; index++) {
var meterElement = template.clone(); var meterElement = template.clone();
$(meterElement).attr('id', 'voltage-meter-' + index); $(meterElement).attr('id', 'voltage-meter-' + index);
@ -72,6 +75,12 @@ TABS.power.initialize = function (callback) {
var message = chrome.i18n.getMessage('powerVoltageId' + VOLTAGE_METERS[index].id); var message = chrome.i18n.getMessage('powerVoltageId' + VOLTAGE_METERS[index].id);
$(meterElement).find('.label').text(message) $(meterElement).find('.label').text(message)
destination.append(meterElement); destination.append(meterElement);
meterElement.hide();
if ((BATTERY_CONFIG.voltageMeterSource == 1 && VOLTAGE_METERS[index].id == 10) // TODO: replace hardcoded constants
|| (BATTERY_CONFIG.voltageMeterSource == 2 && VOLTAGE_METERS[index].id >= 50)) {
meterElement.show();
}
} }
var template = $('#tab-power-templates .voltage-configuration'); var template = $('#tab-power-templates .voltage-configuration');
@ -85,9 +94,9 @@ TABS.power.initialize = function (callback) {
} }
destination.append(element); destination.append(element);
$('input[name="vbatscale-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatscale).attr('disabled','disabled'); $('input[name="vbatscale-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatscale);
$('input[name="vbatresdivval-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivval).attr('disabled','disabled'); $('input[name="vbatresdivval-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivval);
$('input[name="vbatresdivmultiplier-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivmultiplier).attr('disabled','disabled'); $('input[name="vbatresdivmultiplier-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivmultiplier);
} }
// amperage meters // amperage meters
@ -95,6 +104,9 @@ TABS.power.initialize = function (callback) {
var template = $('#tab-power-templates .amperage-meters .amperage-meter'); var template = $('#tab-power-templates .amperage-meters .amperage-meter');
var destination = $('.tab-power .amperage-meters'); var destination = $('.tab-power .amperage-meters');
if (BATTERY_CONFIG.currentMeterSource == 0)
$('.boxAmperageConfiguration').hide();
for (var index = 0; index < CURRENT_METERS.length; index++) { for (var index = 0; index < CURRENT_METERS.length; index++) {
var meterElement = template.clone(); var meterElement = template.clone();
$(meterElement).attr('id', 'amperage-meter-' + index); $(meterElement).attr('id', 'amperage-meter-' + index);
@ -102,6 +114,13 @@ TABS.power.initialize = function (callback) {
var message = chrome.i18n.getMessage('powerAmperageId' + CURRENT_METERS[index].id); var message = chrome.i18n.getMessage('powerAmperageId' + CURRENT_METERS[index].id);
$(meterElement).find('.label').text(message) $(meterElement).find('.label').text(message)
destination.append(meterElement); destination.append(meterElement);
meterElement.hide();
if ((BATTERY_CONFIG.currentMeterSource == 1 && CURRENT_METERS[index].id == 10) // TODO: replace constants
|| (BATTERY_CONFIG.currentMeterSource == 2 && CURRENT_METERS[index].id == 80)
|| (BATTERY_CONFIG.currentMeterSource == 3 && CURRENT_METERS[index].id >= 50 && CURRENT_METERS[index].id < 80)) {
meterElement.show();
}
} }
var template = $('#tab-power-templates .amperage-configuration'); var template = $('#tab-power-templates .amperage-configuration');
@ -115,14 +134,14 @@ TABS.power.initialize = function (callback) {
} }
destination.append(element); destination.append(element);
$('input[name="amperagescale-' + index + '"]').val(CURRENT_METER_CONFIGS[index].scale).attr('disabled','disabled'); $('input[name="amperagescale-' + index + '"]').val(CURRENT_METER_CONFIGS[index].scale);
$('input[name="amperageoffset-' + index + '"]').val(CURRENT_METER_CONFIGS[index].offset).attr('disabled','disabled'); $('input[name="amperageoffset-' + index + '"]').val(CURRENT_METER_CONFIGS[index].offset);
} }
// battery // battery
var template = $('#tab-power-templates .battery-states .battery-state'); var template = $('#tab-power-templates .battery-state .battery-state');
var destination = $('.tab-power .battery-state'); var destination = $('.tab-power .battery-state');
var element = template.clone(); var element = template.clone();
$(element).find('.connection-state').attr('id', 'battery-connection-state'); $(element).find('.connection-state').attr('id', 'battery-connection-state');
@ -221,7 +240,6 @@ TABS.power.initialize = function (callback) {
$('a.save').click(function () { $('a.save').click(function () {
/* FIXME update for api 1.33.0
for (var index = 0; index < VOLTAGE_METER_CONFIGS.length; index++) { for (var index = 0; index < VOLTAGE_METER_CONFIGS.length; index++) {
VOLTAGE_METER_CONFIGS[index].vbatscale = parseInt($('input[name="vbatscale-' + index + '"]').val()); VOLTAGE_METER_CONFIGS[index].vbatscale = parseInt($('input[name="vbatscale-' + index + '"]').val());
VOLTAGE_METER_CONFIGS[index].vbatresdivval = parseInt($('input[name="vbatresdivval-' + index + '"]').val()); VOLTAGE_METER_CONFIGS[index].vbatresdivval = parseInt($('input[name="vbatresdivval-' + index + '"]').val());
@ -232,25 +250,22 @@ TABS.power.initialize = function (callback) {
CURRENT_METER_CONFIGS[index].scale = parseInt($('input[name="amperagescale-' + index + '"]').val()); CURRENT_METER_CONFIGS[index].scale = parseInt($('input[name="amperagescale-' + index + '"]').val());
CURRENT_METER_CONFIGS[index].offset = parseInt($('input[name="amperageoffset-' + index + '"]').val()); CURRENT_METER_CONFIGS[index].offset = parseInt($('input[name="amperageoffset-' + index + '"]').val());
} }
*/
BATTERY_CONFIG.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()); BATTERY_CONFIG.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val());
BATTERY_CONFIG.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()); BATTERY_CONFIG.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val());
BATTERY_CONFIG.vbatwarningcellvoltage = parseFloat($('input[name="warningcellvoltage"]').val()); BATTERY_CONFIG.vbatwarningcellvoltage = parseFloat($('input[name="warningcellvoltage"]').val());
BATTERY_CONFIG.capacity = parseInt($('input[name="capacity"]').val()); BATTERY_CONFIG.capacity = parseInt($('input[name="capacity"]').val());
/* FIXME update for api 1.33.0 function save_battery_config() {
MSP.send_message(MSPCodes.MSP_SET_BATTERY_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BATTERY_CONFIG), false, save_voltage_config);
}
function save_voltage_config() { function save_voltage_config() {
MSP.sendVoltageMeterConfigs(save_amperage_config); MSP.send_message(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_VOLTAGE_METER_CONFIG), false, save_amperage_config);
} }
function save_amperage_config() { function save_amperage_config() {
MSP.sendAmperageMeterConfigs(save_battery_config); MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, save_to_eeprom);
}
*/
function save_battery_config() {
MSP.send_message(MSPCodes.MSP_SET_BATTERY_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BATTERY_CONFIG), false, save_to_eeprom);
} }
function save_to_eeprom() { function save_to_eeprom() {