dddomodossola / PFD

Apache License 2.0
0 stars 1 forks source link

Configuration/settings page. #22

Closed AndKe closed 3 years ago

AndKe commented 3 years ago

In order to change voltage level-alarm threshold, stallspeed, cruise speeds per airframe, a configuration page would be useful. The configuration should only be displayed when needed (toggled by a clickable area)

Please see the mockup below: Screenshot from 2021-04-20 20-09-37

Normally - by default the page ends where the horizontal blue line is. (which is here only for illustration purpose) Clicking the text-area encircled in orange toggles the page to display/hide the items below the blue bar.

Please note that I do not ask you to include all those items, just a few examples on how to create, and access the droplist-items, checkbox, textbox item. (I should be able to figure it out reading Remi docs) I have not yet worked out all I wish to include there, so if I only get a few example items, I will be able to make the rest as I go.

At first, I thought I would wish to access those values from the telemetry thread, but I see that this is not necessary. (and I suspect that would cause additional work to do so) - hence the request for an example on how to access those values... which I think may not be necessary.

AndKe commented 3 years ago

@dddomodossola Making such expanding area could solve the sound issue.

If it was expanded by a click, (that also played a sound?) that would fulfill the user-activity requirements to play sounds "normally" afterwards.

As a fallback plan, the configuration page would have a "make sound" button, that simply played a sound .. which in turn would fix the same issue.

In other words: a configuration/settings page could be the solution to the sound issue.

dddomodossola commented 3 years ago

Hello @AndKe I will work on this tomorrow ;-)

dddomodossola commented 3 years ago

Hello @AndKe , this is done, please give it a try.

AndKe commented 3 years ago

@dddomodossola Thank you. The settings page is great. Unfortunately, the way it plays a sound is the same as a script would, so that does not fulfill the browser's need for user interaction.

This is the most minimal code I know of that plays of glass browser:

<html>
 <button id="playButton" onclick="document.getElementById('myTune').play()">Play</button>
 <audio id="myTune">
  <source src="sound.wav">
 </audio>
</html>

I have reason to believe that any sound after manually playing a sound, will work. I guess the <HTML> and </html> won't be needed. but how can I append/insert this code to the configuration page?. (so that this button and audio item is inserted into the top of, or at the the end of the configuration page)

dddomodossola commented 3 years ago

Hello @AndKe please excuse me. Now I fixed it ;-)

AndKe commented 3 years ago

Thank you. This is very odd. self.bt_init_sound.attributes['onclick'] = '''document.getElementById('audio').play();''' works very well on glass. Then I have fulfilled the "need for interaction" - yet there Is no playback on alarms. (like in the desktop browser) , but I can play via button any time.

Please bear with me on following observations: Then I see that the alarms trigger: self.execute_javascript('document.getElementById("audio").play();')

which has four apostrophes less than what the onclick does? - is that of any importance? also at one time, we replaced the javascript with html5: https://github.com/dddomodossola/PFD/pull/17/files/6894dbbe3a7e5454390272062fced3ab9350e9a8..cb70081e609b1f23cae388b42fe25560b93002b6#diff-ff423580bc6734e55a935bc9c28eb3a3207b0666be2cb5403fac4e480a32a3a6L776

is the "self.execute_javascript" still correct then? I have a small hope there is a small error somewhere, and newer browsers simply handle such things, while the glass is more strict (stripped of such smartness due to older codebase or resource-saving)

dddomodossola commented 3 years ago

Hello @AndKe , apostrophes are ok and self.execute_javascript seems to be also correct to me. Unfortunately I see no error in this. Can you please try this with glasses: https://www.w3schools.com/graphics/tryit.asp?filename=trygame_sound

AndKe commented 3 years ago

@dddomodossola After much research, I learned enough about Android and Google Glass to make a webview app for it. - and made it work just now... (until now, I just launched glass-browser.)
Among other things, I needed to set setMediaPlaybackRequiresUserGesture(false); in the app. Then the webpage works just fine, with sounds and all. but I have no clicking/scrolling capability. The clicking is not necessary on the glass, I could also make the app offer to launch as browser (no sound, but clinking) - or as webview (with sounds).

I've also tried the trygame_sound URL, but that made no sound. Anyway: with the webview app I've made I am quite happy :) ---- moving on: Question is: in order to have the various alamrs/feedback files,(>20 small files) is the proper way to duplicate this line: https://github.com/dddomodossola/PFD/blob/cutting_edge_performace/PFD.py#L811 like:

a_stall = gui.load_resource('./stall.wav')
a_overspeed = gui.load_resource('./overspeed.wav')

and same with line: https://github.com/dddomodossola/PFD/blob/cutting_edge_performace/PFD.py#L814

self.centering_container.add_child("audio", """<audio id="ai_stall" style="visibility:hidden;height:0px;width:0px;position:absolute" controls><source src="%s" /></audio>"""%a_stall)
self.centering_container.add_child("audio", """<audio id="ai_overspeed" style="visibility:hidden;height:0px;width:0px;position:absolute" controls><source src="%s" /></audio>"""%a_overspeed)

Then I would think I need to invoke them by conditionally running one of many lines like:

self.execute_javascript('document.getElementById("ai_stall").play();')
self.execute_javascript('document.getElementById("ai_overspeed").play();')

I am onto the "correct" way to do it? (Please have in mind that I wish to have the sounds preloaded/prebuffered on webpage-load, so that they play "instantly")

dddomodossola commented 3 years ago

Yes this seems correct, you are loading and playing different audio files correctly. Do you mean you made a simple browser app and you will load the pfd with it? I understood it correctly?

AndKe commented 3 years ago

I made an android app that uses https://developer.android.com/reference/android/webkit/WebView to present the webpage. (hardcoded) It performs equally to the standard glass browser, and the main difference is that it is a "browser in a window" , not a standalone task/browser. - also, that I had the control to make it play sounds regardless of user interaction.

AndKe commented 3 years ago

@dddomodossola Please point out my failure: I added many different child items like:

        i01 = gui.load_resource('./sound.wav')
        m01 = gui.load_resource('./snd/m_auto.mp3')
        m02 = gui.load_resource('./snd/m_autotune.mp3')
        (...)
        self.centering_container.add_child("audio",
        """<audio id="i01" style="visibility:hidden;height:0px;width:0px;position:absolute" controls><source src="%s" /></audio>""" % i01)

        self.centering_container.add_child("audio",
        """<audio id="m01" style="visibility:hidden;height:0px;width:0px;position:absolute" controls><source src="%s" /></audio>""" % m01)

and changed the function that plays it a little bit

 def play_beep(self, snd="i01"):
    (...)
            self.execute_javascript('document.getElementById(snd).play();')

Then I call it like: play_beep("i01") But then there is no sound playback . (and no error)

dddomodossola commented 3 years ago

Hello @AndKe ,

The problem is here:

def play_beep(self, snd="i01"):
    (...)
    self.execute_javascript('document.getElementById("%s").play();' % snd)

;-)

AndKe commented 3 years ago

@dddomodossola Thank you. I also needed to add a unique child name to each instead of "audio" self.centering_container.add_child("unique-name-here", and it all works fine, the neat bonus is that the sounds can overlap too.

Does REMI see, or can provide the requested URL with a query string like? https://pfd.local:8081/?alarms=all

can I get to see "alarms=all" in the idle function? ..If it is not possible, no problem.

dddomodossola commented 3 years ago

@AndKe Unfortunately actually it is not possible. But maybe I will be able to add this feature in a near future, thank you for the idea! ;-)

AndKe commented 3 years ago

@dddomodossola thank you.