Skip to content

Add support for smix reverse #4388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,19 @@ MspHelper.prototype.process_data = function (dataHandler) {
}
break;
case MSPCodes.MSP_SERVO_MIX_RULES:
FC.SERVO_RULES = []; // empty the array as new data is coming in
for (let i = 0; i < 16; i++) {
const array = {
targetChannel: data.readU8(),
inputSource: data.readU8(),
rate: data.readU8(),
speed: data.readU8(),
min: data.readU8(),
max: data.readU8(),
box: data.readU8(),
};
FC.SERVO_RULES.push(array);
}
break;

case MSPCodes.MSP_SERVO_CONFIGURATIONS:
Expand Down Expand Up @@ -2521,6 +2534,7 @@ MspHelper.prototype.sendServoConfigurations = function (onCompleteCallback) {
if (out == undefined) {
out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF"
}

buffer.push8(out).push32(servoConfiguration.reversedInputSources);

// prepare for next iteration
Expand Down
28 changes: 22 additions & 6 deletions src/js/tabs/servos.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { gui_log } from "../gui_log";
import $ from "jquery";

const servos = {};

servos.initialize = function (callback) {
if (GUI.active_tab !== "servos") {
GUI.active_tab = "servos";
Expand Down Expand Up @@ -42,19 +43,22 @@ servos.initialize = function (callback) {

$(".tab-servos").addClass("supported");

let servoCheckbox = "";
// setup header
let servoHeader = "";
for (let i = 0; i < FC.RC.active_channels - 4; i++) {
servoHeader += `<th>A${i + 1}</th>`;
}

servoHeader += '<th style="width: 110px" i18n="servosRateAndDirection"></th>';

$("div.tab-servos table.fields tr.main").append(servoHeader);

// setup checkboxes
let servoCheckbox = "";
for (let i = 0; i < FC.RC.active_channels; i++) {
servoCheckbox += `<td class="channel"><input type="checkbox"/></td>`;
servoCheckbox += `<td class="channel" id="channel${i}"><input type="checkbox"/></td>`;
}

$("div.tab-servos table.fields tr.main").append(servoHeader);

/*
* function: void process_servos(string, object)
*/
Expand Down Expand Up @@ -93,6 +97,19 @@ servos.initialize = function (callback) {

$("div.tab-servos table.fields tr:last").data("info", { obj: obj });

// check if input sources are reversed
for (const rule of FC.SERVO_RULES) {
const inputSource = rule.inputSource;
const reversed = FC.SERVO_CONFIG[obj].reversedInputSources & (1 << inputSource);
if (reversed) {
FC.SERVO_CONFIG[obj].reversedInputSources |= 1 << inputSource;
const inputSourceElement = $(`#channel${inputSource}`).find("input");
if (inputSourceElement) {
inputSourceElement.prop("checked", true).parent().css("background-color", "red");
}
}
}

// UI hooks

// only one checkbox for indicating a channel to forward can be selected at a time, perhaps a radio group would be best here.
Expand Down Expand Up @@ -123,8 +140,7 @@ servos.initialize = function (callback) {
FC.SERVO_CONFIG[info.obj].min = parseInt($(".min input", this).val());
FC.SERVO_CONFIG[info.obj].max = parseInt($(".max input", this).val());

const val = parseInt($(".direction select", this).val());
FC.SERVO_CONFIG[info.obj].rate = val;
FC.SERVO_CONFIG[info.obj].rate = parseInt($(".direction select", this).val());
});

//
Expand Down