<!-- Custom Aurora Skate Controller
  Joystick has four axes:
  axis 0: X on right stick
  axis 1: Y on right stick
  axis 2: Y on left stick
  axis 3: X on left stick

It has 9 buttons.
 b0  - right side/left bumper
 b1  - right side/right bumper
 b2  - right side/down bumper
 b3  - right side/up bumper
 b7 - yellow
 b8 - red
 b9 - green
 b10 - left side/left bumper
 b11 - left side/right bumper

-->

<joystick>
 <input>
  <axis index="0" name="rx" limit="1.00" exponent="0.7" trim="0"/>
  <axis index="1" name="ry" limit="1.00" exponent="0.7" trim="0"/>
  <axis index="2" name="ly" limit="1.00" exponent="0.0" trim="0"/>
  <axis index="3" name="lx" limit="1.00" exponent="0.7" trim="0"/>
  <button index="0" name="b0"/>
  <button index="1" name="b1"/>
  <button index="2" name="b2"/>
  <button index="3" name="b3"/>
  <button index="4" name="b4"/>
  <button index="5" name="b5"/>
  <button index="6" name="b6"/>
  <button index="7" name="b7"/>
  <button index="8" name="b8"/>
  <button index="9" name="b9"/>
  <button index="10" name="b10"/>
  <button index="11" name="b11"/>
</input>

<messages period="0.0333333333">


  <message class="datalink" name="RC_4CH" send_always="true">
   <field name="joystick_id" value="JoystickID()"/>
   <field name="throttle"    value="Scale(ly,-10,127)"/>
   <field name="roll"        value="rx"/>
   <field name="yaw"         value="lx"/>
   <field name="pitch"       value="0-ry"/>
  </message>


  <!-- trim commands -->
  <message class="ground" name="DL_SETTING_MOD" on_event="b1">
    <field name="index" value="IndexOfSetting('rc_roll_trim')"/>
    <field name="mod" value="10"/>
  </message>
  <message class="ground" name="DL_SETTING_MOD" on_event="b0">
    <field name="index" value="IndexOfSetting('rc_roll_trim')"/>
    <field name="mod" value="0-10"/>
  </message>

  <message class="ground" name="DL_SETTING_MOD" on_event="b3">
    <field name="index" value="IndexOfSetting('rc_pitch_trim')"/>
    <field name="mod" value="10"/>
  </message>
  <message class="ground" name="DL_SETTING_MOD" on_event="b2">
    <field name="index" value="IndexOfSetting('rc_pitch_trim')"/>
    <field name="mod" value="0-10"/>
  </message>

  <message class="ground" name="DL_SETTING_MOD" on_event="b11">
    <field name="index" value="IndexOfSetting('rc_yaw_trim')"/>
    <field name="mod" value="10"/>
  </message>
  <message class="ground" name="DL_SETTING_MOD" on_event="b10">
    <field name="index" value="IndexOfSetting('rc_yaw_trim')"/>
    <field name="mod" value="0-10"/>
  </message>

  <message class="ground" name="DL_SETTING" on_event="b10 && b11">
    <field name="index" value="IndexOfSetting('rc_roll_trim')"/>
    <field name="value" value="0"/>
  </message>

  <message class="ground" name="DL_SETTING" on_event="b10 && b11">
    <field name="index" value="IndexOfSetting('rc_pitch_trim')"/>
    <field name="value" value="0"/>
  </message>

  <message class="ground" name="DL_SETTING" on_event="b10 && b11">
    <field name="index" value="IndexOfSetting('rc_yaw_trim')"/>
    <field name="value" value="0-10"/>
  </message>
<!--
  <message class="ground" name="lx" on_event="b8"/>
  <message class="trim_plus" name="ly" on_event="b10"/>
  <message class="trim_minus" name="ly" on_event="b11"/>
  <message class="trim_plus" name="rx" on_event="b2"/>
  <message class="trim_minus" name="rx" on_event="b0"/>
  <message class="trim_minus" name="ry" on_event="b3"/>
  <message class="trim_plus" name="ry" on_event="b1"/>
  <message class="trim_save" name="" on_event="b5"/>
-->

<!-- Camera switch. Currently uses same buttons as yaw trim -->

  <message class="ground" name="DL_SETTING" on_event="b1">
    <field name="index" value="IndexOfSetting('cam_switch')"/>
    <field name="value" value="1"/>
  </message>

  <message class="ground" name="DL_SETTING" on_event="b0">
    <field name="index" value="IndexOfSetting('cam_switch')"/>
    <field name="value" value="0"/>
  </message>


  <!-- Red Button -->  <!-- AUTO2 mode -->
  <message class="ground" name="DL_SETTING" on_event="b8">
    <field name="index" value="IndexOfSetting('pprz_mode')"/>
    <field name="value" value="2"/>
  </message>

  <!-- Yellow Button -->   <!-- AUTO1 mode -->
  <message class="ground" name="DL_SETTING" on_event="b7">
    <field name="index" value="IndexOfSetting('pprz_mode')"/>
    <field name="value" value="1"/>
  </message>

  <!-- Green Button -->  <!-- MANUAL mode -->
  <message class="ground" name="DL_SETTING" on_event="b9">
    <field name="index" value="IndexOfSetting('pprz_mode')"/>
    <field name="value" value="0"/>
  </message>

 <message class="ground" name="DL_SETTING" on_event="b7 || b8 || b9">
    <field name="index" value="IndexOfSetting('rc_dl_active_joystick')"/>
    <field name="value" value="JoystickID()"/>
  </message>

</messages>

</joystick>
