Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua function for trainer status #2483

Merged
merged 3 commits into from
Nov 30, 2022
Merged

Lua function for trainer status #2483

merged 3 commits into from
Nov 30, 2022

Conversation

CamGenius
Copy link
Contributor

Summary of changes:
Adds a lua function for getting the status of the trainer input. #627
Also adds a sound function for trainer initial connection.

@pfeerick pfeerick added enhancement ✨ New feature or request lua-api Lua API related labels Oct 6, 2022
@pfeerick pfeerick added this to the 2.9 milestone Oct 6, 2022
@dlktdr
Copy link
Collaborator

dlktdr commented Oct 11, 2022

Testing trainer input fairly often, I like the idea of having the extra voice for trainer connected 👍 It not obvious it's working the first time you connect a device. When you consider some of the previous issues with the trainer jack on TX16s or trying to find the proper PPM input levels, did you pick the right bluetooth address, not having a notification the first time it's working can be highly confusing. (Also need to bring the B&W trainer connected icon on the main title bar (in color).. but that's another issue)

@CamGenius What is the purpose of having disconnected and not_connected? Are these not the same thing?

@CamGenius
Copy link
Contributor Author

I figured a widget could have use to differentiate between not connected and disconnected. For instance not connected could be gray while disconnected could be red.

@pfeerick
Copy link
Member

pfeerick commented Nov 30, 2022

Have tested this with the following dumb widget, and a newly generated trainco.wav on TX16S and both the audio and Lua are working perfectly - tracks initial disconnected state, reponds when the trainer is connected, and then accordingly when disconnected and reconnected. Tracking the initial state, connect and reconnect is excellent, as would allow a widget or standalone lua to track the state of the link and react accordingly.

local options = {
}

local function create(zone, options)
  local widget = { zone=zone, options=options }
  return widget
end

local function update(widget, options)
  widget.options = options
end

local function background(widget)
end

local function refresh(widget)
  local trainerStatus = getTrainerStatus()

  if trainerStatus == 0 then
    lcd.drawText(widget.zone.x, widget.zone.y, "Not Connected", LEFT);
  elseif trainerStatus == 1 then
    lcd.drawText(widget.zone.x, widget.zone.y, "Connected", LEFT);
  elseif trainerStatus == 2 then
    lcd.drawText(widget.zone.x, widget.zone.y, "Disconnected", LEFT);
  elseif trainerStatus == 3 then
    lcd.drawText(widget.zone.x, widget.zone.y, "Reconnected", LEFT);
  else
    lcd.drawText(widget.zone.x, widget.zone.y, "Unknown state", LEFT);
  end
end

return { name="Trainer Status", options=options, create=create, update=update, refresh=refresh, background=background }

@pfeerick pfeerick merged commit becbbac into EdgeTX:main Nov 30, 2022
@BatesKG
Copy link

BatesKG commented Dec 1, 2022

Hi @CamGenius and @pfeerick
I was just trying to do this on the weekend. Awesome!
I was just setting the student Tx to output a max value on Ch10 and was checking for the high value of TR10 on the instructor radio. It was a little flakey though and would randomly cause disconnects when the logical switches didn't see the value for some reason. It was also on openTx but will be updating the instructor radio to ETX this weekend after a successful conversion on the student radio.

One request..... Could you please add one extra line to the script to insert the numerical value of 'trainerstatus' into a telemetry or global variable on the radio that logical switches could reference?
I have my system set up so that it automatically announces a disconnect and passes control back to the instructor if the trainer link is lost. I'm also testing the trainer link exists before allowing the transfer of control, even if the trainer switch is activated.
Thanks!
KevinB

@pfeerick
Copy link
Member

pfeerick commented Dec 2, 2022

I'm not sure that is the best way to do it... probably better to have a lua widget or some other script do that sort of conversion - it's not telemetry as such, and sending it to a GV then begs the question "which GV" and "who else is going to complain we've just clobbered GV# that they use for XYZ"

e.g. The flight modes widget uses GV9 IIRC (to store the persistent flight counter). I suggest instead that perhaps a "trainer" widget needs to be developed, and as part of that an option to push the trainer state to a (configurable) GV.

@BatesKG
Copy link

BatesKG commented Dec 2, 2022

Yes, I totally agree that the best approach would be a widget that you can configure to put the 'trainerstatus' into the GV of your choice. By default, it wouldn't push the value to any GV so other scripts aren't clobbered. The user would need to make a config selection to choose the GV to use.
From the code above, it looks like the "trainer widget" is over 50% done already? :)

mha1 pushed a commit to mha1/edgetx that referenced this pull request Dec 22, 2022
* Initial Commit

* Finished Trainer Status

* fix: Bump version number

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request lua-api Lua API related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants