Skip to content

Commit

Permalink
feat(lua): Add getTrainerStatus to Lua API (#2483)
Browse files Browse the repository at this point in the history
* Initial Commit

* Finished Trainer Status

* fix: Bump version number

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
  • Loading branch information
CamGenius and pfeerick authored Nov 30, 2022
1 parent 14c9a6f commit becbbac
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions radio/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const char * const audioFilenames[] = {
"swr_red",
"telemko",
"telemok",
"trainco",
"trainko",
"trainok",
"sensorko",
Expand Down
1 change: 1 addition & 0 deletions radio/src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 19 additions & 0 deletions radio/src/lua/api_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -2609,6 +2627,7 @@ const luaL_Reg opentxLib[] = {
{ "getValue", luaGetValue },
{ "getOutputValue", luaGetOutputValue },
{ "getSourceValue", luaGetSourceValue },
{ "getTrainerStatus", luaGetTrainerStatus },
{ "getRAS", luaGetRAS },
{ "getTxGPS", luaGetTxGPS },
{ "getFieldInfo", luaGetFieldInfo },
Expand Down
1 change: 1 addition & 0 deletions radio/src/opentx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions radio/src/trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
Expand Down

0 comments on commit becbbac

Please sign in to comment.