mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 20:35:17 +03:00
Merge pull request #3326 from opentx/bsongis/passthrough_sport_to_lua
Bsongis/passthrough sport to lua
This commit is contained in:
commit
a7d0816ac7
17 changed files with 131 additions and 70 deletions
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
OS_TID cliTaskId;
|
OS_TID cliTaskId;
|
||||||
TaskStack<CLI_STACK_SIZE> cliStack;
|
TaskStack<CLI_STACK_SIZE> cliStack;
|
||||||
Fifo<256> cliRxFifo;
|
Fifo<uint8_t, 256> cliRxFifo;
|
||||||
uint8_t cliTracesEnabled = true;
|
uint8_t cliTracesEnabled = true;
|
||||||
// char cliLastLine[CLI_COMMAND_MAX_LEN+1];
|
// char cliLastLine[CLI_COMMAND_MAX_LEN+1];
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ extern uint8_t cliTracesEnabled;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
extern Fifo<256> cliRxFifo;
|
extern Fifo<uint8_t, 256> cliRxFifo;
|
||||||
#include "tasks_arm.h"
|
#include "tasks_arm.h"
|
||||||
#define CLI_STACK_SIZE 1000
|
#define CLI_STACK_SIZE 1000
|
||||||
extern TaskStack<CLI_STACK_SIZE> cliStack;
|
extern TaskStack<CLI_STACK_SIZE> cliStack;
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _FIFO_H_
|
|
||||||
#define _FIFO_H_
|
|
||||||
|
|
||||||
template <int N>
|
#ifndef _FIFO_H_
|
||||||
|
#define _FIFO_H_
|
||||||
|
|
||||||
|
template <class T, int N>
|
||||||
class Fifo
|
class Fifo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -36,20 +36,20 @@ class Fifo
|
||||||
widx = ridx = 0;
|
widx = ridx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void push(uint8_t byte) {
|
void push(T element) {
|
||||||
uint32_t next = (widx+1) & (N-1);
|
uint32_t next = (widx+1) & (N-1);
|
||||||
if (next != ridx) {
|
if (next != ridx) {
|
||||||
fifo[widx] = byte;
|
fifo[widx] = element;
|
||||||
widx = next;
|
widx = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pop(uint8_t & byte) {
|
bool pop(T & element) {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
byte = fifo[ridx];
|
element = fifo[ridx];
|
||||||
ridx = (ridx+1) & (N-1);
|
ridx = (ridx+1) & (N-1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,9 @@ class Fifo
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint8_t fifo[N];
|
T fifo[N];
|
||||||
volatile uint32_t widx;
|
volatile uint32_t widx;
|
||||||
volatile uint32_t ridx;
|
volatile uint32_t ridx;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _FIFO_H_
|
#endif // _FIFO_H_
|
||||||
|
|
|
@ -326,6 +326,41 @@ bool luaFindFieldByName(const char * name, LuaField & field, unsigned int flags)
|
||||||
return false; // not found
|
return false; // not found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int luaTelemetryPop(lua_State *L)
|
||||||
|
{
|
||||||
|
if (!luaInputTelemetryFifo) {
|
||||||
|
luaInputTelemetryFifo = new Fifo<LuaTelemetryValue, 16>();
|
||||||
|
if (!luaInputTelemetryFifo) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LuaTelemetryValue value;
|
||||||
|
if (luaInputTelemetryFifo->pop(value)) {
|
||||||
|
lua_pushnumber(L, value.id);
|
||||||
|
lua_pushunsigned(L, value.value);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int luaTelemetryPush(lua_State *L)
|
||||||
|
{
|
||||||
|
if (!luaOutputTelemetryFifo) {
|
||||||
|
luaOutputTelemetryFifo = new Fifo<LuaTelemetryValue, 16>();
|
||||||
|
if (!luaOutputTelemetryFifo) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int id = luaL_checkunsigned(L, 1);
|
||||||
|
unsigned int value = luaL_checkunsigned(L, 2);
|
||||||
|
|
||||||
|
luaOutputTelemetryFifo->push((LuaTelemetryValue){ id, value });
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*luadoc
|
/*luadoc
|
||||||
@function getFieldInfo(name)
|
@function getFieldInfo(name)
|
||||||
|
|
||||||
|
@ -795,6 +830,8 @@ const luaL_Reg opentxLib[] = {
|
||||||
#if !defined(COLORLCD)
|
#if !defined(COLORLCD)
|
||||||
{ "GREY", luaGrey },
|
{ "GREY", luaGrey },
|
||||||
#endif
|
#endif
|
||||||
|
{ "telemetryPop", luaTelemetryPop },
|
||||||
|
{ "telemetryPush", luaTelemetryPush },
|
||||||
{ NULL, NULL } /* sentinel */
|
{ NULL, NULL } /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
#define SBUS_CH_CENTER 0x3E0
|
#define SBUS_CH_CENTER 0x3E0
|
||||||
|
|
||||||
Fifo<32> sbusFifo;
|
Fifo<uint8_t, 32> sbusFifo;
|
||||||
uint8_t SbusFrame[SBUS_MAX_FRAME_SIZE];
|
uint8_t SbusFrame[SBUS_MAX_FRAME_SIZE];
|
||||||
uint16_t SbusTimer ;
|
uint16_t SbusTimer ;
|
||||||
uint8_t SbusIndex = 0 ;
|
uint8_t SbusIndex = 0 ;
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) OpenTX
|
* Copyright (C) OpenTX
|
||||||
*
|
*
|
||||||
* Based on code named
|
* Based on code named
|
||||||
* th9x - http://code.google.com/p/th9x
|
* th9x - http://code.google.com/p/th9x
|
||||||
* er9x - http://code.google.com/p/er9x
|
* er9x - http://code.google.com/p/er9x
|
||||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
*
|
*
|
||||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
* published by the Free Software Foundation.
|
* published by the Free Software Foundation.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
uint8_t serial2Mode = 0;
|
uint8_t serial2Mode = 0;
|
||||||
Fifo<512> serial2TxFifo;
|
Fifo<uint8_t, 512> serial2TxFifo;
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<uint8_t, 512> telemetryFifo;
|
||||||
extern Fifo<32> sbusFifo;
|
extern Fifo<uint8_t, 32> sbusFifo;
|
||||||
|
|
||||||
void uart3Setup(unsigned int baudrate)
|
void uart3Setup(unsigned int baudrate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<uint8_t, 512> telemetryFifo;
|
||||||
|
|
||||||
void telemetryPortInit(uint32_t baudrate)
|
void telemetryPortInit(uint32_t baudrate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
extern Fifo<32> sbusFifo;
|
extern Fifo<uint8_t, 32> sbusFifo;
|
||||||
|
|
||||||
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
|
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
/** Pins description corresponding to Rxd,Txd, (UART pins) */
|
/** Pins description corresponding to Rxd,Txd, (UART pins) */
|
||||||
#define SECOND_SERIAL_PINS {PINS_UART}
|
#define SECOND_SERIAL_PINS {PINS_UART}
|
||||||
|
|
||||||
Fifo<512> serial2RxFifo;
|
Fifo<uint8_t, 512> serial2RxFifo;
|
||||||
|
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
Fifo<64> btTxFifo;
|
Fifo<uint8_t, 64> btTxFifo;
|
||||||
Fifo<64> btRxFifo;
|
Fifo<uint8_t, 64> btRxFifo;
|
||||||
|
|
||||||
enum BluetoothState
|
enum BluetoothState
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
uint8_t serial2Mode = 0;
|
uint8_t serial2Mode = 0;
|
||||||
Fifo<512> serial2TxFifo;
|
Fifo<uint8_t, 512> serial2TxFifo;
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<uint8_t, 512> telemetryFifo;
|
||||||
extern Fifo<32> sbusFifo;
|
extern Fifo<uint8_t, 32> sbusFifo;
|
||||||
|
|
||||||
void uart3Setup(unsigned int baudrate)
|
void uart3Setup(unsigned int baudrate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<uint8_t, 512> telemetryFifo;
|
||||||
|
|
||||||
void telemetryPortInit(uint32_t baudrate)
|
void telemetryPortInit(uint32_t baudrate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
extern Fifo<32> sbusFifo;
|
extern Fifo<uint8_t, 32> sbusFifo;
|
||||||
|
|
||||||
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
|
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ uint8_t telemetryState = TELEMETRY_INIT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
|
#if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
|
||||||
Fifo<512> telemetryFifo; // TODO should be in the driver
|
Fifo<uint8_t, 512> telemetryFifo; // TODO should be in the driver
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t frskyRxBufferCount = 0;
|
uint8_t frskyRxBufferCount = 0;
|
||||||
|
@ -665,3 +665,8 @@ NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm)
|
||||||
{
|
{
|
||||||
return (45 - 3*alarm + g_model.frsky.rssiAlarms[alarm].value);
|
return (45 - 3*alarm + g_model.frsky.rssiAlarms[alarm].value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(LUA)
|
||||||
|
Fifo<LuaTelemetryValue, 16> * luaInputTelemetryFifo = NULL;
|
||||||
|
Fifo<LuaTelemetryValue, 16> * luaOutputTelemetryFifo = NULL;
|
||||||
|
#endif
|
||||||
|
|
|
@ -139,6 +139,8 @@
|
||||||
#define POWERBOX_STATE_LAST_ID 0x0b2f
|
#define POWERBOX_STATE_LAST_ID 0x0b2f
|
||||||
#define POWERBOX_CNSP_FIRST_ID 0x0b30
|
#define POWERBOX_CNSP_FIRST_ID 0x0b30
|
||||||
#define POWERBOX_CNSP_LAST_ID 0x0b3f
|
#define POWERBOX_CNSP_LAST_ID 0x0b3f
|
||||||
|
#define DIY_FIRST_ID 0x5000
|
||||||
|
#define DIY_LAST_ID 0x50ff
|
||||||
#define RSSI_ID 0xf101
|
#define RSSI_ID 0xf101
|
||||||
#define ADC1_ID 0xf102
|
#define ADC1_ID 0xf102
|
||||||
#define ADC2_ID 0xf103
|
#define ADC2_ID 0xf103
|
||||||
|
@ -344,7 +346,6 @@ struct FrskyData {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) && defined(REVPLUS)
|
#if defined(PCBTARANIS) && defined(REVPLUS)
|
||||||
#define IS_VALID_XJT_VERSION() (frskyData.xjtVersion != 0 && frskyData.xjtVersion != 0xff)
|
#define IS_VALID_XJT_VERSION() (frskyData.xjtVersion != 0 && frskyData.xjtVersion != 0xff)
|
||||||
#else
|
#else
|
||||||
|
@ -553,4 +554,15 @@ void processSerialData(uint8_t data);
|
||||||
#define MODEL_TELEMETRY_PROTOCOL() g_model.telemetryProtocol
|
#define MODEL_TELEMETRY_PROTOCOL() g_model.telemetryProtocol
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LUA)
|
||||||
|
struct LuaTelemetryValue
|
||||||
|
{
|
||||||
|
uint8_t id;
|
||||||
|
uint32_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Fifo<LuaTelemetryValue, 16> * luaInputTelemetryFifo;
|
||||||
|
extern Fifo<LuaTelemetryValue, 16> * luaOutputTelemetryFifo;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // _FRSKY_H_
|
#endif // _FRSKY_H_
|
||||||
|
|
|
@ -269,6 +269,13 @@ void processSportPacket(uint8_t * packet)
|
||||||
processSportPacket(id, 6, instance, bool(data & 0x2000000));
|
processSportPacket(id, 6, instance, bool(data & 0x2000000));
|
||||||
processSportPacket(id, 7, instance, bool(data & 0x4000000));
|
processSportPacket(id, 7, instance, bool(data & 0x4000000));
|
||||||
}
|
}
|
||||||
|
else if (id >= DIY_FIRST_ID && id <= DIY_LAST_ID) {
|
||||||
|
#if defined(LUA)
|
||||||
|
if (luaInputTelemetryFifo) {
|
||||||
|
luaInputTelemetryFifo->push((LuaTelemetryValue){(uint8_t)id, data});
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
processSportPacket(id, 0, instance, data);
|
processSportPacket(id, 0, instance, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#ifndef _TELEMETRY_H_
|
#ifndef _TELEMETRY_H_
|
||||||
#define _TELEMETRY_H_
|
#define _TELEMETRY_H_
|
||||||
|
|
||||||
extern Fifo<512> telemetryFifo;
|
extern Fifo<uint8_t, 512> telemetryFifo;
|
||||||
|
|
||||||
enum TelemetryProtocol
|
enum TelemetryProtocol
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue