Skip to content

Commit 37fada1

Browse files
authored
Use firmware options on introduction (#3900)
* Use firmware options * Enable telemetry for CRSF, GHST and FPORT * Add supported date * Only add telemetry when not included in firmware * Reduce brain overload
1 parent 16f70a5 commit 37fada1

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

src/js/Features.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { bit_check, bit_set, bit_clear } from "./bit";
2-
import { API_VERSION_1_44, API_VERSION_1_45 } from './data_storage';
2+
import { API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from './data_storage';
33
import semver from "semver";
44
import { tracking } from "./Analytics";
55
import $ from 'jquery';
@@ -51,6 +51,18 @@ const Features = function (config) {
5151
}
5252
}
5353

54+
// Add TELEMETRY feature if any of the following protocols are used: CRSF, GHST, FPORT
55+
if (semver.gte(config.apiVersion, API_VERSION_1_46)) {
56+
let enableTelemetry = false;
57+
if (config.buildOptions.some(opt => opt.includes('CRSF') || opt.includes('GHST') || opt.includes('FPORT'))) {
58+
enableTelemetry = true;
59+
}
60+
61+
if (enableTelemetry) {
62+
self._features.push({bit: 10, group: 'telemetry', name: 'TELEMETRY', haveTip: true, dependsOn: 'TELEMETRY'});
63+
}
64+
}
65+
5466
self._features.sort((a, b) => a.name.localeCompare(b.name, window.navigator.language, { ignorePunctuation: true }));
5567
self._featureMask = 0;
5668

src/js/msp/MSPHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import semver from 'semver';
88
import vtxDeviceStatusFactory from "../utils/VtxDeviceStatus/VtxDeviceStatusFactory";
99
import MSP from "../msp";
1010
import MSPCodes from "./MSPCodes";
11-
import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from '../data_storage';
11+
import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage';
1212
import EscProtocols from "../utils/EscProtocols";
1313
import huffmanDecodeBuf from "../huffman";
1414
import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree";
@@ -795,7 +795,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
795795
FC.CONFIG.gitRevision = String.fromCharCode.apply(null, buff);
796796
console.log("Fw git rev:", FC.CONFIG.gitRevision);
797797

798-
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
798+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
799799
let option = data.readU16();
800800
while (option) {
801801
FC.CONFIG.buildOptions.push(option);

src/js/serial_backend.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import MSP from "./msp";
1010
import MSPCodes from "./msp/MSPCodes";
1111
import PortUsage from "./port_usage";
1212
import PortHandler from "./port_handler";
13-
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from "./data_storage";
13+
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46 } from "./data_storage";
1414
import UI_PHONES from "./phones_ui";
1515
import { bit_check } from './bit.js';
1616
import { sensor_status, have_sensor } from "./sensor_helpers";
@@ -353,7 +353,7 @@ function onOpen(openInfo) {
353353
gui_log(i18n.getMessage('buildInfoReceived', [FC.CONFIG.buildInfo]));
354354

355355
// retrieve build options from the flight controller
356-
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
356+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
357357
FC.processBuildOptions();
358358
}
359359

@@ -540,7 +540,7 @@ function checkReportProblems() {
540540
}
541541

542542
async function processBuildOptions() {
543-
const supported = semver.satisfies(FC.CONFIG.apiVersion, `${API_VERSION_1_45} - ${API_VERSION_1_46}`);
543+
const supported = semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_45);
544544

545545
// firmware 1_45 or higher is required to support cloud build options
546546
// firmware 1_46 or higher retrieves build options from the flight controller

src/js/tabs/firmware_flasher.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import FC from '../fc';
1212
import MSP from '../msp';
1313
import MSPCodes from '../msp/MSPCodes';
1414
import PortHandler, { usbDevices } from '../port_handler';
15-
import { API_VERSION_1_39, API_VERSION_1_45, API_VERSION_1_47 } from '../data_storage';
15+
import { API_VERSION_1_39, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage';
1616
import serial from '../serial';
1717
import STM32DFU from '../protocols/stm32usbdfu';
1818
import { gui_log } from '../gui_log';
@@ -1305,7 +1305,7 @@ firmware_flasher.verifyBoard = function() {
13051305

13061306
function getBoardInfo() {
13071307
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, function() {
1308-
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
1308+
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
13091309
FC.processBuildOptions();
13101310
self.cloudBuildOptions = FC.CONFIG.buildOptions;
13111311
}
@@ -1320,20 +1320,24 @@ firmware_flasher.verifyBoard = function() {
13201320
getBoardInfo();
13211321
}
13221322

1323-
function getBuildInfo() {
1323+
async function getBuildInfo() {
13241324
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.CONFIG.flightControllerIdentifier === 'BTFL') {
1325-
MSP.send_message(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.BUILD_KEY), false, () => {
1326-
MSP.send_message(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME), false, () => {
1327-
// store FC.CONFIG.buildKey as the object gets destroyed after disconnect
1328-
self.cloudBuildKey = FC.CONFIG.buildKey;
1325+
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.BUILD_KEY));
1326+
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME));
1327+
await MSP.promise(MSPCodes.MSP_BUILD_INFO);
13291328

1330-
if (self.validateBuildKey() && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
1331-
self.buildApi.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
1332-
} else {
1333-
getBoardInfo();
1334-
}
1335-
});
1336-
});
1329+
// store FC.CONFIG.buildKey as the object gets destroyed after disconnect
1330+
self.cloudBuildKey = FC.CONFIG.buildKey;
1331+
1332+
// 3/21/2024 is the date when the build key was introduced
1333+
const supportedDate = new Date('3/21/2024');
1334+
const buildDate = new Date(FC.CONFIG.buildInfo);
1335+
1336+
if (self.validateBuildKey() && (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_46) || buildDate < supportedDate)) {
1337+
self.buildApi.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
1338+
} else {
1339+
getBoardInfo();
1340+
}
13371341
} else {
13381342
getBoardInfo();
13391343
}

0 commit comments

Comments
 (0)