Skip to content

Commit

Permalink
Add mspGetOptionalIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
pmattila committed Nov 19, 2024
1 parent 099f71d commit fcb42e2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ typedef unsigned char uchar;

typedef uint32_t bitmap_t;
typedef uint64_t bitmap64_t;

typedef struct {
int min;
int max;
} range_t;

17 changes: 17 additions & 0 deletions src/main/msp/msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,23 @@ static bool mspProcessOutCommand(int16_t cmdMSP, sbuf_t *dst)
return !unsupportedCommand;
}

void mspGetOptionalIndex(sbuf_t *src, const range_t *range, int *value)
{
if (sbufBytesRemaining(src) > 0) {
*value = constrain(sbufReadU8(src), range->min, range->max);
}
}

void mspGetOptionalIndexRange(sbuf_t *src, const range_t *range, range_t *value)
{
if (sbufBytesRemaining(src) > 0) {
value->min = value->max = constrain(sbufReadU8(src), range->min, range->max);
if (sbufBytesRemaining(src) > 0) {
value->max = constrain(sbufReadU8(src), value->min, range->max);
}
}
}

static mspResult_e mspFcProcessOutCommandWithArg(mspDescriptor_t srcDesc, int16_t cmdMSP, sbuf_t *src, sbuf_t *dst, mspPostProcessFnPtr *mspPostProcessFn)
{

Expand Down

0 comments on commit fcb42e2

Please sign in to comment.