Merge pull request #651 from mikeller/fix_battery_tab
Fixed box content refresh in battery tab.10.3.x-maintenance
commit
13e505ec61
|
@ -257,8 +257,8 @@ MspHelper.prototype.process_data = function(dataHandler) {
|
||||||
} else {
|
} else {
|
||||||
currentMeterConfig.id = data.readU8();
|
currentMeterConfig.id = data.readU8();
|
||||||
currentMeterConfig.sensorType = data.readU8();
|
currentMeterConfig.sensorType = data.readU8();
|
||||||
currentMeterConfig.scale = data.readU16();
|
currentMeterConfig.scale = data.read16();
|
||||||
currentMeterConfig.offset = data.readU16();
|
currentMeterConfig.offset = data.read16();
|
||||||
|
|
||||||
CURRENT_METER_CONFIGS.push(currentMeterConfig);
|
CURRENT_METER_CONFIGS.push(currentMeterConfig);
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,12 +196,12 @@
|
||||||
|
|
||||||
<div class="amperage-configuration">
|
<div class="amperage-configuration">
|
||||||
<div class="number">
|
<div class="number">
|
||||||
<label> <input type="number" name="amperagescale" step="1" min="-1000" max="1500" /> <span
|
<label> <input type="number" name="amperagescale" step="1" min="-16000" max="16000" /> <span
|
||||||
i18n="powerAmperageScale"></span>
|
i18n="powerAmperageScale"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="number">
|
<div class="number">
|
||||||
<label> <input type="number" name="amperageoffset" step="1" min="0" max="3300" /> <span
|
<label> <input type="number" name="amperageoffset" step="1" min=-16000" max="16000" /> <span
|
||||||
i18n="powerAmperageOffset"></span>
|
i18n="powerAmperageOffset"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,21 +53,29 @@ TABS.power.initialize = function (callback) {
|
||||||
load_status();
|
load_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_ui() {
|
function updateDisplay(voltageDataSource, currentDataSource) {
|
||||||
if (!TABS.power.supported) {
|
|
||||||
$(".tab-power").removeClass("supported");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$(".tab-power").addClass("supported");
|
|
||||||
|
|
||||||
// voltage meters
|
// voltage meters
|
||||||
|
|
||||||
|
if (BATTERY_CONFIG.voltageMeterSource == 0) {
|
||||||
|
$('.boxVoltageConfiguration').hide();
|
||||||
|
} else {
|
||||||
|
$('.boxVoltageConfiguration').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!voltageDataSource) {
|
||||||
|
voltageDataSource = [];
|
||||||
|
for (var index = 0; index < VOLTAGE_METER_CONFIGS.length; index++) {
|
||||||
|
voltageDataSource[index] = {
|
||||||
|
vbatscale: parseInt($('input[name="vbatscale-' + index + '"]').val()),
|
||||||
|
vbatresdivval: parseInt($('input[name="vbatresdivval-' + index + '"]').val()),
|
||||||
|
vbatresdivmultiplier: parseInt($('input[name="vbatresdivmultiplier-' + index + '"]').val())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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');
|
||||||
|
destination.empty();
|
||||||
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);
|
||||||
|
@ -94,19 +102,30 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
destination.append(element);
|
destination.append(element);
|
||||||
|
|
||||||
$('input[name="vbatscale-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatscale);
|
$('input[name="vbatscale-' + index + '"]').val(voltageDataSource[index].vbatscale);
|
||||||
$('input[name="vbatresdivval-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivval);
|
$('input[name="vbatresdivval-' + index + '"]').val(voltageDataSource[index].vbatresdivval);
|
||||||
$('input[name="vbatresdivmultiplier-' + index + '"]').val(VOLTAGE_METER_CONFIGS[index].vbatresdivmultiplier);
|
$('input[name="vbatresdivmultiplier-' + index + '"]').val(voltageDataSource[index].vbatresdivmultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// amperage meters
|
// amperage meters
|
||||||
|
if (BATTERY_CONFIG.currentMeterSource == 0) {
|
||||||
|
$('.boxAmperageConfiguration').hide();
|
||||||
|
} else {
|
||||||
|
$('.boxAmperageConfiguration').show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentDataSource) {
|
||||||
|
currentDataSource = [];
|
||||||
|
for (var index = 0; index < CURRENT_METER_CONFIGS.length; index++) {
|
||||||
|
currentDataSource[index] = {
|
||||||
|
scale: parseInt($('input[name="amperagescale-' + index + '"]').val()),
|
||||||
|
offset: parseInt($('input[name="amperageoffset-' + index + '"]').val())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
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');
|
||||||
|
destination.empty();
|
||||||
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);
|
||||||
|
@ -134,13 +153,19 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
destination.append(element);
|
destination.append(element);
|
||||||
|
|
||||||
$('input[name="amperagescale-' + index + '"]').val(CURRENT_METER_CONFIGS[index].scale);
|
$('input[name="amperagescale-' + index + '"]').val(currentDataSource[index].scale);
|
||||||
$('input[name="amperageoffset-' + index + '"]').val(CURRENT_METER_CONFIGS[index].offset);
|
$('input[name="amperageoffset-' + index + '"]').val(currentDataSource[index].offset);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDisplay() {
|
||||||
|
if (!TABS.power.supported) {
|
||||||
|
$(".tab-power").removeClass("supported");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$(".tab-power").addClass("supported");
|
||||||
|
|
||||||
// battery
|
// battery
|
||||||
|
|
||||||
var template = $('#tab-power-templates .battery-state .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();
|
||||||
|
@ -173,15 +198,11 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var batteryMeterType_e = $('select.batterymetersource');
|
var batteryMeterType_e = $('select.batterymetersource');
|
||||||
|
|
||||||
for (var i = 0; i < batteryMeterTypes.length; i++) {
|
for (var i = 0; i < batteryMeterTypes.length; i++) {
|
||||||
batteryMeterType_e.append('<option value="' + i + '">' + batteryMeterTypes[i] + '</option>');
|
batteryMeterType_e.append('<option value="' + i + '">' + batteryMeterTypes[i] + '</option>');
|
||||||
}
|
}
|
||||||
|
|
||||||
batteryMeterType_e.change(function () {
|
|
||||||
BATTERY_CONFIG.voltageMeterSource = parseInt($(this).val());
|
|
||||||
});
|
|
||||||
batteryMeterType_e.val(BATTERY_CONFIG.voltageMeterSource).change();
|
|
||||||
|
|
||||||
// fill current
|
// fill current
|
||||||
var currentMeterTypes = [
|
var currentMeterTypes = [
|
||||||
'None',
|
'None',
|
||||||
|
@ -194,16 +215,28 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentMeterType_e = $('select.currentmetersource');
|
var currentMeterType_e = $('select.currentmetersource');
|
||||||
|
|
||||||
for (var i = 0; i < currentMeterTypes.length; i++) {
|
for (var i = 0; i < currentMeterTypes.length; i++) {
|
||||||
currentMeterType_e.append('<option value="' + i + '">' + currentMeterTypes[i] + '</option>');
|
currentMeterType_e.append('<option value="' + i + '">' + currentMeterTypes[i] + '</option>');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDisplay(VOLTAGE_METER_CONFIGS, CURRENT_METER_CONFIGS);
|
||||||
|
|
||||||
|
var batteryMeterType_e = $('select.batterymetersource');
|
||||||
|
batteryMeterType_e.val(BATTERY_CONFIG.voltageMeterSource);
|
||||||
|
batteryMeterType_e.change(function () {
|
||||||
|
BATTERY_CONFIG.voltageMeterSource = parseInt($(this).val());
|
||||||
|
|
||||||
|
updateDisplay();
|
||||||
|
});
|
||||||
|
|
||||||
|
var currentMeterType_e = $('select.currentmetersource');
|
||||||
|
currentMeterType_e.val(BATTERY_CONFIG.currentMeterSource);
|
||||||
currentMeterType_e.change(function () {
|
currentMeterType_e.change(function () {
|
||||||
BATTERY_CONFIG.currentMeterSource = parseInt($(this).val());
|
BATTERY_CONFIG.currentMeterSource = parseInt($(this).val());
|
||||||
|
|
||||||
|
updateDisplay();
|
||||||
});
|
});
|
||||||
currentMeterType_e.val(BATTERY_CONFIG.currentMeterSource).change();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function get_slow_data() {
|
function get_slow_data() {
|
||||||
MSP.send_message(MSPCodes.MSP_VOLTAGE_METERS, false, false, function () {
|
MSP.send_message(MSPCodes.MSP_VOLTAGE_METERS, false, false, function () {
|
||||||
|
@ -239,7 +272,6 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$('a.save').click(function () {
|
$('a.save').click(function () {
|
||||||
|
|
||||||
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());
|
||||||
|
@ -293,7 +325,7 @@ TABS.power.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_html() {
|
function process_html() {
|
||||||
update_ui();
|
initDisplay();
|
||||||
|
|
||||||
// translate to user-selected language
|
// translate to user-selected language
|
||||||
localize();
|
localize();
|
||||||
|
|
Loading…
Reference in New Issue