mirror of
https://github.com/okalachev/flix.git
synced 2026-01-11 21:46:55 +00:00
Initial commit
This commit is contained in:
34
flix/rc.ino
Normal file
34
flix/rc.ino
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
||||
// Repository: https://github.com/okalachev/flix
|
||||
|
||||
#include <SBUS.h>
|
||||
|
||||
static const uint16_t channelNeutral[] = {995, 883, 200, 972, 512, 512};
|
||||
static const uint16_t channelMax[] = {1651, 1540, 1713, 1630, 1472, 1472};
|
||||
|
||||
static SBUS RC(Serial2);
|
||||
|
||||
void setupRC()
|
||||
{
|
||||
Serial.println("Setup RC");
|
||||
RC.begin();
|
||||
}
|
||||
|
||||
static uint32_t lastReadRC = 0;
|
||||
|
||||
void readRC()
|
||||
{
|
||||
bool failSafe, lostFrame;
|
||||
if (RC.read(channels, &failSafe, &lostFrame)) {
|
||||
if (failSafe) { rcFailSafe++; return; } // TODO: NOT TESTED YET
|
||||
if (lostFrame) { rcLostFrame++; return; }
|
||||
normalizeRC();
|
||||
lastReadRC = stepTime;
|
||||
}
|
||||
}
|
||||
|
||||
static void normalizeRC() {
|
||||
for (uint8_t i = 0; i < RC_CHANNELS; i++) {
|
||||
controls[i] = mapf(channels[i], channelNeutral[i], channelMax[i], 0, 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user