Skip to content

Commit fa0325c

Browse files
committed
Added analytics for battery calibration.
1 parent 41d09d9 commit fa0325c

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3715,6 +3715,9 @@
37153715
"powerCalibrationManagerSourceNote": {
37163716
"message": "<span class=\"message-negative\">Warning:</span> Voltage and/or amperage meter sources <strong>have been changed but not saved.</strong> Please set the correct meter sources and save them before trying to calibrate."
37173717
},
3718+
"powerCalibrationManagerConfirmationTitle": {
3719+
"message": "Calibration Manager Confirmation"
3720+
},
37183721
"powerCalibrationSave": {
37193722
"message": "Calibrate"
37203723
},

src/js/tabs/power.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
TABS.power = {
44
supported: false,
5+
analyticsChanges: {},
56
};
67

78
TABS.power.initialize = function (callback) {
@@ -114,6 +115,14 @@ TABS.power.initialize = function (callback) {
114115
$('input[name="vbatresdivmultiplier-' + index + '"]').val(voltageDataSource[index].vbatresdivmultiplier);
115116
}
116117

118+
$('input[name="vbatscale-0"]').change(function () {
119+
let value = parseInt($(this).val());
120+
121+
if (value !== voltageDataSource[0].vbatscale) {
122+
self.analyticsChanges['PowerVBatUpdated'] = value;
123+
}
124+
});
125+
117126
// amperage meters
118127
if (BATTERY_CONFIG.currentMeterSource == 0) {
119128
$('.boxAmperageConfiguration').hide();
@@ -164,6 +173,26 @@ TABS.power.initialize = function (callback) {
164173
$('input[name="amperageoffset-' + index + '"]').val(currentDataSource[index].offset);
165174
}
166175

176+
$('input[name="amperagescale-0"]').change(function () {
177+
if (BATTERY_CONFIG.currentMeterSource === 1) {
178+
let value = parseInt($(this).val());
179+
180+
if (value !== currentDataSource[0].scale) {
181+
self.analyticsChanges['PowerAmperageUpdated'] = value;
182+
}
183+
}
184+
});
185+
186+
$('input[name="amperagescale-1"]').change(function () {
187+
if (BATTERY_CONFIG.currentMeterSource === 2) {
188+
let value = parseInt($(this).val());
189+
190+
if (value !== currentDataSource[1].scale) {
191+
self.analyticsChanges['PowerAmperageUpdated'] = value;
192+
}
193+
}
194+
});
195+
167196
if(BATTERY_CONFIG.voltageMeterSource == 1 || BATTERY_CONFIG.currentMeterSource == 1 || BATTERY_CONFIG.currentMeterSource == 2) {
168197
$('.calibration').show();
169198
} else {
@@ -324,7 +353,7 @@ TABS.power.initialize = function (callback) {
324353
closeButton: 'title',
325354
animation: false,
326355
attach: $('#calibrate'),
327-
title: 'Calibration Manager Confirmation',
356+
title: i18n.getMessage('powerCalibrationManagerConfirmationTitle'),
328357
content: $('#calibrationmanagerconfirmcontent'),
329358
onCloseComplete: function() {
330359
GUI.calibrationManager.close();
@@ -409,6 +438,14 @@ TABS.power.initialize = function (callback) {
409438
$('output[name="amperagenewscale"').val(amperagenewscale);
410439

411440
$('a.applycalibration').click(function() {
441+
if (vbatscalechanged) {
442+
self.analyticsChanges['PowerVBatUpdated'] = 'Calibrated';
443+
}
444+
445+
if (amperagescalechanged) {
446+
self.analyticsChanges['PowerAmperageUpdated'] = 'Calibrated';
447+
}
448+
412449
calibrationconfirmed = true;
413450
GUI.calibrationManagerConfirmation.close();
414451
updateDisplay(VOLTAGE_METER_CONFIGS, CURRENT_METER_CONFIGS);
@@ -440,6 +477,8 @@ TABS.power.initialize = function (callback) {
440477
BATTERY_CONFIG.vbatwarningcellvoltage = parseFloat($('input[name="warningcellvoltage"]').val());
441478
BATTERY_CONFIG.capacity = parseInt($('input[name="capacity"]').val());
442479

480+
analytics.sendChangeEvents(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, self.analyticsChanges);
481+
443482
save_power_config();
444483
});
445484

@@ -483,6 +522,8 @@ TABS.power.initialize = function (callback) {
483522
function process_html() {
484523
initDisplay();
485524

525+
self.analyticsChanges = {};
526+
486527
// translate to user-selected language
487528
i18n.localizePage();
488529

0 commit comments

Comments
 (0)