1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 08:15:22 +03:00

feat: use modules for common utils

This commit is contained in:
Tomas Chmelevskij 2021-01-01 22:01:42 +04:00
parent d5d0146af7
commit ef68bb170f
5 changed files with 33 additions and 27 deletions

View file

@ -1,21 +1,20 @@
'use strict';
import semver from "semver";
function microtime() {
export function microtime() {
return new Date().getTime() / 1000;
}
function millitime() {
export function millitime() {
return new Date().getTime();
}
const DEGREE_TO_RADIAN_RATIO = Math.PI / 180;
function degToRad(degrees) {
export function degToRad(degrees) {
return degrees * DEGREE_TO_RADIAN_RATIO;
}
function bytesToSize(bytes) {
export function bytesToSize(bytes) {
let outputBytes;
if (bytes < 1024) {
@ -35,27 +34,33 @@ function bytesToSize(bytes) {
* checkChromeRuntimeError() has to be called after each chrome API call
*/
function checkChromeRuntimeError() {
export function checkChromeRuntimeError() {
if (chrome.runtime.lastError) {
console.error(`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${(new Error).stack}`);
console.error(
`Chrome API Error: ${chrome.runtime.lastError.message}.\n Traced ${
new Error().stack
}`
);
return true;
}
return false;
}
const majorFirmwareVersions = {
'1.43': '4.2.*',
'1.42': '4.1.*',
'1.41': '4.0.*',
'1.40': '3.5.*',
'1.39': '3.4.*',
'1.37': '3.3.0',
'1.36': '3.2.*',
'1.31': '3.1.0',
"1.43": "4.2.*",
"1.42": "4.1.*",
"1.41": "4.0.*",
"1.40": "3.5.*",
"1.39": "3.4.*",
"1.37": "3.3.0",
"1.36": "3.2.*",
"1.31": "3.1.0"
};
function generateVirtualApiVersions() {
const firmwareVersionDropdown = document.getElementById('firmware-version-dropdown');
export function generateVirtualApiVersions() {
const firmwareVersionDropdown = document.getElementById(
"firmware-version-dropdown"
);
const max = semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED);
for (let i = max; i > 0; i--) {
@ -73,3 +78,10 @@ function generateVirtualApiVersions() {
firmwareVersionDropdown.appendChild(option);
}
}
window.microtime = microtime;
window.millitime = millitime;
window.degToRad = degToRad;
window.bytesToSize = bytesToSize;
window.checkChromeRuntimeError = checkChromeRuntimeError;
window.generateVirtualApiVersions = generateVirtualApiVersions;