Using the Joysticks / Game Controllers Extension for Microsoft Small Basic

Using the Joysticks / Game Controllers Extension for Microsoft Small Basic


 

Introduction

The Joysticks and Game Controllers extension, written in C# using DirectX by gungan37, allows for the use of any game controller in Small Basic. Such devices include joysticks, Xbox Controllers for Windows, racing wheels and pedals, flight sim yokes and rudder pedals and many more things, even a Wii Remote with the appropriate drivers!

Dependencies & Downloads

To use the Joysticks/Game Controllers extension you will need the extension files (a .dll and .xml file) and the SlimDX framework, which is a version of Microsoft DirectX for the .NET platform. You can find the SlimDX download here, and the download for the Joysticks/Game Controllers extension here. Once you have both of these items downloaded, and you have installed the SlimDX framework, you should be ready to advance.

You will also need to move the files for the Joystick/Game Controllers extension into the appropriate folder for Small Basic. By default, Small Basic is installed in Program Files (x86)/Microsoft/Small Basic for users on a 64-bit version of Windows, and Program Files/Microsoft/Small Basic for users on a 32-bit version of Windows. You will need to move both the .dll and .xml file into the "lib" folder. You will most likely require administrator permission to do this.

Using the Extension in Small Basic

You should now be ready to use this extension in Small Basic. If you have Small Basic open, you will need to close and re-open it. If you have it closed, simply open it. You should find two new classes: JoystickForSmallBasic class, which is for beginners, and the MUCH faster JoystickForSmallBasicAdvanced, which is for more advanced users. The only difference is that everything is taken care of for you in the less advanced class while, in the latter class, you must call the Acquire() method before polling for input and Unacquire() when you are done. We will be using the advanced class in this tutorial.

Take a look around the class and explore the members with the Intellisense wheel! You will notice the GetSlider(slidernumber) to get the slider value (percent) at the specified slider. You can also use GetButton(buttonnumber) to get "True" or "False" for if a button is pressed (and ButtonCount to get the total number of buttons). Finally, you can use GetPOV(pov hat index) to get the angle (in degrees) of a POV hat and GetX(), GetY(), and GetZ() to get the X, Y, and Z axis values, respectively.

Here is some sample code, which you can get with the Import ID FGM626:

start:
 
JoystickForSmallBasicAdvanced.Acquire()
TextWindow.Title = "Joystick Information"
TextWindow.WriteLine("")
TextWindow.WriteLine("Axis position: " + JoystickForSmallBasicAdvanced.GetX() + ", " + JoystickForSmallBasicAdvanced.GetY() + ", " + JoystickForSmallBasicAdvanced.GetZ())
 
slider = JoystickForSmallBasicAdvanced.GetSlider(0) 'get slider #0 value
slider = (slider / 65536) * 100 'convert to a percentage (go from out of 65536 to out of 100)
slider = 100 - slider 'flip value (DirectX gives value backwards)
 
TextWindow.WriteLine("Slider position: " + Math.Round(slider) + "%")
TextWindow.WriteLine("POV hat position: " + JoystickForSmallBasicAdvanced.GetPOV(0) + "°")
TextWindow.WriteLine("Firmware revision: " + JoystickForSmallBasicAdvanced.FirmwareRevision)
TextWindow.WriteLine("")
TextWindow.Write("Buttons: ")
For i = 0 To (JoystickForSmallBasicAdvanced.ButtonCount - 1) 'since buttons start with zero
  If JoystickForSmallBasicAdvanced.GetButton(i) = "True" Then
    TextWindow.Write(" " + i + " ")
  EndIf
EndFor
 
Program.Delay(120) 'delay so user can read info
TextWindow.Clear()
 
Goto start

Happy coding!

 

 

 

Sort by: Published Date | Most Recent | Most Useful
Comments
  • Great contribution, Gungan! Thanks for getting us started!

Page 1 of 1 (1 items)
</