Welcome, Guest. Please login or register.
Did you miss your activation email?

News:
Precision Simulator update 10.156 (3 July 2022) is now available.
Navburo update 12 (18 November 2021) is now available.
NG FMC and More is released.

Author Topic: Pushover App- integration with PSX PRINT function?  (Read 4767 times)

andrej

  • Join date: Apr 2012
  • Location: Bratislava, Slovakia
  • Posts: 487
Re: Pushover App- integration with PSX PRINT function?
« Reply #20 on: Sat, 15 Feb 2020 11:11 »
Dear Jeroen,
Thank you for this brief intro. Very useful!
It is greatly appreciated. Similar to the old proverb, “Give a man a fish and you feed him for a day, teach him how to fish and you feed him for a lifetime”, I rather learn to code. :)

Cheers,

Andrej

Jeroen Hoppenbrouwers

  • Moderator
  • Join date: May 2009
  • Location: KTMB
  • Posts: 4457
  • Hoppie designs avionics equipment for airliners.
    • http://www.hoppie.nl/
Re: Pushover App- integration with PSX PRINT function?
« Reply #21 on: Sat, 15 Feb 2020 11:16 »
My pleasure.

Remember that this program, though short, uses a lot of complex techniques such as asynchronous event handling that are guaranteed to make you wonder what's going on here. This is the unfortunate truth of programming, just as of flying an airplane: there is no such thing as an easy start. Once you lift off, it's all-out full everything at once. So I gladly be your instructor on these first flights  :-P


Hoppie
(Simon: I made sure I have barf bags in reach)


PS. And if people push me enough, I will also show how you could FAA-certify this kind of stuff for real-world commercial aviation use under DO-178C, but that may take a few more postings  :-P

simonijs

  • Join date: Oct 2014
  • Location: Amsterdam
  • Posts: 169
Re: Pushover App- integration with PSX PRINT function?
« Reply #22 on: Sat, 15 Feb 2020 17:46 »
 :) Well: I have loads of them at home now, but quitted flying. Shall I send them over?

Groet,
Simon

cavaricooper

  • Join date: Dec 2009
  • Location: KTPA
  • Posts: 1260
Re: Pushover App- integration with PSX PRINT function?
« Reply #23 on: Sun, 16 Feb 2020 17:45 »
Hoppie-

After a few sessions of head scratching and reading your post over about 50 times, I arrived at



but more importantly this on my iPhone



I can't thank you enough- this is just splendid!

C
Carl Avari-Cooper, KTPA

cavaricooper

  • Join date: Dec 2009
  • Location: KTPA
  • Posts: 1260
Re: Pushover App- integration with PSX PRINT function?
« Reply #24 on: Sun, 16 Feb 2020 18:09 »
Hoppie-

Whilst you are in the teaching mode- is there a way I can make that command prompt py file a clickable executable and assign an icon to it? That way it can be run with a mouse click instead of the keyboard?

Ta- C
Carl Avari-Cooper, KTPA

Jeroen Hoppenbrouwers

  • Moderator
  • Join date: May 2009
  • Location: KTMB
  • Posts: 4457
  • Hoppie designs avionics equipment for airliners.
    • http://www.hoppie.nl/
Re: Pushover App- integration with PSX PRINT function?
« Reply #25 on: Sun, 16 Feb 2020 19:17 »
Sure. Create a Shortcut where you want it (Background click >> new >> shortcut) and point it at the python.exe interpreter. Name it Pushover. Then right-click on it and select Properties. After the python.exe in Target, BEHIND the quotes, add the path to your psx-pushover.py file. You may change the window type to minimized and give it a new icon.

That's it!


Hoppie

cavaricooper

  • Join date: Dec 2009
  • Location: KTPA
  • Posts: 1260
Re: Pushover App- integration with PSX PRINT function?
« Reply #26 on: Mon, 17 Feb 2020 01:39 »


