feat(lua): Add getTrainerStatus to Lua API (#2483)
* Initial Commit * Finished Trainer Status * fix: Bump version number Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
co-authored by
Peter Feerick
parent
14c9a6fc9a
commit
becbbac2cb
@@ -191,6 +191,7 @@ const char * const audioFilenames[] = {
|
||||
"swr_red",
|
||||
"telemko",
|
||||
"telemok",
|
||||
"trainco",
|
||||
"trainko",
|
||||
"trainok",
|
||||
"sensorko",
|
||||
|
||||
@@ -589,6 +589,7 @@ void audioTimerCountdown(uint8_t timer, int value);
|
||||
#define AUDIO_RAS_RED() audioEvent(AU_RAS_RED)
|
||||
#define AUDIO_TELEMETRY_LOST() audioEvent(AU_TELEMETRY_LOST)
|
||||
#define AUDIO_TELEMETRY_BACK() audioEvent(AU_TELEMETRY_BACK)
|
||||
#define AUDIO_TRAINER_CONNECTED() audioEvent(AU_TRAINER_CONNECTED)
|
||||
#define AUDIO_TRAINER_LOST() audioEvent(AU_TRAINER_LOST)
|
||||
#define AUDIO_TRAINER_BACK() audioEvent(AU_TRAINER_BACK)
|
||||
|
||||
|
||||
@@ -2595,6 +2595,24 @@ static int luaGetOutputValue(lua_State * L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*luadoc
|
||||
@function getTrainerStatus()
|
||||
|
||||
@retval value current output value (number).
|
||||
0 - Not Connected
|
||||
1 - Connected
|
||||
2 - Disconnected
|
||||
3 - Reconnected
|
||||
|
||||
@status current Introduced in 2.9.0
|
||||
*/
|
||||
static int luaGetTrainerStatus(lua_State * L)
|
||||
{
|
||||
extern uint8_t trainerStatus;
|
||||
lua_pushinteger(L, trainerStatus);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg opentxLib[] = {
|
||||
{ "getTime", luaGetTime },
|
||||
{ "getDateTime", luaGetDateTime },
|
||||
@@ -2609,6 +2627,7 @@ const luaL_Reg opentxLib[] = {
|
||||
{ "getValue", luaGetValue },
|
||||
{ "getOutputValue", luaGetOutputValue },
|
||||
{ "getSourceValue", luaGetSourceValue },
|
||||
{ "getTrainerStatus", luaGetTrainerStatus },
|
||||
{ "getRAS", luaGetRAS },
|
||||
{ "getTxGPS", luaGetTxGPS },
|
||||
{ "getFieldInfo", luaGetFieldInfo },
|
||||
|
||||
@@ -787,6 +787,7 @@ enum AUDIO_SOUNDS {
|
||||
AU_RAS_RED,
|
||||
AU_TELEMETRY_LOST,
|
||||
AU_TELEMETRY_BACK,
|
||||
AU_TRAINER_CONNECTED,
|
||||
AU_TRAINER_LOST,
|
||||
AU_TRAINER_BACK,
|
||||
AU_SENSOR_LOST,
|
||||
|
||||
@@ -27,6 +27,14 @@ int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
||||
uint8_t ppmInputValidityTimer;
|
||||
uint8_t currentTrainerMode = 0xff;
|
||||
|
||||
enum {
|
||||
TRAINER_NOT_CONNECTED = 0,
|
||||
TRAINER_CONNECTED,
|
||||
TRAINER_DISCONNECTED,
|
||||
TRAINER_RECONNECTED
|
||||
};
|
||||
uint8_t trainerStatus = TRAINER_NOT_CONNECTED;
|
||||
|
||||
void checkTrainerSignalWarning()
|
||||
{
|
||||
enum {
|
||||
@@ -39,13 +47,17 @@ void checkTrainerSignalWarning()
|
||||
|
||||
if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
trainerStatus = TRAINER_CONNECTED;
|
||||
AUDIO_TRAINER_CONNECTED();
|
||||
}
|
||||
else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
|
||||
ppmInputValidState = PPM_IN_INVALID;
|
||||
trainerStatus = TRAINER_DISCONNECTED;
|
||||
AUDIO_TRAINER_LOST();
|
||||
}
|
||||
else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
|
||||
ppmInputValidState = PPM_IN_IS_VALID;
|
||||
trainerStatus = TRAINER_RECONNECTED;
|
||||
AUDIO_TRAINER_BACK();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user