1
0
Fork 0
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:
Bertrand Songis 2016-03-05 00:27:13 +01:00
commit a7d0816ac7
17 changed files with 131 additions and 70 deletions

View file

@ -28,7 +28,7 @@
OS_TID cliTaskId;
TaskStack<CLI_STACK_SIZE> cliStack;
Fifo<256> cliRxFifo;
Fifo<uint8_t, 256> cliRxFifo;
uint8_t cliTracesEnabled = true;
// char cliLastLine[CLI_COMMAND_MAX_LEN+1];

View file

@ -27,7 +27,7 @@ extern uint8_t cliTracesEnabled;
#ifdef __cplusplus
#include "fifo.h"
extern Fifo<256> cliRxFifo;
extern Fifo<uint8_t, 256> cliRxFifo;
#include "tasks_arm.h"
#define CLI_STACK_SIZE 1000
extern TaskStack<CLI_STACK_SIZE> cliStack;

View file

@ -21,7 +21,7 @@
#ifndef _FIFO_H_
#define _FIFO_H_
template <int N>
template <class T, int N>
class Fifo
{
public:
@ -36,20 +36,20 @@ class Fifo
widx = ridx = 0;
}
void push(uint8_t byte) {
void push(T element) {
uint32_t next = (widx+1) & (N-1);
if (next != ridx) {
fifo[widx] = byte;
fifo[widx] = element;
widx = next;
}
}
bool pop(uint8_t & byte) {
bool pop(T & element) {
if (isEmpty()) {
return false;
}
else {
byte = fifo[ridx];
element = fifo[ridx];
ridx = (ridx+1) & (N-1);
return true;
}
@ -69,7 +69,7 @@ class Fifo
}
protected:
uint8_t fifo[N];
T fifo[N];
volatile uint32_t widx;
volatile uint32_t ridx;
};

View file

@ -326,6 +326,41 @@ bool luaFindFieldByName(const char * name, LuaField & field, unsigned int flags)
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
@function getFieldInfo(name)
@ -795,6 +830,8 @@ const luaL_Reg opentxLib[] = {
#if !defined(COLORLCD)
{ "GREY", luaGrey },
#endif
{ "telemetryPop", luaTelemetryPop },
{ "telemetryPush", luaTelemetryPush },
{ NULL, NULL } /* sentinel */
};

View file

@ -33,7 +33,7 @@
#define SBUS_CH_CENTER 0x3E0
Fifo<32> sbusFifo;
Fifo<uint8_t, 32> sbusFifo;
uint8_t SbusFrame[SBUS_MAX_FRAME_SIZE];
uint16_t SbusTimer ;
uint8_t SbusIndex = 0 ;

View file

@ -18,12 +18,12 @@
* GNU General Public License for more details.
*/
#include "../../opentx.h"
#include "opentx.h"
uint8_t serial2Mode = 0;
Fifo<512> serial2TxFifo;
extern Fifo<512> telemetryFifo;
extern Fifo<32> sbusFifo;
Fifo<uint8_t, 512> serial2TxFifo;
extern Fifo<uint8_t, 512> telemetryFifo;
extern Fifo<uint8_t, 32> sbusFifo;
void uart3Setup(unsigned int baudrate)
{

View file

@ -20,7 +20,7 @@
#include "../../opentx.h"
extern Fifo<512> telemetryFifo;
extern Fifo<uint8_t, 512> telemetryFifo;
void telemetryPortInit(uint32_t baudrate)
{

View file

@ -18,9 +18,9 @@
* 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)

View file

@ -28,7 +28,7 @@
/** Pins description corresponding to Rxd,Txd, (UART pins) */
#define SECOND_SERIAL_PINS {PINS_UART}
Fifo<512> serial2RxFifo;
Fifo<uint8_t, 512> serial2RxFifo;
#if !defined(SIMU)
/*

View file

@ -20,8 +20,8 @@
#include "../../opentx.h"
Fifo<64> btTxFifo;
Fifo<64> btRxFifo;
Fifo<uint8_t, 64> btTxFifo;
Fifo<uint8_t, 64> btRxFifo;
enum BluetoothState
{

View file

@ -21,9 +21,9 @@
#include "../../opentx.h"
uint8_t serial2Mode = 0;
Fifo<512> serial2TxFifo;
extern Fifo<512> telemetryFifo;
extern Fifo<32> sbusFifo;
Fifo<uint8_t, 512> serial2TxFifo;
extern Fifo<uint8_t, 512> telemetryFifo;
extern Fifo<uint8_t, 32> sbusFifo;
void uart3Setup(unsigned int baudrate)
{

View file

@ -20,7 +20,7 @@
#include "../../opentx.h"
extern Fifo<512> telemetryFifo;
extern Fifo<uint8_t, 512> telemetryFifo;
void telemetryPortInit(uint32_t baudrate)
{

View file

@ -20,7 +20,7 @@
#include "../../opentx.h"
extern Fifo<32> sbusFifo;
extern Fifo<uint8_t, 32> sbusFifo;
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)

View file

@ -44,7 +44,7 @@ uint8_t telemetryState = TELEMETRY_INIT;
#endif
#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
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);
}
#if defined(LUA)
Fifo<LuaTelemetryValue, 16> * luaInputTelemetryFifo = NULL;
Fifo<LuaTelemetryValue, 16> * luaOutputTelemetryFifo = NULL;
#endif

View file

@ -139,6 +139,8 @@
#define POWERBOX_STATE_LAST_ID 0x0b2f
#define POWERBOX_CNSP_FIRST_ID 0x0b30
#define POWERBOX_CNSP_LAST_ID 0x0b3f
#define DIY_FIRST_ID 0x5000
#define DIY_LAST_ID 0x50ff
#define RSSI_ID 0xf101
#define ADC1_ID 0xf102
#define ADC2_ID 0xf103
@ -344,7 +346,6 @@ struct FrskyData {
};
#endif
#if defined(PCBTARANIS) && defined(REVPLUS)
#define IS_VALID_XJT_VERSION() (frskyData.xjtVersion != 0 && frskyData.xjtVersion != 0xff)
#else
@ -553,4 +554,15 @@ void processSerialData(uint8_t data);
#define MODEL_TELEMETRY_PROTOCOL() g_model.telemetryProtocol
#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_

View file

@ -269,6 +269,13 @@ void processSportPacket(uint8_t * packet)
processSportPacket(id, 6, instance, bool(data & 0x2000000));
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 {
processSportPacket(id, 0, instance, data);
}

View file

@ -21,7 +21,7 @@
#ifndef _TELEMETRY_H_
#define _TELEMETRY_H_
extern Fifo<512> telemetryFifo;
extern Fifo<uint8_t, 512> telemetryFifo;
enum TelemetryProtocol
{