Skip to content

Commit

Permalink
Merge pull request #2798 from krasiyan/1877-display-name-configuration
Browse files Browse the repository at this point in the history
Add 'Pilot name' to the Configurator UI; rename 'Display name' to 'Pilot name'; rename 'name' to 'craft_name'
  • Loading branch information
haslinghuis authored Oct 30, 2022
2 parents fbff80d + 3873f82 commit 4f93487
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 47 deletions.
20 changes: 18 additions & 2 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4998,7 +4998,7 @@
"description": "One of the elements of the OSD"
},
"osdDescElementCraftName": {
"message": "Craft name as set in Configuration tab"
"message": "Craft name as set in the Configuration tab.</br>Can also be set via the \"craft_name\" CLI variable."
},
"osdTextElementAltitude": {
"message": "Altitude",
Expand Down Expand Up @@ -5346,7 +5346,14 @@
"description": "One of the elements of the OSD"
},
"osdDescElementDisplayName": {
"message": "Display name as set by the \"display_name\" cli command"
"message": "Can also be set via the \"display_name\" CLI variable."
},
"osdTextElementPilotName": {
"message": "Pilot name",
"description": "One of the elements of the OSD"
},
"osdDescElementPilotName": {
"message": "Pilot name as set in the Configuration tab.</br>Can also be set via the \"pilot_name\" CLI variable."
},
"osdTextElementEscRpmFreq": {
"message": "ESC RPM frequency",
Expand Down Expand Up @@ -6284,6 +6291,15 @@
"craftName": {
"message": "Craft name"
},
"configurationCraftNameHelp": {
"message": "Can be show in logs, backup file names and the OSD.</br>Can be set via the <b>craft_name</b> CLI variable."
},
"configurationPilotName": {
"message": "Pilot name"
},
"configurationPilotNameHelp": {
"message": "Can be show in the OSD.</br>Can be set via <b>pilot_name</b> CLI variable."
},
"configurationFpvCamAngleDegrees": {
"message": "FPV Camera Angle [degrees]"
},
Expand Down
43 changes: 35 additions & 8 deletions src/js/backup_restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,13 @@ function configuration_backup(callback) {
configuration.LED_STRIP = jQuery.extend(true, [], FC.LED_STRIP);
configuration.LED_COLORS = jQuery.extend(true, [], FC.LED_COLORS);
configuration.BOARD_ALIGNMENT_CONFIG = jQuery.extend(true, {}, FC.BOARD_ALIGNMENT_CONFIG);
configuration.CRAFT_NAME = FC.CONFIG.name;
configuration.DISPLAY_NAME = FC.CONFIG.displayName;
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
configuration.CRAFT_NAME = FC.CONFIG.craftName;
configuration.PILOT_NAME = FC.CONFIG.pilotName;
} else {
configuration.CRAFT_NAME = FC.CONFIG.name;
configuration.DISPLAY_NAME = FC.CONFIG.displayName;
}
configuration.MIXER_CONFIG = jQuery.extend(true, {}, FC.MIXER_CONFIG);
configuration.SENSOR_CONFIG = jQuery.extend(true, {}, FC.SENSOR_CONFIG);
configuration.PID_ADVANCED_CONFIG = jQuery.extend(true, {}, FC.PID_ADVANCED_CONFIG);
Expand Down Expand Up @@ -190,7 +195,12 @@ function configuration_backup(callback) {
MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG).then(function() {
return MSP.promise(MSPCodes.MSP_SENSOR_CONFIG);
}).then(function() {
return MSP.promise(MSPCodes.MSP_NAME);
return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
: MSP.promise(MSPCodes.MSP_NAME);
}).then(function() {
return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true);
}).then(function() {
return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG);
}).then(function() {
Expand Down Expand Up @@ -801,7 +811,13 @@ function configuration_restore(callback) {
];

function update_unique_data_list() {
uniqueData.push(MSPCodes.MSP_SET_NAME);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME]);
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME]);
} else {
uniqueData.push(MSPCodes.MSP_SET_NAME);
}

uniqueData.push(MSPCodes.MSP_SET_SENSOR_CONFIG);
uniqueData.push(MSPCodes.MSP_SET_MIXER_CONFIG);
uniqueData.push(MSPCodes.MSP_SET_BEEPER_CONFIG);
Expand Down Expand Up @@ -847,8 +863,13 @@ function configuration_restore(callback) {
FC.GPS_CONFIG = configuration.GPS_CONFIG;
FC.RSSI_CONFIG = configuration.RSSI_CONFIG;
FC.BOARD_ALIGNMENT_CONFIG = configuration.BOARD_ALIGNMENT_CONFIG;
FC.CONFIG.name = configuration.CRAFT_NAME;
FC.CONFIG.displayName = configuration.DISPLAY_NAME;
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
FC.CONFIG.craftName = configuration.CRAFT_NAME;
FC.CONFIG.pilotName = configuration.PILOT_NAME;
} else {
FC.CONFIG.name = configuration.CRAFT_NAME;
FC.CONFIG.displayName = configuration.DISPLAY_NAME;
}
FC.MIXER_CONFIG = configuration.MIXER_CONFIG;
FC.SENSOR_CONFIG = configuration.SENSOR_CONFIG;
FC.PID_ADVANCED_CONFIG = configuration.PID_ADVANCED_CONFIG;
Expand All @@ -862,10 +883,16 @@ function configuration_restore(callback) {

function send_unique_data_item() {
if (codeKey < uniqueData.length) {
MSP.send_message(uniqueData[codeKey], mspHelper.crunch(uniqueData[codeKey]), false, function () {
const callback = () => {
codeKey++;
send_unique_data_item();
});
};

if (Array.isArray(uniqueData[codeKey])) {
MSP.send_message(uniqueData[codeKey][0], mspHelper.crunch(...uniqueData[codeKey]), false, callback);
} else {
MSP.send_message(uniqueData[codeKey], mspHelper.crunch(uniqueData[codeKey]), false, callback);
}
} else {
send_led_strip_config();
}
Expand Down
6 changes: 4 additions & 2 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const INITIAL_CONFIG = {
profile: 0,
uid: [0, 0, 0],
accelerometerTrims: [0, 0],
name: '',
displayName: 'JOE PILOT',
name: '', // present for backwards compatibility before MSP v1.45
craftName: '',
displayName: '', // present for backwards compatibility before MSP v1.45
pilotName: '',
numProfiles: 3,
rateProfile: 0,
boardType: 0,
Expand Down
7 changes: 5 additions & 2 deletions src/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,11 @@ function generateFilename(prefix, suffix) {
if (FC.CONFIG.flightControllerIdentifier) {
filename = `${FC.CONFIG.flightControllerIdentifier}_${filename}`;
}
if(FC.CONFIG.name && FC.CONFIG.name.trim() !== '') {
filename = `${filename}_${FC.CONFIG.name.trim().replace(' ', '_')}`;
const craftName = semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? FC.CONFIG.craftName
: FC.CONFIG.name;
if (craftName.trim() !== '') {
filename = `${filename}_${craftName.trim().replace(' ', '_')}`;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const MSPCodes = {
MSP_BOARD_INFO: 4,
MSP_BUILD_INFO: 5,

MSP_NAME: 10,
MSP_SET_NAME: 11,
MSP_NAME: 10, // DEPRECATED IN MSP 1.45
MSP_SET_NAME: 11, // DEPRECATED IN MSP 1.45

MSP_BATTERY_CONFIG: 32,
MSP_SET_BATTERY_CONFIG: 33,
Expand Down Expand Up @@ -192,4 +192,10 @@ const MSPCodes = {
MSP2_SET_MOTOR_OUTPUT_REORDERING: 0x3002,
MSP2_SEND_DSHOT_COMMAND: 0x3003,
MSP2_GET_VTX_DEVICE_STATUS: 0x3004,
MSP2_GET_TEXT: 0x3006,
MSP2_SET_TEXT: 0x3007,

// MSP2_GET_TEXT and MSP2_SET_TEXT variable types
MSP2TEXT_PILOT_NAME: 1,
MSP2TEXT_CRAFT_NAME: 2,
};
66 changes: 64 additions & 2 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,25 @@ MspHelper.prototype.process_data = function(dataHandler) {
}
break;

case MSPCodes.MSP2_GET_TEXT:
// type byte
const textType = data.readU8();
// length byte followed by the actual characters
const textLength = data.readU8() || 0;

if (textType === MSPCodes.MSP2TEXT_PILOT_NAME) {
FC.CONFIG.pilotName = '';
for (let i = 0; i < textLength; i++) {
FC.CONFIG.pilotName += String.fromCharCode(data.readU8());
}
} else if (textType === MSPCodes.MSP2TEXT_CRAFT_NAME) {
FC.CONFIG.craftName = '';
for (let i = 0; i < textLength; i++) {
FC.CONFIG.craftName += String.fromCharCode(data.readU8());
}
}
break;

case MSPCodes.MSP_SET_CHANNEL_FORWARDING:
console.log('Channel forwarding saved');
break;
Expand Down Expand Up @@ -1688,6 +1707,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
case MSPCodes.MSP_SET_NAME:
console.log('Name set');
break;
case MSPCodes.MSP2_SET_TEXT:
console.log('Text set');
break;
case MSPCodes.MSP_SET_FILTER_CONFIG:
// removed as this fires a lot with firmware sliders console.log('Filter config set');
break;
Expand Down Expand Up @@ -1794,8 +1816,10 @@ MspHelper.prototype.process_data = function(dataHandler) {

/**
* Encode the request body for the MSP request with the given code and return it as an array of bytes.
* The second (optional) 'modifierCode' argument can be used to extend/specify the behavior of certain MSP codes
* (e.g. 'MSPCodes.MSP2_GET_TEXT' and 'MSPCodes.MSP2_SET_TEXT')
*/
MspHelper.prototype.crunch = function(code) {
MspHelper.prototype.crunch = function(code, modifierCode = undefined) {
const buffer = [];
const self = this;

Expand Down Expand Up @@ -2320,6 +2344,44 @@ MspHelper.prototype.crunch = function(code) {
}
break;

case MSPCodes.MSP2_GET_TEXT:
if (modifierCode === MSPCodes.MSP2TEXT_PILOT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_PILOT_NAME);
} else if (modifierCode === MSPCodes.MSP2TEXT_CRAFT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_CRAFT_NAME);
}
break;

case MSPCodes.MSP2_SET_TEXT:
if (modifierCode === MSPCodes.MSP2TEXT_PILOT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_PILOT_NAME);

const MAX_NAME_LENGTH = 16;
const pilotNameLength = Math.min(MAX_NAME_LENGTH, FC.CONFIG.pilotName.length);
// length byte followed by the actual characters
buffer.push8(pilotNameLength);

for (let i = 0; i < pilotNameLength; i++) {
buffer.push8(FC.CONFIG.pilotName.charCodeAt(i));
}
} else if (modifierCode === MSPCodes.MSP2TEXT_CRAFT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_CRAFT_NAME);

const MAX_NAME_LENGTH = 16;
const craftNameLength = Math.min(MAX_NAME_LENGTH, FC.CONFIG.craftName.length);
// length byte followed by the actual characters
buffer.push8(craftNameLength);

for (let i = 0; i < craftNameLength; i++) {
buffer.push8(FC.CONFIG.craftName.charCodeAt(i));
}
}
break;

case MSPCodes.MSP_SET_BLACKBOX_CONFIG:
buffer.push8(FC.BLACKBOX.blackboxDevice)
.push8(FC.BLACKBOX.blackboxRateNum)
Expand Down Expand Up @@ -2474,7 +2536,7 @@ MspHelper.prototype.crunch = function(code) {
break;

default:
return false;
return buffer;
}

return buffer;
Expand Down
31 changes: 24 additions & 7 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,20 +445,37 @@ function processUid() {
GUI.log(i18n.getMessage('uniqueDeviceIdReceived', [uniqueDeviceIdentifier]));

if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
processName();
processCraftName();
} else {
setRtc();
}
});
}

function processName() {
MSP.send_message(MSPCodes.MSP_NAME, false, false, function () {
GUI.log(i18n.getMessage('craftNameReceived', [FC.CONFIG.name]));
async function processCraftName() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
await MSP.promise(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME),
);
} else {
await MSP.promise(MSPCodes.MSP_NAME);
}

FC.CONFIG.armingDisabled = false;
mspHelper.setArmingEnabled(false, false, setRtc);
});
GUI.log(i18n.getMessage('craftNameReceived', semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? [FC.CONFIG.craftName]
: [FC.CONFIG.name],
));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
await MSP.promise(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME),
);
}

