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",
|
"swr_red",
|
||||||
"telemko",
|
"telemko",
|
||||||
"telemok",
|
"telemok",
|
||||||
|
"trainco",
|
||||||
"trainko",
|
"trainko",
|
||||||
"trainok",
|
"trainok",
|
||||||
"sensorko",
|
"sensorko",
|
||||||
|
|||||||
@@ -589,6 +589,7 @@ void audioTimerCountdown(uint8_t timer, int value);
|
|||||||
#define AUDIO_RAS_RED() audioEvent(AU_RAS_RED)
|
#define AUDIO_RAS_RED() audioEvent(AU_RAS_RED)
|
||||||
#define AUDIO_TELEMETRY_LOST() audioEvent(AU_TELEMETRY_LOST)
|
#define AUDIO_TELEMETRY_LOST() audioEvent(AU_TELEMETRY_LOST)
|
||||||
#define AUDIO_TELEMETRY_BACK() audioEvent(AU_TELEMETRY_BACK)
|
#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_LOST() audioEvent(AU_TRAINER_LOST)
|
||||||
#define AUDIO_TRAINER_BACK() audioEvent(AU_TRAINER_BACK)
|
#define AUDIO_TRAINER_BACK() audioEvent(AU_TRAINER_BACK)
|
||||||
|
|
||||||
|
|||||||
@@ -2595,6 +2595,24 @@ static int luaGetOutputValue(lua_State * L)
|
|||||||
return 1;
|
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[] = {
|
const luaL_Reg opentxLib[] = {
|
||||||
{ "getTime", luaGetTime },
|
{ "getTime", luaGetTime },
|
||||||
{ "getDateTime", luaGetDateTime },
|
{ "getDateTime", luaGetDateTime },
|
||||||
@@ -2609,6 +2627,7 @@ const luaL_Reg opentxLib[] = {
|
|||||||
{ "getValue", luaGetValue },
|
{ "getValue", luaGetValue },
|
||||||
{ "getOutputValue", luaGetOutputValue },
|
{ "getOutputValue", luaGetOutputValue },
|
||||||
{ "getSourceValue", luaGetSourceValue },
|
{ "getSourceValue", luaGetSourceValue },
|
||||||
|
{ "getTrainerStatus", luaGetTrainerStatus },
|
||||||
{ "getRAS", luaGetRAS },
|
{ "getRAS", luaGetRAS },
|
||||||
{ "getTxGPS", luaGetTxGPS },
|
{ "getTxGPS", luaGetTxGPS },
|
||||||
{ "getFieldInfo", luaGetFieldInfo },
|
{ "getFieldInfo", luaGetFieldInfo },
|
||||||
|
|||||||
@@ -787,6 +787,7 @@ enum AUDIO_SOUNDS {
|
|||||||
AU_RAS_RED,
|
AU_RAS_RED,
|
||||||
AU_TELEMETRY_LOST,
|
AU_TELEMETRY_LOST,
|
||||||
AU_TELEMETRY_BACK,
|
AU_TELEMETRY_BACK,
|
||||||
|
AU_TRAINER_CONNECTED,
|
||||||
AU_TRAINER_LOST,
|
AU_TRAINER_LOST,
|
||||||
AU_TRAINER_BACK,
|
AU_TRAINER_BACK,
|
||||||
AU_SENSOR_LOST,
|
AU_SENSOR_LOST,
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ int16_t ppmInput[MAX_TRAINER_CHANNELS];
|
|||||||
uint8_t ppmInputValidityTimer;
|
uint8_t ppmInputValidityTimer;
|
||||||
uint8_t currentTrainerMode = 0xff;
|
uint8_t currentTrainerMode = 0xff;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TRAINER_NOT_CONNECTED = 0,
|
||||||
|
TRAINER_CONNECTED,
|
||||||
|
TRAINER_DISCONNECTED,
|
||||||
|
TRAINER_RECONNECTED
|
||||||
|
};
|
||||||
|
uint8_t trainerStatus = TRAINER_NOT_CONNECTED;
|
||||||
|
|
||||||
void checkTrainerSignalWarning()
|
void checkTrainerSignalWarning()
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
@@ -39,13 +47,17 @@ void checkTrainerSignalWarning()
|
|||||||
|
|
||||||
if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
|
if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_NOT_USED)) {
|
||||||
ppmInputValidState = PPM_IN_IS_VALID;
|
ppmInputValidState = PPM_IN_IS_VALID;
|
||||||
|
trainerStatus = TRAINER_CONNECTED;
|
||||||
|
AUDIO_TRAINER_CONNECTED();
|
||||||
}
|
}
|
||||||
else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
|
else if (!ppmInputValidityTimer && (ppmInputValidState == PPM_IN_IS_VALID)) {
|
||||||
ppmInputValidState = PPM_IN_INVALID;
|
ppmInputValidState = PPM_IN_INVALID;
|
||||||
|
trainerStatus = TRAINER_DISCONNECTED;
|
||||||
AUDIO_TRAINER_LOST();
|
AUDIO_TRAINER_LOST();
|
||||||
}
|
}
|
||||||
else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
|
else if (ppmInputValidityTimer && (ppmInputValidState == PPM_IN_INVALID)) {
|
||||||
ppmInputValidState = PPM_IN_IS_VALID;
|
ppmInputValidState = PPM_IN_IS_VALID;
|
||||||
|
trainerStatus = TRAINER_RECONNECTED;
|
||||||
AUDIO_TRAINER_BACK();
|
AUDIO_TRAINER_BACK();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user