gpiojoyfunctions

GPIO Joy User Functions

If you need to do something more complex than simple device control with the joystick, you can write your own functions and map them to joysticks or buttons on the controller.

<GpioConfig>

  <JoystickFunctions>

    <!--  Declare one or more assemblies to load.  -->
    <!--  You can call one or more setup functions at load time.  -->
    <Assembly>
      <Name>MyUserFunctions.dll</Name>
      <Setup class="MyUserFunctions.UserFunctions">Init</Setup>
    </Assembly>

    <!--  Map your function to a joystick button  -->
    <Function>
      <Joystick>DpadUp</Joystick>
      <Method assembly="MyUserFunctions.dll" class="MyUserFunctions.UserFunctions">SomeFunction</Method>
      <Name>My Func</Name>
    </Function>

  </JoystickFunctions>

</GpioConfig>

To integrate your own assembly with GPIOJoy:

  • Create a C# assembly using .NET Framework 4.7.2
  • Create one or more static classes with your user functions.
  • Add a reference GpioJoy.exe if you want to use pins or GPIO devices from your user functions.
    • You can use pins or devices in your functions by using the GpioJoyProgram.PinManager property

For example the following code could be used to turn pin 40 on and off five times when you hit a controller button.

namespace MyUserFunctions
{
    public static class UserFunctions
    {
        //  To use pins in your user functions, add a reference to GpioJoy, GpioManagerObjects, and wiringGpioExtensions
        static GpioManager PinManager => GpioJoyProgram.PinManager;

        public static void Init()
        {
            Console.WriteLine("User functions, init called");
        }

       

        public static async void SomeFunction(bool input)
        {
            //  check for button mashing, only accept this button once every six seconds
            if ( input &amp;&amp; Environment.TickCount - _buttonDownSomeFunction > 6000)
            {
                await FlashButtonFourty();
            }
        }
        static int _buttonDownSomeFunction = 0;


        /// <summary>
        /// Flash pin 40 five times
        /// </summary>
        static async Task FlashButtonFourty()
        {
            for (int i = 0; i < 5; i++)
            {
                PinManager.GetPin(40).Write(1);
                await Task.Delay(500);
                PinManager.GetPin(40).Write(0);
                await Task.Delay(500);
            }
        }
    }
}