Skip to content

Commit

Permalink
Refactor ConfigInserter to class
Browse files Browse the repository at this point in the history
  • Loading branch information
blckmn committed Jan 6, 2023
1 parent 82092f5 commit 35115e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions src/js/ConfigInserter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
'use strict';

const ConfigInserter = function () {
};

const CUSTOM_DEFAULTS_POINTER_ADDRESS = 0x08002800;
const BLOCK_SIZE = 16384;
Expand Down Expand Up @@ -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);
generateData(firmware, input, customDefaultsArea.startAddress);

console.timeEnd(CONFIG_LABEL);
console.timeEnd(CONFIG_LABEL);

return true;
};
return true;
}
}
1 change: 1 addition & 0 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 35115e7

Please sign in to comment.