<?xml version="1.0"?>
<!--
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2026 Kent Stevens (timeplt)

********************************************************************
*
* Bindings for Winwing WINCTRL URSA MINOR 32 Joystick L
*
* it has an LED and vibrator which are addressable
*
* joystick axes XYZ are 0-65535
* Z axis is lockable with a screw
* slider is from 4095-0
* hat switch - neutral 675, 0 up, 90 right, 180 down, 270 left
*   - press btn-20
* left buttons increase from left side across right then down
* right buttons increase from right side across left then down
* btn-21: trigger (PTT)
* btn-22: AP disconnect
*
********************************************************************
-->
<PropertyList>
    <vendor-id>winctrl</vendor-id>
    <model-id>joyl32</model-id>
    <name type="string">Winwing WINCTRL URSA MINOR 32 Joystick L</name>
    <debug-events type="bool">false</debug-events>
    <hid-debug-raw type="bool">false</hid-debug-raw>
    <nasal>
        <open>
            <![CDATA[
                logprint(LOG_DEBUG,"WINCTRL JOYL Nasal (event) open");
                joyl32 = input_helpers.winctrl.new("joyl32",cmdarg());
                var onOff = func() { return joyl32.leds.panel.update(); }
                var vibro = func() { return joyl32.leds.vib.update(); }
            ]]>
        </open>
        <close>
            <![CDATA[
                logprint(LOG_DEBUG,"WINCTRL JOYL Nasal (event) close");
                joyl32.close(cmdarg());
            ]]>
        </close>
    </nasal>
    <report>
        <report-id type="int">2</report-id>
        <report-type>output</report-type>
        <watch>/input/winctrl/joyl32/leds/panel</watch>
        <nasal-function>onOff</nasal-function>
    </report>
    <report>
        <report-id type="int">2</report-id>
        <report-type>output</report-type>
        <watch>/input/winctrl/joyl32/leds/vib</watch>
        <nasal-function>vibro</nasal-function>
    </report>
    <event>
        <desc>Aileron</desc>
        <name>abs-x-translate</name>
        <min-range>0</min-range>
        <max-range>65535</max-range>
        <dead-band type="double">0.02</dead-band>
        <binding>
            <command>property-scale</command>
            <property>/controls/flight/aileron</property>
            <factor type="double">1</factor>
            <offset type="double">0</offset>
            <power type="double">1</power>
        </binding>
    </event>
    <event>
        <desc>Elevator</desc>
        <name>abs-y-translate</name>
        <min-range>0</min-range>
        <max-range>65535</max-range>
        <dead-band type="double">0.02</dead-band>
        <binding>
            <command>property-scale</command>
            <property>/controls/flight/elevator</property>
            <factor type="double">-1</factor>
            <offset type="double">0</offset>
            <power type="double">1</power>
        </binding>
    </event>
    <event>
        <desc>Rudder</desc>
        <name>abs-z-translate</name>
        <min-range>0</min-range>
        <max-range>65535</max-range>
        <dead-band type="double">0.02</dead-band>
        <binding>
            <command>property-scale</command>
            <property>/controls/flight/rudder</property>
            <factor type="double">1</factor>
            <offset type="double">0</offset>
            <power type="double">1</power>
        </binding>
    </event>
    <event>
        <desc>slider</desc>
        <name>abs-slider</name>
        <min-range>0</min-range>
        <max-range>4095</max-range>
        <binding>
            <command>property-scale</command>
            <property>/input/winctrl/joyl32/slider</property>
            <factor type="double">-1</factor>
            <offset type="double">0</offset>
            <power type="double">1</power>
        </binding>
    </event>
    <event>
        <desc>hat</desc>
        <name>abs-hat</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>property-scale</command>
            <property>/input/winctrl/joyl32/hat</property>
            <factor type="double">45</factor>
            <offset type="double">0</offset>
            <power type="double">1</power>
        </binding>
    </event>
    <!--
    # joystick config
  <axis n="4">
    <desc type="string">View (horizontal)</desc>
    <low>
      <binding>
        <command type="string">nasal</command>
        <script type="string">setprop("/sim/current-view/goal-heading-offset-deg", getprop("/sim/current-view/goal-heading-offset-deg") + 2);</script>
      </binding>
      <repeatable type="bool">true</repeatable>
    </low>
    <high>
      <binding>
        <command type="string">nasal</command>
        <script type="string">setprop("/sim/current-view/goal-heading-offset-deg", getprop("/sim/current-view/goal-heading-offset-deg") - 2);</script>
      </binding>
      <repeatable type="bool">true</repeatable>
    </high>
  </axis>
  <axis n="5">
    <desc type="string">View (vertical)</desc>
    <low>
      <binding>
        <command type="string">nasal</command>
        <script type="string">setprop("/sim/current-view/goal-pitch-offset-deg", getprop("/sim/current-view/goal-pitch-offset-deg") + 1);</script>
      </binding>
      <repeatable type="bool">true</repeatable>
    </low>
    <high>
      <binding>
        <command type="string">nasal</command>
        <script type="string">setprop("/sim/current-view/goal-pitch-offset-deg", getprop("/sim/current-view/goal-pitch-offset-deg") - 1);</script>
      </binding>
      <repeatable type="bool">true</repeatable>
    </high>
  </axis>
    -->
    <event>
        <desc>trim reset</desc>
        <name>button-5</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.setElevatorTrimToPosition();</script>
        </binding>
    </event>
    <event>
        <desc>trim up</desc>
        <name>button-6</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.elevatorTrim(1);</script>
        </binding>
    </event>
    <event>
        <desc>trim down</desc>
        <name>button-7</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.elevatorTrim(-1);</script>
        </binding>
    </event>
    <event>
        <desc>trim reset</desc>
        <name>button-12</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.setElevatorTrimToPosition();</script>
        </binding>
    </event>
    <event>
        <desc>trim up</desc>
        <name>button-13</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.elevatorTrim(1);</script>
        </binding>
    </event>
    <event>
        <desc>trim down</desc>
        <name>button-14</name>
        <repeatable type="bool">true</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.elevatorTrim(-1);</script>
        </binding>
    </event>
    <event>
        <desc>view reset</desc>
        <name>button-20</name>
        <repeatable type="bool">false</repeatable>
        <binding>
            <command>property-assign</command>
            <property>/sim/current-view/goal-pitch-offset-deg</property>
            <value>0</value>
        </binding>
        <binding>
            <command>property-assign</command>
            <property>/sim/current-view/goal-heading-offset-deg</property>
            <value>0</value>
        </binding>
    </event>
    <event>
        <desc>FgCom PTT</desc>
        <name>button-21</name>
        <repeatable type="bool">false</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.ptt(1);</script>
        </binding>
        <mod-up>
            <binding>
                <command>nasal</command>
                <script>controls.ptt(0);</script>
            </binding>
        </mod-up>
    </event>
    <event>
        <desc>AP disconnect</desc>
        <name>button-22</name>
        <repeatable type="bool">false</repeatable>
        <binding>
            <command>nasal</command>
            <script>controls.autopilotDisconnect();</script>
        </binding>
    </event>
</PropertyList>