DONE!  Many thanks Hoppie!  Off to work on the Mac now...

C
Carl Avari-Cooper, KTPA

cavaricooper

  • Join date: Dec 2009
  • Location: KTPA
  • Posts: 1260
Re: Pushover App- integration with PSX PRINT function?
« Reply #27 on: Mon, 17 Feb 2020 17:37 »
... and with STILL MORE OF HOPPIE'S HELP- success on the Mac!



FINALLY!  Thank-you Hoppie!

Now, I get PSX Pushovers to my iPhone and iPad which I can reference indefinitely, and delete when done- fantastic!

C
Carl Avari-Cooper, KTPA

GodAtum

  • Join date: Jun 2014
  • Posts: 865
Re: Pushover App- integration with PSX PRINT function?
« Reply #28 on: Sat, 22 Feb 2020 21:15 »
Thank you for all the advice. Uploaded the code to Github for ease of use: https://github.com/GodAtum360/PSX-Stuff/blob/master/psx-pushover%20-%20master.py

cavaricooper

  • Join date: Dec 2009
  • Location: KTPA
  • Posts: 1260
Re: Pushover App- integration with PSX PRINT function?
« Reply #29 on: Sun, 23 Feb 2020 01:11 »
This is NOT my code- it is HOPPIES.  Please check with him BEFORE uploading it anywhere.

TY- C
Carl Avari-Cooper, KTPA

Greg Hateley

  • Join date: Aug 2011
  • Location: Perth
  • Posts: 97
Re: Pushover App- integration with PSX PRINT function?
« Reply #30 on: Wed, 18 May 2022 13:45 »
Hey Hoppie,
Can you please explain, with a bit of example code how to asyncio a function into the current code.
I need to pole (read) some switches (using RPi.GPIO) and return a switch is, pressed or not, back to the main program.
(I am using the PSX.py class).
I recall doing something like this last time for reading pots n the radar panel"await  asyncio.gather(PSX.connect(host, port),SendWxRdrPanelTurnQ())"

Main PSX Code:


Code: [Select]
VERSION = "Some kinda Greg version 000000 0.0-alpha-1"

import asyncio
import argparse
import sys
sys.path.append("/home/pi/hifiberry-dsp/hifiberrydsp")
from dsptoolkit import DSPToolkit
mydsp = DSPToolkit()
xmlfile =open('747acp_V3.xml')
data = xmlfile.read()
mydsp.install_profile_from_content(data)
mydsp.mic_gain(30,30,30,30,30,30)

from PSX import Client
from PSX import MCDU

if __name__ == "__main__":
  """ Try to connect to the PSX Main Server and see what happens. """

##  import datetime
##  import time
  def  RotSelAudioL(key, value):
    mystring4 =str(value)
    list1=(mystring4.split(";"))
    vhfvol = int(int(list1[0])/2 -30)
    print(vhfvol)
    mydsp.fader_gain(0x003B,0,vhfvol)
    print(f"RotSelAudioL: {mystring4}")
   
  def ReceiverSelL(key, value):
    mystring = str(bin(int(value)))
    mystring2 = int(value) & 1
    mystring3 = int((int(value) & 8)/8)
    print(f"ReceiverselL Val: {mystring}")
    print(f" Cpt VHF L Green Light: {mystring2}")
    print(f" Cpt FLT : {mystring3}")
    if mystring2 == 1:
     mydsp.fader_mute(0x0014,0,True)
    if mystring2 == 0:
     mydsp.fader_mute(0x0014,0,False)



  ##### MAIN #############################################################

  print(f"Self-test for the PSX Client Module, version {VERSION}\n")

  # Create a PSX Client and install a custom logger.
  with Client() as psx:
    psx.logger = lambda msg: print(f"   {msg}")

    # Register some PSX variables we are interested in, and some callbacks.
    # NOTE: These subscriptions are registered in the connector module, but
    # until the PSX connection is activated, nothing will happen.
    psx.subscribe("id")
    psx.subscribe("version", lambda key, value:
      print(f"Connected to PSX {value} as client #{psx.get('id')}"))

    # A simple thing to play with EICAS.
    #psx.subscribe("TimeEarth", TimeEarth)
    psx.subscribe("ReceiverSelL", ReceiverSelL)
    psx.subscribe("RotSelAudioL", RotSelAudioL)


    try:
      # Make and maintain a PSX Main Server connection until stopped.
      # Only here something actually happens!
      asyncio.run(psx.connect())
    except KeyboardInterrupt:
      print("\nStopped by keyboard interrupt (Ctrl-C)")

