diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 2fa6fc2bb..c473e16ca 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -812,6 +812,113 @@ static int luaCrossfireTelemetryPush(lua_State * L) } #endif +#if defined(GHOST) +/*luadoc +@function ghostTelemetryPop() + +Pops a received Ghost Telemetry packet from the queue. + +@retval nil queue does not contain any (or enough) bytes to form a whole packet + +@retval multiple returns 2 values: + * type (number) + * packet (table) data bytes + +@status current Introduced in 2.7.0 +*/ +static int luaGhostTelemetryPop(lua_State * L) +{ + if (!luaInputTelemetryFifo) { + luaInputTelemetryFifo = new Fifo(); + if (!luaInputTelemetryFifo) { + return 0; + } + } + + uint8_t length = 0, data = 0; + if (luaInputTelemetryFifo->probe(length) && luaInputTelemetryFifo->size() >= uint32_t(length)) { + // length value includes type(1B), payload, crc(1B) + luaInputTelemetryFifo->pop(length); + luaInputTelemetryFifo->pop(data); // type + lua_pushnumber(L, data); // return type + lua_newtable(L); + for (uint8_t i=0; ipop(data); + lua_pushinteger(L, i+1); + lua_pushinteger(L, data); + lua_settable(L, -3); + } + return 2; + } + + return 0; +} + +/*luadoc +@function ghostTelemetryPush() + +This functions allows for sending telemetry data toward the Ghost link. + +When called without parameters, it will only return the status of the output buffer without sending anything. + +@param command command + +@param data table of data bytes + +@retval boolean data queued in output buffer or not. + +@retval nil incorrect telemetry protocol. + +@status current Introduced in 2.7.0 +*/ +static int luaGhostTelemetryPush(lua_State * L) +{ + bool sport = (telemetryProtocol == PROTOCOL_TELEMETRY_GHOST); + + if (!sport) { + lua_pushnil(L); + return 1; + } + + if (lua_gettop(L) == 0) { + lua_pushboolean(L, outputTelemetryBuffer.isAvailable()); + } + else if (lua_gettop(L) > TELEMETRY_OUTPUT_BUFFER_SIZE ) { + lua_pushboolean(L, false); + return 1; + } + else if (outputTelemetryBuffer.isAvailable()) { + uint8_t type = luaL_checkunsigned(L, 1); + luaL_checktype(L, 2, LUA_TTABLE); + uint8_t length = luaL_len(L, 2); // payload length + + if( length > 10 ) { // max 10B payload + lua_pushboolean(L, false); + return 1; + } + + // Ghost frames are fixed 14B + outputTelemetryBuffer.pushByte(getGhostModuleAddr()); // addr (1B) + outputTelemetryBuffer.pushByte(12); // len = payload length(10B) + type(1B) + crc(1B) + outputTelemetryBuffer.pushByte(type); // type (1B) + for (int i=0; ipulses, outputTelemetryBuffer.data, outputTelemetryBuffer.size); + p_data->length = outputTelemetryBuffer.size; + outputTelemetryBuffer.reset(); + } else + #endif if (moduleState[EXTERNAL_MODULE].counter == GHST_MENU_CONTROL) { - extmodulePulsesData.ghost.length = createGhostMenuControlFrame(pulses, &channelOutputs[module.channelsStart]); + p_data->length = createGhostMenuControlFrame(p_data->pulses, &channelOutputs[module.channelsStart]); } else { - extmodulePulsesData.ghost.length = createGhostChannelsFrame(pulses, &channelOutputs[module.channelsStart], module.ghost.raw12bits); + p_data->length = createGhostChannelsFrame(p_data->pulses, &channelOutputs[module.channelsStart], module.ghost.raw12bits); } moduleState[EXTERNAL_MODULE].counter = GHST_FRAME_CHANNEL; } diff --git a/radio/src/telemetry/ghost.cpp b/radio/src/telemetry/ghost.cpp index 4734c2758..9ed24c74d 100755 --- a/radio/src/telemetry/ghost.cpp +++ b/radio/src/telemetry/ghost.cpp @@ -302,6 +302,20 @@ void processGhostTelemetryFrame() processGhostTelemetryValue(GHOST_ID_GPS_SATS, telemetryRxBuffer[7]); break; } + case GHST_DL_MAGBARO: { + // Not implemented yet + break; + } +#if defined(LUA) + default: + if (luaInputTelemetryFifo && luaInputTelemetryFifo->hasSpace(telemetryRxBufferCount-2) ) { + for (uint8_t i=1; ipush(telemetryRxBuffer[i]); + } + } + break; +#endif } } diff --git a/radio/src/telemetry/ghost.h b/radio/src/telemetry/ghost.h index 46fb1f16c..870eb765e 100755 --- a/radio/src/telemetry/ghost.h +++ b/radio/src/telemetry/ghost.h @@ -51,6 +51,8 @@ #define GHST_DL_MENU_DESC 0x24 #define GHST_DL_GPS_PRIMARY 0x25 #define GHST_DL_GPS_SECONDARY 0x26 +#define GHST_DL_MAGBARO 0x27 +#define GHST_DL_MSP_RESP 0x28 #define GHST_RC_CTR_VAL_12BIT 0x7C0 // 0x3e0 << 1 #define GHST_RC_CTR_VAL_8BIT 0x7C