Skip to content

Commit 93e4cf8

Browse files
authored
Added dialog to offer resetting to custom defaults. (#1651)
Added dialog to offer resetting to custom defaults.
2 parents dde266a + 6999656 commit 93e4cf8

File tree

7 files changed

+82
-10
lines changed

7 files changed

+82
-10
lines changed

locales/en/messages.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"close": {
5757
"message": "Close"
5858
},
59+
"cancel": {
60+
"message": "Cancel"
61+
},
5962
"autoConnectEnabled": {
6063
"message": "Auto-Connect: Enabled - Configurator automatically tries to connect when new port is detected"
6164
},
@@ -467,6 +470,12 @@
467470
"firmwareUpgradeRequired": {
468471
"message": "The firmware on this device needs upgrading to a newer version. Use CLI for backup before flashing. CLI backup/restore procedure is in the documention.<br />Alternatively download and use an old version of the configurator if you are not ready to upgrade."
469472
},
473+
"resetToCustomDefaultsDialog": {
474+
"message": "There are custom defaults for this board available. Normally, a board will not work properly unless custom defaults are applied.<br />Do you want to apply the custom defaults for this board?"
475+
},
476+
"resetToCustomDefaultsAccept": {
477+
"message": "Apply Custom Defaults"
478+
},
470479

471480
"infoVersions": {
472481
"message" : "Running - OS: <strong>{{operatingSystem}}</strong>, Chrome: <strong>{{chromeVersion}}</strong>, Configurator: <strong>{{configuratorVersion}}</strong>",

src/css/main.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,3 +2113,8 @@ input {
21132113
height: 9px;
21142114
border:1px solid var(--accent);
21152115
}
2116+
2117+
#dialogResetToCustomDefaults-content {
2118+
margin-top: 10px;
2119+
margin-bottom: 10px;
2120+
}

src/js/fc.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ var FC = {
9595
runawayTakeoffPreventionDisabled: false,
9696
boardIdentifier: "",
9797
boardVersion: 0,
98-
commCapabilities: 0,
98+
targetCapabilities: 0,
9999
targetName: "",
100100
boardName: "",
101101
manufacturerId: "",
102102
signature: [],
103103
mcuTypeId: 255,
104+
configurationState: 0,
104105
};
105106

106107
BF_CONFIG = {
@@ -607,15 +608,25 @@ var FC = {
607608
return FC.MCU_TYPES[CONFIG.mcuTypeId];
608609
},
609610

610-
COMM_CAPABILITIES_FLAGS: {
611-
HAS_VCP: 0x01,
612-
HAS_SOFTSERIAL: 0x02,
611+
CONFIGURATION_STATES: {
612+
DEFAULTS_BARE: 0,
613+
DEFAULTS_CUSTOM: 1,
614+
CONFIGURED: 2,
615+
},
616+
617+
TARGET_CAPABILITIES_FLAGS: {
618+
HAS_VCP: 0,
619+
HAS_SOFTSERIAL: 1,
620+
IS_UNIFIED: 2,
621+
HAS_FLASH_BOOTLOADER: 3,
622+
SUPPORTS_CUSTOM_DEFAULTS: 4,
623+
HAS_CUSTOM_DEFAULTS: 5,
613624
},
614625

615626
boardHasVcp: function () {
616627
var hasVcp = false;
617628
if (semver.gte(CONFIG.apiVersion, "1.37.0")) {
618-
hasVcp = (CONFIG.commCapabilities & FC.COMM_CAPABILITIES_FLAGS.HAS_VCP) !== 0;
629+
hasVcp = bit_check(CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_VCP);
619630
} else {
620631
hasVcp = BOARD.find_board_definition(CONFIG.boardIdentifier).vcp;
621632
}

src/js/msp/MSPHelper.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ function MspHelper () {
3434
MSC_UTC: 3
3535
};
3636

37+
self.RESET_TYPES = {
38+
BASE_DEFAULTS: 0,
39+
CUSTOM_DEFAULTS: 1,
40+
};
41+
3742
self.SIGNATURE_LENGTH = 32;
3843

3944
self.mspMultipleCache = [];
@@ -751,14 +756,14 @@ MspHelper.prototype.process_data = function(dataHandler) {
751756

752757
CONFIG.targetName = "";
753758
if (semver.gte(CONFIG.apiVersion, "1.37.0")) {
754-
CONFIG.commCapabilities = data.readU8();
759+
CONFIG.targetCapabilities = data.readU8();
755760

756761
let length = data.readU8();
757762
for (let i = 0; i < length; i++) {
758763
CONFIG.targetName += String.fromCharCode(data.readU8());
759764
}
760765
} else {
761-
CONFIG.commCapabilities = 0;
766+
CONFIG.targetCapabilities = 0;
762767
}
763768

764769
CONFIG.boardName = "";
@@ -782,6 +787,10 @@ MspHelper.prototype.process_data = function(dataHandler) {
782787

783788
if (semver.gte(CONFIG.apiVersion, "1.41.0")) {
784789
CONFIG.mcuTypeId = data.readU8();
790+
791+
if (semver.gte(CONFIG.apiVersion, "1.42.0")) {
792+
CONFIG.configurationState = data.readU8();
793+
}
785794
} else {
786795
CONFIG.mcuTypeId = 255;
787796
}

src/js/protocols/stm32.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ STM32_protocol.prototype.connect = function (port, baud, hex, options, callback)
153153

154154
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, function () {
155155
var rebootMode = 0; // FIRMWARE
156-
if (bit_check(CONFIG.commCapabilities, 3)) {
156+
if (bit_check(CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER)) {
157157
// Board has flash bootloader
158158
GUI.log(i18n.getMessage('deviceRebooting_flashBootloader'));
159159
console.log('flash bootloader detected');

src/js/serial_backend.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,29 @@ function onOpen(openInfo) {
258258
updateStatusBarVersion(CONFIG.flightControllerVersion, CONFIG.flightControllerIdentifier, FC.getHardwareName());
259259
updateTopBarVersion(CONFIG.flightControllerVersion, CONFIG.flightControllerIdentifier, FC.getHardwareName());
260260

261+
if (bit_check(CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.SUPPORTS_CUSTOM_DEFAULTS) && bit_check(CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_CUSTOM_DEFAULTS) && CONFIG.configurationState === FC.CONFIGURATION_STATES.DEFAULTS_BARE) {
262+
var dialog = $('#dialogResetToCustomDefaults')[0];
263+
264+
$('#dialogResetToCustomDefaults-content').html(i18n.getMessage('resetToCustomDefaultsDialog'));
265+
266+
$('#dialogResetToCustomDefaults-acceptbtn').click(function() {
267+
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'AcceptResetToCustomDefaults');
268+
269+
var buffer = [];
270+
buffer.push(mspHelper.RESET_TYPES.CUSTOM_DEFAULTS);
271+
MSP.send_message(MSPCodes.MSP_RESET_CONF, buffer, false);
272+
273+
dialog.close();
274+
});
275+
276+
$('#dialogResetToCustomDefaults-cancelbtn').click(function() {
277+
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'CancelResetToCustomDefaults');
278+
279+
dialog.close();
280+
});
281+
282+
dialog.showModal();
283+
}
261284
MSP.send_message(MSPCodes.MSP_UID, false, false, function () {
262285
var uniqueDeviceIdentifier = CONFIG.uid[0].toString(16) + CONFIG.uid[1].toString(16) + CONFIG.uid[2].toString(16);
263286

@@ -281,7 +304,7 @@ function onOpen(openInfo) {
281304
});
282305
});
283306
} else {
284-
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefused');
307+
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareType');
285308

286309
var dialog = $('.dialogConnectWarning')[0];
287310

@@ -297,7 +320,7 @@ function onOpen(openInfo) {
297320
}
298321
});
299322
} else {
300-
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefused');
323+
analytics.sendEvent(analytics.EVENT_CATEGORIES.FLIGHT_CONTROLLER, 'ConnectionRefusedFirmwareVersion');
301324

302325
var dialog = $('.dialogConnectWarning')[0];
303326

src/main.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,21 @@ <h3 i18n="warningTitle"></h3>
403403
</div>
404404
</dialog>
405405

406+
<dialog id="dialogResetToCustomDefaults">
407+
<h3 i18n="noticeTitle"></h3>
408+
<div class="content">
409+
<div id="dialogResetToCustomDefaults-content"></div>
410+
</div>
411+
<div>
412+
<span class="buttons">
413+
<a href="#" id="dialogResetToCustomDefaults-acceptbtn" class="regular-button" i18n="resetToCustomDefaultsAccept"></a>
414+
</span>
415+
<span class="buttons">
416+
<a href="#" id="dialogResetToCustomDefaults-cancelbtn" class="regular-button" i18n="cancel"></a>
417+
</span>
418+
</div>
419+
</dialog>
420+
406421
<dialog class="dialogError">
407422
<h3 i18n="errorTitle"></h3>
408423
<div class="content">

0 commit comments

Comments
 (0)