Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Message
Author
SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#11 Post by SimPassion »

XPLOU wrote: Sun Jan 08, 2023 10:01 pm I had nice indents but they got stripped so I'll paste a screenshot
Just use the Code tag with the icon present above the text area while writing the post, this will write the start and ending tags for code and we paste in the middle of them :

image.png

Just like this :

Code: Select all

function stbyBatt_callback(position, direction)
    if position == 2 then
        -- CURRENTLY IN THE ARM POSITION
        if direction == -1 then
            -- SWITCH IS BEING MOVED DOWN TO THE OFF POSITION
            xpl_command("C172/cockpit/stbyBattDec") -- WORKS. AM AND SIM SWITCHES REACT PROPERLY. C172/cockpit/stbyBatt DATAREF VALUE CHANGES TO 0.
        end
    elseif position == 1 then
            -- CURRENTLY IN THE OFF POSITION
        if direction == 1 then
            -- SWITCH IS BEING MOVED UP TO THE ARM POSITION
            xpl_command("C172/cockpit/stbyBattInc") -- WORKS. AM AND SIM SWITCHES REACT PROPERLY. C172/cockpit/stbyBatt DATAREF VALUE CHANGES TO 1.
        else
            -- SWITCH IS BEING MOVED DOWN TO THE TEST POSITION
            xpl_command("C172/cockpit/stbyBattDec") -- DOES NOT WORK. NO EFFECT IN EITHER THE AM OR SIM SWITCHES. C172/cockpit/stbyBatt DATAREF VALUE STAYS AT 0.
                                                    -- I assume their internal code that forces the automatic return to the OFF position kicks in immediately or I'm simply overlooking something.
        end
    end
end

stbyBatt_id = switch_add("stby_batt_test.png", "stby_batt_off.png", "stby_batt_arm.png", 0, 0, 256, 165, "VERTICAL", stbyBatt_callback)
I'm on it, trying to provide a way using the switch solution, next soon ...
 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#12 Post by Sling »

Great that’s all the information needed. It should be simple to do what you want and we can help you with achieving that. My personal choice for this sort of thing is to use just 2 buttons rather than 3. In this case it will also make the code easier because I see AFL have provided the up and down commands which can simply put in each of the button callbacks. The animation is then just a simple case of subscribing to the switch position dataref and using the reported values to show/hide the relevant switch image. This gives total 2 way control meaning both the in sim and AM switch will animate in unison if either switch is operated.

I hope this helps. If you need further explanation just shout.

XPLOU
Posts: 13
Joined: Sat Dec 17, 2022 4:27 am

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#13 Post by XPLOU »

@SimPassion
@Sling

Thx for the forum code tag. Very useful.

Yes. I do think just a top and bottom button for either a 2-way or a 3-way switch, using the subscribe to flip the images, is the best implementation. While add-switch with just two images works fine it's not quite as natural as you can press your finger anywhere on the switch and it changes state. I like the idea of having to press the top of the switch to make it go up, or the bottom of the switch to make it go down (regardless if 2-way or 3-way).
I did start playing around with it but appreciate you giving it a shot.

Gets me wondering if the API can handle a finger "slide" up or down on the touchscreen and detect direction of travel :-P Now that would be quite realistic... But a top and bottom button is very close.

I selected this panel as my first foray into AM panels and instruments because it had what seemed like simple switches but also more complex switches, without getting into anything "too" crazy. Seemed like a decent training exercise. It has been. Definitely getting the hang of lua and the AM API more.

But it's always good to learn from those that have gone before :-)

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#14 Post by Sling »

Gets me wondering if the API can handle a finger "slide" up or down on the touchscreen and detect direction of travel :-P Now that would be quite realistic
You can use a slider to do that if you really want but after several years now of using all the AM controls I can tell you that a switch or a button gives much more reliable operation because it only needs to register that single first touch to action. Sliders are useful for some controls but I wouldn’t recommend them for simple switches. Just my thoughts. You can obviously try it for yourself if you want to compare the different control types after prolonged use with each.

XPLOU
Posts: 13
Joined: Sat Dec 17, 2022 4:27 am

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#15 Post by XPLOU »

I wouldn’t recommend them for simple switches
Was just a thought. If you've already gone down that path and found it lacking that's good enough for me.

XPLOU
Posts: 13
Joined: Sat Dec 17, 2022 4:27 am

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#16 Post by XPLOU »

With everyone's help I am close to finishing this panel!

The STBY BATT led on or off is still not tied to the actual voltage/amperage of the battery. I haven't been able to find a dataref that exposes that for me and I don't even know if the aircraft addon suports that or if the led on is just a dummy that lights up when you press the switch down into the TEST position. I've asked them and if I get a response I'll go back to that. It also has been a bit hard to find the information on the real-world aircraft for what those voltage/amperage levels even should be. So far I have this from various manuals/docs on the C172 G1000:

* If BUS E volts < 24 LED OFF
* The led will be on when discharge rates are > 0.5 amps for more than 10 seconds
* At 20v has little or no capacity left

This was interesting and was where I got the discharge rate and 20v comment:
http://avitmedia.aero.und.edu/c172sElec ... index.html

I've implemented the dimming knobs ok spo at this point everything works with touch controls.

As far as mouse control, though. Doesn't the add_button api already have basic mouse support? When I hover over any of the "buttons" I created to control the switches I get nothing, eben thpigh they work fine for touch and I did not add any touch_setting calls. Do I have to add mouse_setting calls?

Once I get that mouse control worked-out done I'll move on to knobster control.

Thanks!

XPLOU
Posts: 13
Joined: Sat Dec 17, 2022 4:27 am

Re: Stumped on the Cessna 172 G1000 STBY BATT switch in the TEST position

#17 Post by XPLOU »

Never mind previous post. Realized the mouse controls work when the instrument was added to the overall panel. On to knobster!

Post Reply