From 66693914d186d20c4a1c5dc0f0639e825b39f29a Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Thu, 19 Apr 2018 11:18:36 +0200 Subject: [PATCH] improed processing of sbus frames --- .vscode/arduino.json | 2 +- .vscode/c_cpp_properties.json | 5 ++++- crossbow/crossbow.ino | 1 - crossbow/sbus.cpp | 8 +++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.vscode/arduino.json b/.vscode/arduino.json index 470c2cf..e8e6b14 100644 --- a/.vscode/arduino.json +++ b/.vscode/arduino.json @@ -1,6 +1,6 @@ { "board": "bsfrance:avr:lora32u4", "sketch": "crossbow/crossbow.ino", - "port": "COM3", + "port": "COM7", "output": "../build" } \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index cfa69c7..8e3b549 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -14,7 +14,10 @@ "intelliSenseMode": "msvc-x64", "cStandard": "c11", "cppStandard": "c++17", - "compilerPath": "/usr/bin/clang" + "compilerPath": "/usr/bin/clang", + "defines": [ + "FEATURE_TX_INPUT_SBUS" + ] }, { "name": "Mac", diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index a880816..3c2f32f 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -8,7 +8,6 @@ Copyright (c) 20xx, MPL Contributor1 contrib1@example.net #include "config.h" - #include "lora.h" #include "variables.h" #include "main_variables.h" diff --git a/crossbow/sbus.cpp b/crossbow/sbus.cpp index c1fb430..881ccbc 100644 --- a/crossbow/sbus.cpp +++ b/crossbow/sbus.cpp @@ -21,12 +21,14 @@ equivalent to map(channels[i], RC_CHANNEL_MIN, RC_CHANNEL_MAX, SBUS_MIN_OFFSET, SBUS_MAX_OFFSET); */ int mapChannelToSbus(int in) { - return (((long) in * 1605l) / 1000l) - 1417; + return ((long) in * 1605l / 1000l) - 1417; } +/* +Precomputed mapping from 173:1811 to 990-2010 +*/ int mapSbusToChannel(int in) { - //TODO, speed up this processing - return map(in, 173, 1811, 990, 2010); + return (((long) in - 173l) * 1020l / 1638l) + 990; } void sbusPreparePacket(uint8_t packet[], int16_t channels[], bool isSignalLoss, bool isFailsafe){