Skip to content

Commit 0845b74

Browse files
authored
Merge pull request #734 from mikeller/add_arming_enable_to_motor_test_slider
Added arming enable to the 'motor test enable' switch.
2 parents ddde159 + 808c338 commit 0845b74

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed

_locales/en/messages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,10 +1495,10 @@
14951495
"message": "Master"
14961496
},
14971497
"motorsNotice": {
1498-
"message": "<strong>Motor Test Mode Notice:</strong><br />Moving the sliders will cause the motors to <strong>spin up</strong>.<br />In order to prevent injury <strong style=\"color: red\">remove ALL propellers</strong> before using this feature.<br />"
1498+
"message": "<strong>Motor Test Mode / Arming Notice:</strong><br />Moving the sliders or arming your craft with the transmitter will cause the motors to <strong>spin up</strong>.<br />In order to prevent injury <strong style=\"color: red\">remove ALL propellers</strong> before using this feature.<br />"
14991499
},
15001500
"motorsEnableControl": {
1501-
"message": "I understand the risks, propellers are removed - Enable motor control."
1501+
"message": "I understand the risks, propellers are removed - Enable motor control and arming."
15021502
},
15031503

15041504
"sensorsInfo": {

js/msp/MSPHelper.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,6 +2022,28 @@ MspHelper.prototype.sendRxFailConfig = function(onCompleteCallback) {
20222022
}
20232023
}
20242024

2025+
MspHelper.prototype.setArmingEnabled = function(doEnable, onCompleteCallback) {
2026+
if (semver.gte(CONFIG.apiVersion, "1.37.0") && (doEnable === CONFIG.arming_disabled)) {
2027+
CONFIG.arming_disabled = !doEnable;
2028+
2029+
MSP.send_message(MSPCodes.MSP_ARMING_DISABLE, mspHelper.crunch(MSPCodes.MSP_ARMING_DISABLE), false, function () {
2030+
if (doEnable) {
2031+
GUI.log(chrome.i18n.getMessage('armingEnabled'));
2032+
} else {
2033+
GUI.log(chrome.i18n.getMessage('armingDisabled'));
2034+
}
2035+
2036+
if (onCompleteCallback) {
2037+
onCompleteCallback();
2038+
}
2039+
});
2040+
} else {
2041+
if (onCompleteCallback) {
2042+
onCompleteCallback();
2043+
}
2044+
}
2045+
}
2046+
20252047
MSP.SDCARD_STATE_NOT_PRESENT = 0; //TODO, move these to better place
20262048
MSP.SDCARD_STATE_FATAL = 1;
20272049
MSP.SDCARD_STATE_CARD_INIT = 2;

js/serial_backend.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ $(document).ready(function () {
5959
$('div#port-picker #port, div#port-picker #baud, div#port-picker #delay').prop('disabled', true);
6060
$('div.connect_controls a.connect_state').text(chrome.i18n.getMessage('connecting'));
6161

62-
6362
serial.connect(selected_port, {bitrate: selected_baud}, onOpen);
6463

6564
toggleStatus();
@@ -69,17 +68,11 @@ $(document).ready(function () {
6968
GUI.tab_switch_cleanup();
7069
GUI.tab_switch_in_progress = false;
7170

72-
if (semver.gte(CONFIG.apiVersion, "1.37.0") && CONFIG.arming_disabled) {
73-
CONFIG.arming_disabled = false;
74-
75-
MSP.send_message(MSPCodes.MSP_ARMING_DISABLE, mspHelper.crunch(MSPCodes.MSP_ARMING_DISABLE), false, function () {
76-
GUI.log(chrome.i18n.getMessage('armingEnabled'));
77-
78-
finishClose(toggleStatus);
79-
});
80-
} else {
71+
function onFinishCallback() {
8172
finishClose(toggleStatus);
8273
}
74+
75+
mspHelper.setArmingEnabled(true, onFinishCallback);
8376
}
8477
}
8578
}
@@ -234,17 +227,8 @@ function onOpen(openInfo) {
234227
MSP.send_message(MSPCodes.MSP_NAME, false, false, function () {
235228
GUI.log(chrome.i18n.getMessage('craftNameReceived', [CONFIG.name]));
236229

237-
if (semver.gte(CONFIG.apiVersion, "1.37.0")) {
238-
CONFIG.arming_disabled = true;
239-
240-
MSP.send_message(MSPCodes.MSP_ARMING_DISABLE, mspHelper.crunch(MSPCodes.MSP_ARMING_DISABLE), false, function () {
241-
GUI.log(chrome.i18n.getMessage('armingDisabled'));
242-
243-
finishOpen();
244-
});
245-
} else {
246-
finishOpen();
247-
}
230+
CONFIG.arming_disabled = false;
231+
mspHelper.setArmingEnabled(false, finishOpen);
248232
});
249233
} else {
250234
finishOpen();

tabs/motors.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ TABS.motors.initialize = function (callback) {
210210
self.escProtocolIsDshot = false;
211211
}
212212

213-
$('#motorsEnableTestMode').prop('checked', false)
214-
.prop('disabled', true);
213+
$('#motorsEnableTestMode').prop('checked', false);
215214

216215
update_model(MIXER_CONFIG.mixer);
217216

@@ -461,10 +460,8 @@ TABS.motors.initialize = function (callback) {
461460
}
462461
}
463462

464-
setSlidersDefault();
465-
466-
$('#motorsEnableTestMode').change(function () {
467-
if ($(this).is(':checked')) {
463+
function setSlidersEnabled(isEnabled) {
464+
if (isEnabled && !self.armed) {
468465
$('div.sliders input').slice(0, number_of_valid_outputs).prop('disabled', false);
469466

470467
// unlock master slider
@@ -477,6 +474,18 @@ TABS.motors.initialize = function (callback) {
477474
}
478475

479476
$('div.sliders input').trigger('input');
477+
}
478+
479+
setSlidersDefault();
480+
481+
$('#motorsEnableTestMode').change(function () {
482+
var enabled = $(this).is(':checked');
483+
484+
setSlidersEnabled(enabled);
485+
486+
$('div.sliders input').trigger('input');
487+
488+
mspHelper.setArmingEnabled(enabled);
480489
}).change();
481490

482491
var buffering_set_motor = [],
@@ -530,9 +539,8 @@ TABS.motors.initialize = function (callback) {
530539
}
531540

532541
if (motors_running) {
533-
if (!self.armed) {
534-
$('#motorsEnableTestMode').prop('checked', true).change();
535-
}
542+
$('#motorsEnableTestMode').prop('checked', true).change();
543+
536544
// motors are running adjust sliders to current values
537545

538546
var sliders = $('div.sliders input:not(.master)');
@@ -607,15 +615,9 @@ TABS.motors.initialize = function (callback) {
607615
//keep the following here so at least we get a visual cue of our motor setup
608616
update_arm_status();
609617

610-
if (self.armed) {
611-
$('#motorsEnableTestMode').prop('disabled', true)
612-
.prop('checked', false);
613-
} else {
614-
$('#motorsEnableTestMode').prop('disabled', false);
615-
}
616-
617618
if (previousArmState != self.armed) {
618619
console.log('arm state change detected');
620+
619621
$('#motorsEnableTestMode').change();
620622
}
621623
}

0 commit comments

Comments
 (0)