UNPKG

@betaflight/api

Version:

A high-level API to read data from betaflight flight controllers

68 lines 2.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.writePartialMixerConfig = exports.writeMixerConfig = exports.readMixerConfig = exports.writeMotorConfig = exports.readMotorConfig = void 0; const msp_1 = require("@betaflight/msp"); const semver_1 = __importDefault(require("semver")); const codes_1 = __importDefault(require("../codes")); const utils_1 = require("../utils"); const readMotorConfig = async (port) => { const api = (0, msp_1.apiVersion)(port); const data = await (0, msp_1.execute)(port, { code: codes_1.default.MSP_MOTOR_CONFIG }); return { minThrottle: data.readU16(), maxThrottle: data.readU16(), minCommand: data.readU16(), ...(semver_1.default.gte(api, "1.42.0") ? { motorCount: data.readU8(), motorPoles: data.readU8(), useDshotTelemetry: data.readU8() !== 0, useEscSensor: data.readU8() !== 0, } : { motorCount: 0, motorPoles: 0, useDshotTelemetry: false, useEscSensor: false, }), }; }; exports.readMotorConfig = readMotorConfig; const writeMotorConfig = async (port, config) => { const api = (0, msp_1.apiVersion)(port); const buffer = new msp_1.WriteBuffer(); buffer .push16(config.minThrottle) .push16(config.maxThrottle) .push16(config.minCommand); if (semver_1.default.gte(api, "1.42.0")) { buffer.push8(config.motorPoles); buffer.push8(config.useDshotTelemetry ? 1 : 0); } await (0, msp_1.execute)(port, { code: codes_1.default.MSP_SET_MOTOR_CONFIG, data: buffer }); }; exports.writeMotorConfig = writeMotorConfig; const readMixerConfig = async (port) => { const data = await (0, msp_1.execute)(port, { code: codes_1.default.MSP_MIXER_CONFIG }); const api = (0, msp_1.apiVersion)(port); return { mixer: data.readU8(), reversedMotors: !!(semver_1.default.gte(api, "1.36.0") ? data.readU8() : 0), }; }; exports.readMixerConfig = readMixerConfig; const writeMixerConfig = async (port, config) => { const buffer = new msp_1.WriteBuffer(); const api = (0, msp_1.apiVersion)(port); buffer.push8(config.mixer); if (semver_1.default.gte(api, "1.36.0")) { buffer.push8(config.reversedMotors ? 1 : 0); } await (0, msp_1.execute)(port, { code: codes_1.default.MSP_SET_MIXER_CONFIG, data: buffer }); }; exports.writeMixerConfig = writeMixerConfig; exports.writePartialMixerConfig = (0, utils_1.partialWriteFunc)(exports.readMixerConfig, exports.writeMixerConfig); //# sourceMappingURL=index.js.map