Skip to content

Commit

Permalink
Adjust peripherals mode name in failsafe tab
Browse files Browse the repository at this point in the history
The failsafe tab does not adjust the real name of the MODE for
peripherals. Only the MODES tab do it.
  • Loading branch information
McGiverGim committed Oct 4, 2017
1 parent d55f22b commit 6054e69
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
32 changes: 32 additions & 0 deletions js/peripherals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

// return true if user has choose a special peripheral
function isPeripheralSelected(peripheralName) {
for (var portIndex = 0; portIndex < SERIAL_CONFIG.ports.length; portIndex++) {
var serialPort = SERIAL_CONFIG.ports[portIndex];
if (serialPort.functions.indexOf(peripheralName) >= 0) {
return true;
}
}

return false;
}

// Adjust the real name for a modeId. Useful if it belongs to a peripheral
function adjustBoxNameIfPeripheralWithModeID(modeId, defaultName) {
if (isPeripheralSelected("RUNCAM_SPLIT_CONTROL")) {
switch (modeId) {
case 32: // BOXCAMERA1
return chrome.i18n.getMessage('modeCameraWifi');
case 33: // BOXCAMERA2
return chrome.i18n.getMessage('modeCameraPower');
case 34: // BOXCAMERA3
return chrome.i18n.getMessage('modeCameraChangeMode');
default:
return defaultName;
}
}

return defaultName;

}
1 change: 1 addition & 0 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<script type="text/javascript" src="./js/msp.js"></script>
<script type="text/javascript" src="./js/msp/MSPHelper.js"></script>
<script type="text/javascript" src="./js/backup_restore.js"></script>
<script type="text/javascript" src="./js/peripherals.js"></script>
<script type="text/javascript" src="./js/protocols/stm32.js"></script>
<script type="text/javascript" src="./js/protocols/stm32usbdfu.js"></script>
<script type="text/javascript" src="./js/localization.js"></script>
Expand Down
33 changes: 3 additions & 30 deletions tabs/auxiliary.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,13 @@ TABS.auxiliary.initialize = function (callback) {

MSP.send_message(MSPCodes.MSP_BOXNAMES, false, false, get_mode_ranges);

// return true if user has choose a special peripheral
function isPeripheralSelected(peripheralName) {
for (var portIndex = 0; portIndex < SERIAL_CONFIG.ports.length; portIndex++) {
var serialPort = SERIAL_CONFIG.ports[portIndex];
if (serialPort.functions.indexOf(peripheralName) >= 0) {
return true;
}
}

return false;
}

function adjustRunCamSplitBoxNameWithModeID(modeId, originalModeName) {
switch (modeId) {
case 32: // BOXCAMERA1
return chrome.i18n.getMessage('modeCameraWifi');
case 33: // BOXCAMERA2
return chrome.i18n.getMessage('modeCameraPower');
case 34: // BOXCAMERA3
return chrome.i18n.getMessage('modeCameraChangeMode');
default:
return originalModeName;
}
}

function createMode(modeIndex, modeId) {
var modeTemplate = $('#tab-auxiliary-templates .mode');
var newMode = modeTemplate.clone();

var modeName = AUX_CONFIG[modeIndex];
// if user choose the runcam split at peripheral column, then adjust the boxname(BOXCAMERA1, BOXCAMERA2, BOXCAMERA3)
if (isPeripheralSelected("RUNCAM_SPLIT_CONTROL")) {
modeName = adjustRunCamSplitBoxNameWithModeID(modeId, modeName);
}
var modeName = AUX_CONFIG[modeIndex];
// Adjust the name of the box if a peripheral is selected
modeName = adjustBoxNameIfPeripheralWithModeID(modeId, modeName);

$(newMode).attr('id', 'mode-' + modeIndex);
$(newMode).find('.name').text(modeName);
Expand Down
12 changes: 10 additions & 2 deletions tabs/failsafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
}

function get_box_ids() {
MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, get_rc_data);
MSP.send_message(MSPCodes.MSP_BOXIDS, false, false, get_ports_config);
}

function get_ports_config() {
MSP.send_message(MSPCodes.MSP_CF_SERIAL_CONFIG, false, false, get_rc_data);
}

function get_rc_data() {
Expand Down Expand Up @@ -100,8 +104,12 @@ TABS.failsafe.initialize = function (callback, scrollPosition) {
if (!(range.start < range.end)) {
continue; // invalid!
}

// Search for the real name if it belongs to a peripheral
var modeName = AUX_CONFIG[modeIndex];
modeName = adjustBoxNameIfPeripheralWithModeID(modeId, modeName);

auxAssignment[modeRange.auxChannelIndex] += "<span class=\"modename\">" + AUX_CONFIG[modeIndex] + "</span>";
auxAssignment[modeRange.auxChannelIndex] += "<span class=\"modename\">" + modeName + "</span>";
}
}

Expand Down

0 comments on commit 6054e69

Please sign in to comment.