1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-17 13:25:24 +03:00

Refactor: Config inserter (#3217)

Refactor ConfigInserter to class
This commit is contained in:
J Blackman 2023-01-07 00:20:06 +11:00 committed by GitHub
parent 3e92a0bb64
commit 3a6ea29147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 20 deletions

View file

@ -1,7 +1,3 @@
'use strict';
const ConfigInserter = function () {
};
const CUSTOM_DEFAULTS_POINTER_ADDRESS = 0x08002800;
const BLOCK_SIZE = 16384;
@ -87,21 +83,24 @@ function generateData(firmware, input, startAddress) {
const CONFIG_LABEL = `Custom defaults inserted in`;
ConfigInserter.prototype.insertConfig = function (firmware, config) {
console.time(CONFIG_LABEL);
export default class ConfigInserter {
const input = `# Betaflight\n${config}\0`;
const customDefaultsArea = getCustomDefaultsArea(firmware);
insertConfig(firmware, config) {
console.time(CONFIG_LABEL);
if (!customDefaultsArea || customDefaultsArea.endAddress - customDefaultsArea.startAddress === 0) {
return false;
} else if (input.length >= customDefaultsArea.endAddress - customDefaultsArea.startAddress) {
throw new Error(`Custom defaults area too small (${customDefaultsArea.endAddress - customDefaultsArea.startAddress} bytes), ${input.length + 1} bytes needed.`);
const input = `# Betaflight\n${config}\0`;
const customDefaultsArea = getCustomDefaultsArea(firmware);
if (!customDefaultsArea || customDefaultsArea.endAddress - customDefaultsArea.startAddress === 0) {
return false;
} else if (input.length >= customDefaultsArea.endAddress - customDefaultsArea.startAddress) {
throw new Error(`Custom defaults area too small (${customDefaultsArea.endAddress - customDefaultsArea.startAddress} bytes), ${input.length + 1} bytes needed.`);
}
generateData(firmware, input, customDefaultsArea.startAddress);
console.timeEnd(CONFIG_LABEL);
return true;
}
generateData(firmware, input, customDefaultsArea.startAddress);
console.timeEnd(CONFIG_LABEL);
return true;
};
}

View file

@ -3,6 +3,7 @@ import GUI from '../gui';
import { get as getConfig, set as setConfig } from '../ConfigStorage';
import { get as getStorage, set as setStorage } from '../SessionStorage';
import BuildApi from '../BuildApi';
import ConfigInserter from "../ConfigInserter.js";
const firmware_flasher = {
targets: null,

View file

@ -105,7 +105,6 @@
<script type="text/javascript" src="./js/RateCurve.js"></script>
<script type="text/javascript" src="./js/Features.js"></script>
<script type="text/javascript" src="./js/Beepers.js"></script>
<script type="text/javascript" src="./js/ConfigInserter.js"></script>
<script type="text/javascript" src="./js/GitHubApi.js"></script>
<script type="module" src="./js/main.js"></script>
<script type="text/javascript" src="./js/LogoManager.js"></script>