# EOF

Button Press code.
GPIO.setmode(GPIO.BCM)
    GPIO.setup(CAPT_PTT, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    pressed = False

    while True:
        # button is pressed when pin is LOW (True)
        if not GPIO.input(CAPT_PTT):
            if not pressed:
                print("CAPT_PTT pressed!")
                pressed = True
        # button not pressed (or released)
        else:
            if pressed:
                print("CAPT_PTT released!")
                pressed = False
        #time.sleep(0.1)

Rgds Greg
« Last edit: Wed, 18 May 2022 21:18 by Jeroen Hoppenbrouwers »

Jeroen Hoppenbrouwers

  • Moderator
  • Join date: May 2009
  • Location: KTMB
  • Posts: 4457
  • Hoppie designs avionics equipment for airliners.
    • http://www.hoppie.nl/
Re: Pushover App- integration with PSX PRINT function?
« Reply #31 on: Wed, 18 May 2022 21:20 »
So for each poll you want to open a PSX connection, wait until you get all variables, pick out the one you need, and then close the connection?

I don't understand yet what you try to achieve at the higest level. Inject hardware switch positions into PSX? Read variables from PSX?


Hoppie

Greg Hateley

  • Join date: Aug 2011
  • Location: Perth
  • Posts: 97
Re: Pushover App- integration with PSX PRINT function?
« Reply #32 on: Thu, 26 May 2022 12:17 »
Hi Hoppie,
Sorry for the delayed reply, So here I hope is a better basic description.
I can send and receive from PSX, that part works great.

The Python PSX is running on a Raspberry PI, and I want to read if a real switch also connected to the same Raspberry Pi (GPIO Ports) has been pressed or not within the body of the PSX code you did using the PSX Class.
To read the gpio switch, or switches I need to read the gpio input on the Pi constantly in a loop. (ie pole the inputs) "while True:"  loop.
I have written a function " def Pole_GPIO1" to read the switch 1 and return a pressed True False . this function needs to loop.
So for this function "Pole_GPIO1" it only looks to see if a switch has been pressed or not.

Once the real gpio switch is read,  if the state changes from pressed or to released, then send a code, or do something, IE PSX.send or light a LED for example, PTT vatsim. Im my case this gpio inputs are the PTT switches on the yoke.

something like this
-->->->PSX ->->->Pole(read)Switch -> Do Something else-> Loop

Jeroen Hoppenbrouwers

  • Moderator
  • Join date: May 2009
  • Location: KTMB
  • Posts: 4457
  • Hoppie designs avionics equipment for airliners.
    • http://www.hoppie.nl/
Re: Pushover App- integration with PSX PRINT function?
« Reply #33 on: Thu, 26 May 2022 17:53 »
You will need to add a new asyncio Task to the running main loop. In that Task, you can poll and process, then wait, but you need to use asyncio.sleep() else you lock up the whole thing.

Asyncio is not the same as threads, where you may within limits assume that your tasks run independently of each other in parallel. Asyncio requires you to explicitly have your tasks yield the CPU back to the main loop often, but you get back a cleaner structure that is easier to coordinate exactly because only one task runs at any moment.

I will see when I find time to make an example. It's a bit hectic at this moment.


Hoppie