FC.CONFIG.armingDisabled = false;
mspHelper.setArmingEnabled(false, false, setRtc);
}

function setRtc() {
Expand Down
30 changes: 26 additions & 4 deletions src/js/tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ configuration.initialize = function (callback) {
.then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.17.0") ? MSP.promise(MSPCodes.MSP_RC_DEADBAND) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.16.0") ? MSP.promise(MSPCodes.MSP_SENSOR_CONFIG) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.15.0") ? MSP.promise(MSPCodes.MSP_SENSOR_ALIGNMENT) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.20.0") ? MSP.promise(MSPCodes.MSP_NAME) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, "1.20.0") && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP_NAME)
: Promise.resolve(true); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
: Promise.resolve(true); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31) ? MSP.promise(MSPCodes.MSP_RX_CONFIG) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true); })
.then(() => { return MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG); })
.then(() => { load_html(); });
}
Expand Down Expand Up @@ -368,7 +375,13 @@ configuration.initialize = function (callback) {
$('.hardwareSelection').hide();
}

$('input[name="craftName"]').val(FC.CONFIG.name);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
$('input[name="craftName"]').val(FC.CONFIG.craftName);
$('input[name="pilotName"]').val(FC.CONFIG.pilotName);
} else {
$('input[name="craftName"]').val(FC.CONFIG.name);
$('.pilotName').hide();
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) {
$('input[name="fpvCamAngleDegrees"]').val(FC.RX_CONFIG.fpvCamAngleDegrees);
Expand Down Expand Up @@ -594,7 +607,12 @@ configuration.initialize = function (callback) {
FC.SENSOR_CONFIG.acc_hardware = $('input[id="accHardwareSwitch"]').is(':checked') ? 0 : 1;
FC.SENSOR_CONFIG.baro_hardware = $('input[id="baroHardwareSwitch"]').is(':checked') ? 0 : 1;
FC.SENSOR_CONFIG.mag_hardware = $('input[id="magHardwareSwitch"]').is(':checked') ? 0 : 1;
FC.CONFIG.name = $.trim($('input[name="craftName"]').val());
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
FC.CONFIG.craftName = $('input[name="craftName"]').val().trim();
FC.CONFIG.pilotName = $('input[name="pilotName"]').val().trim();
} else {
FC.CONFIG.name = $('input[name="craftName"]').val().trim();
}

function save_serial_config() {
mspHelper.sendSerialConfig(save_config);
Expand All @@ -617,7 +635,11 @@ configuration.initialize = function (callback) {
.then(() => { return MSP.promise(MSPCodes.MSP_SET_ACC_TRIM, mspHelper.crunch(MSPCodes.MSP_SET_ACC_TRIM)); })
.then(() => { return MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG)); })
.then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG)); })
.then(() => { return MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME)); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
: MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME)); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ?
MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true); })
.then(() => { return (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) ? MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG)) : true; })
.then(() => { return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); })
.then(() => { reboot(); });
Expand Down
11 changes: 10 additions & 1 deletion src/js/tabs/onboard_logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ onboard_logging.initialize = function (callback) {
MSP.send_message(MSPCodes.MSP_SDCARD_SUMMARY, false, false, function() {
MSP.send_message(MSPCodes.MSP_BLACKBOX_CONFIG, false, false, function() {
MSP.send_message(MSPCodes.MSP_ADVANCED_CONFIG, false, false, function() {
MSP.send_message(MSPCodes.MSP_NAME, false, false, load_html);
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
MSP.send_message(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME),
false,
load_html,
);
} else {
MSP.send_message(MSPCodes.MSP_NAME, false, false, load_html);
}
});
});
});
Expand Down
Loading

0 comments on commit 4f93487

Please sign in to comment.