mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 05:03:34 +08:00
simple mixer: make output scalers O: optional and use default values instead
Reduces FLASH usage by about 4KB Command to replace: for i in *.mix; do sed -r -i '/O: +10000 +10000 +0 +-10000 +10000/d' $i; done
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "mixer.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <ctype.h>
|
||||
|
||||
#define debug(fmt, args...) do { } while(0)
|
||||
//#define debug(fmt, args...) do { printf("[mixer] " fmt "\n", ##args); } while(0)
|
||||
@@ -125,6 +126,21 @@ Mixer::findtag(const char *buf, unsigned &buflen, char tag)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char
|
||||
Mixer::findnexttag(const char *buf, unsigned buflen)
|
||||
{
|
||||
while (buflen >= 2) {
|
||||
if (isupper(buf[0]) && buf[1] == ':') {
|
||||
return buf[0];
|
||||
}
|
||||
|
||||
buf++;
|
||||
buflen--;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *
|
||||
Mixer::skipline(const char *buf, unsigned &buflen)
|
||||
{
|
||||
|
||||
@@ -265,6 +265,14 @@ protected:
|
||||
*/
|
||||
static const char *findtag(const char *buf, unsigned &buflen, char tag);
|
||||
|
||||
/**
|
||||
* Find next tag and return it (0 is returned if no tag is found)
|
||||
*
|
||||
* @param buf The buffer to operate on.
|
||||
* @param buflen length of the buffer.
|
||||
*/
|
||||
static char findnexttag(const char *buf, unsigned buflen);
|
||||
|
||||
/**
|
||||
* Skip a line
|
||||
*
|
||||
@@ -340,6 +348,7 @@ public:
|
||||
* M: <control count>
|
||||
* O: <-ve scale> <+ve scale> <offset> <lower limit> <upper limit>
|
||||
*
|
||||
* The second line O: can be omitted. In that case 'O: 10000 10000 0 -10000 10000' is used.
|
||||
* The definition continues with <control count> entries describing the control
|
||||
* inputs and their scaling, in the form:
|
||||
*
|
||||
|
||||
@@ -151,6 +151,7 @@ SimpleMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, c
|
||||
unsigned inputs;
|
||||
int used;
|
||||
const char *end = buf + buflen;
|
||||
char next_tag;
|
||||
|
||||
/* enforce that the mixer ends with a new line */
|
||||
if (!string_well_formed(buf, buflen)) {
|
||||
@@ -163,6 +164,12 @@ SimpleMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, c
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* at least 1 input is required */
|
||||
if (inputs == 0) {
|
||||
debug("simple parse got 0 inputs");
|
||||
goto out;
|
||||
}
|
||||
|
||||
buf = skipline(buf, buflen);
|
||||
|
||||
if (buf == nullptr) {
|
||||
@@ -179,9 +186,27 @@ SimpleMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, c
|
||||
|
||||
mixinfo->control_count = inputs;
|
||||
|
||||
if (parse_output_scaler(end - buflen, buflen, mixinfo->output_scaler)) {
|
||||
debug("simple mixer parser failed parsing out scaler tag, ret: '%s'", buf);
|
||||
goto out;
|
||||
/* find the next tag */
|
||||
next_tag = findnexttag(end - buflen, buflen);
|
||||
|
||||
if (next_tag == 'S') {
|
||||
|
||||
/* No output scalers specified. Use default values.
|
||||
* Corresponds to:
|
||||
* O: 10000 10000 0 -10000 10000
|
||||
*/
|
||||
mixinfo->output_scaler.negative_scale = 1.0f;
|
||||
mixinfo->output_scaler.positive_scale = 1.0f;
|
||||
mixinfo->output_scaler.offset = 0.f;
|
||||
mixinfo->output_scaler.min_output = -1.0f;
|
||||
mixinfo->output_scaler.max_output = 1.0f;
|
||||
|
||||
} else {
|
||||
|
||||
if (parse_output_scaler(end - buflen, buflen, mixinfo->output_scaler)) {
|
||||
debug("simple mixer parser failed parsing out scaler tag, ret: '%s'", buf);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < inputs; i++) {
|
||||
|
||||
Reference in New Issue
Block a user