Announcement

Collapse
No announcement yet.

Direct Input Plugin for Gamepads and Joysticks

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Direct Input Plugin for Gamepads and Joysticks

    The new Direct Input plugin is out. You can break-down a cheap $3 gamepad, and use all the buttons/axes as USB or Joystick port wired inputs for HomeSeer.


    Requirements:

    - Direct X 3.0C (see dxdiag.exe)
    - HomeSeer 2.0 (as it's a .Net plugin)
    - At least one Direct Input compatible GamePad / Joystick.

    Features:

    - AutoCreate a new HomeSeer device per Joystick Axis / Button. You get "realtime" updates of HomeSeer device values according to device moves.

    - Range update Mode for each Axis. This saves on CPU a lot as the HomeSeer device value is updated only on range jumps.

    - DeviceStrings : you can configure any device string per range of values or button state.

    - You can Enable / Disable any Joystick or Axis or button

    - The plugin is notification based. There is no thread polling the joystick devices every 10ms...

    - Sequences. You can define millisec timed sequences that will trigger a HomeSeer Event with the same name as the sequence. Double-Clicks, timed hold and release of a particular sequence of buttons, cabling a gamepad buttons to a simple pinpad for access control....


    Quick how to:

    - Stop HomeSeer 2

    - Copy the content of the attached .ZIP to your HomeSeer 2 directory. There is a directory structure inside the ZIP file that must be kept like that. Make sure your zip/unzip utility doesn't unzip in "flat" mode (flat mode removes the directory structure, and that's bad).

    - Restart HomeSeer 2

    - Plug a Joystick / gamepad, and make sure it is loaded by the system (control panel - Games, or dxdiag.exe - Inputs). If you want to use one of the Joystick Axis inputs seriously, you should calibrate the input first through the control panel applet.

    - Go to config, ENABLE the plugin and watch your HomeSeer log.

    - Now have a look at your devices, and watch device value changes.

    - You can set any trigger on Device Value changes.


    More on Device Parameters and Ranges:

    Have a look at the Config/hspi_di.ini file

    ;LIST OF YOUR DEVICES
    [DirectInputDevices]
    DirectInputDevice0=08809590-bf28-11d6-8001-444553540000

    ;EACH DEVICE HAS HIS OWN SECTION
    [DirectInputDevice0]
    Enabled=True

    ;EACH DEVICE ELEMENT HAS HIS OWN SECTION
    ;ELEMENT-CODES ARE: X,Y,Z,RX,RY,RZ,B0,B1...Bn
    [DirectInputDevice0/Y]
    Enabled=True
    Mode=Auto
    RangeMini=-10
    RangeMaxi=10
    DeadZone=1000
    Saturation=9000
    HomeSeerDeviceRef=817
    Range0=-10,-5,-1,Negative Inclinaison
    Range1=-5,5,0,Zero Inclinaison
    Range2=5,10,1,Positive Inclinaison

    -------------------------------------------------------

    Enabled=False means you can remove the HomeSeer device, and it won't be recreated.

    Mode=Auto,Range,Sequence,Direct

    Direct = Forward input changes to HomeSeer directly (bypassing Range0...RangeX definition), and according to RangeMini and RangeMaxi.

    Range = Forward input changes to HomeSeer according to defined Ranges.

    Auto = Direct if Range0 is not defined, or Range if Range0 is defined

    Sequence = Do not forward input changes to HomeSeer (saves on CPU a lot). However, sequences with this input are still active.

    RangeMini = Minimum value reported by the Axis when it's on lowest position.

    RangeMaxi = Maximum value reported by the Axis when it's on highest position.
    Default range is (-10,10), but you can set (-1000,1000) or (0,100)...

    DeadZone = This parameter is always based on 10.000. DeadZone=1000 means the center 10% of the Axix are seen as a 0 input.

    Saturation = Always based on 10.000. Saturation = 9000 means all moves above 90% of the Axis are seen as a 100% value.

    Range0=-10,-5,-1,Left Direction
    Range1=-5,5,0,Center position
    Range2=5,10,1,Right Direction

    You should use this feature to save on CPU, and report only Range jumps to HomeSeer. The first range number MUST be 0. The range is defined as:

    RangeX = MinimumValue,MaximumValue,HomeSeerDeviceValue,HomeSeerDevice String

    The 2 following .ini keys replace ranges for simple buttons, and lets you assign device strings for each value 1 or 0.

    Pressed=Mybutton is pressed
    Released=My button is not pressed


    Note: Currently, device strings are loaded into HomeSeer when the Device is Created. If you want device string change taken into account, you must delete the HomeSeer device yourself, and reload the plugin. This will recreate the device with new device strings attached.

    More on Sequences:

    If a specific timed sequence of inputs is recognized, the HomeSeer event with the same name as the sequence will be run. For this example, I have defined three manual HomeSeer events Circle, DoubleClick, and BothButtons.


    A sequence step is made of four comma separated elements:

    StepX=DirectInputDevice0/Y,<-5,0,0

    1) DirectInput0/Y is the input ID. This is the Joystick input id, followed by a slash, and the Object id (X,Y,Z,RX,RY,RZ,B0,B1...Bn)

    2) < -5 is an operator and a value. Valid operators are <,>,= or nothing which means =

    3) Number of millisecs the above comparison must remain valid before the step matches. 0 means the Step is valid as soon as the comparison is valid. The last step of a sequence should finish with a 0 "hold" value if you want instant reaction (as the plugin is notification based).

    4) Timeout in millisec to wait for step match (3). The value 0 means no timeout (usefull for Step0). If Timeout=200, the comparison and held time must match before 200ms have elapsed. If the TimeOut is smaller than the "hold" value, it means the comparison must already have been valid for some time before entering the step. This is usefull to match when several inputs must be pressed simultaneously.

    [Sequences]
    Sequence0=Circle
    Sequence1=DoubleClick
    Sequence2=BothButtons

    ; AXES X and Y make a clockwise circle starting north. This example may not be adapted to your joystick
    ; Axis configuration. Watch the values yourself before writting a sequence.
    [Sequence Circle]
    Step0=DirectInputDevice0/Y,<-5,0,0
    Step1=DirectInputDevice0/X,>5,0,1000
    Step2=DirectInputDevice0/Y,>5,0,1000
    Step3=DirectInputDevice0/X,<-5,0,1000
    Step4=DirectInputDevice0/Y,<-5,0,1000

    ; BUTTON0 makes a quick double-click (200ms up and downs)
    [Sequence DoubleClick]
    Step0=DirectInputDevice0/B0, 1, 1,0
    Step1=DirectInputDevice0/B0, 0, 0,200
    Step2=DirectInputDevice0/B0, 1, 0,200
    Step3=DirectInputDevice0/B0, 0, 0,200

    ; BUTTONS 0 and 1 MUST BE PRESSED SIMULTANEOUSLY (within 200ms)
    ; AND HOLD FOR AT LEAST 500ms and no more than 3s.
    [Sequence BothButtons]
    Step0=DirectInputDevice0/B0,1,500,0
    Step1=DirectInputDevice0/B1,1,500,200
    Step2=DirectInputDevice0/B0,0,0,3000
    Step3=DirectInputDevice0/B1,0,0,200

    Note:
    First sequence id must be Sequence0, and the parser stops reading if there is a gap. Same for sequence Steps...


    Have fun, and tell me if you like it, need more features, or find bugs. It's a first beta version but it works well. If you have a problem try deleting the HomeSeer devices, and let the plugin recreates them on reload.

    Stipus
    Last edited by stipus; December 4, 2009, 06:43 PM.
    --
    stipus

    #2
    Version 0.2 of the Direct Input Connector posted

    Version 0.2 of the plugin has been posted (see post #1 to download attachement).

    New features include a full web configuration interface, with the possibility to change all parameters, device ranges, device strings and sequences definition.

    This is my first attempt at a web configuration interface.

    Please tell me what you think.

    stipus
    --
    stipus

    Comment


      #3
      Stipus,


      Good luck with the plugin, I will probably move over to hs2 over the holidays - I may switch over to your plugin and pension mine off - one question have you solved the issue of directx not registering the button press if it is already pressed when plugin loads - I couldn't find a way around that?


      Malarcy

      Comment


        #4
        well, I did solve that issue by polling the device once, storing the current value, then installing the event handlers for device changes. With this solution in place, I didn't see any other initialization problem on my installation.

        But as I didn't receive any feeback yet, I really don't know if it works well with other joysticks / gamepads / usb drivers...

        stipus
        --
        stipus

        Comment


          #5
          I'll try it out over the holidays and let you know - I think you have done some good work with the config and the paramaters, well done - it reads very well.


          Malarcy

          Comment


            #6
            To answer a private message an let everyone know:

            It is possible that the USB controller chip inside your gamepad or joystick supports more inputs than the physically available buttons and axis.

            In that case, the plugin will create homeseer devices for Buttons or Axis you can't physically see on the gamepad.

            You can go to the configuration interface (HomeSeer Setup / Interfaces / Di Connector / Config button), disable the inputs that do not exist, and delete the matching devices from homeseer. When inputs are disabled from the interface, they won't be recreated the next time the plugin is started.

            stipus
            --
            stipus

            Comment


              #7
              Any feedback ? Does it work for you ?Do you think the plugin is ready to be sent to the updater ?

              Thanks in advance,

              stipus
              --
              stipus

              Comment


                #8
                Does this have to be a USB joystick? Can it be one that plugs into a gameport?

                Comment


                  #9
                  I don't have any 'older' gameport joystick to test this, but as soon as the joystick is recognized by the DirectInput system, it should work.

                  Run dxdiag.exe, and have a look at the DirectInput tab. If your joystick is listed here, the plugin should work.

                  You can also just install the plugin, and see if it works. The installation does nothing special in the system, and if it doesn't work, you can just remove the plugin files.

                  stipus
                  --
                  stipus

                  Comment


                    #10
                    Originally posted by stipus
                    You can also just install the plugin, and see if it works.
                    Which was going to be my next question. Do I just plop these in the Homeseer 2 directory and they're recognized or ???

                    Comment


                      #11
                      To install please read the "How To" I wrote on the first post.

                      As it's a .Net plugin, there is no need to register anything. You just have to unzip and copy the directory structure to your homeseer 2 directory.

                      Please tell me if it works. I need feedback before I make the plugin available through the updater.

                      stipus
                      --
                      stipus

                      Comment


                        #12
                        How to?

                        I tried to install according to your how to but the plugin doesn't evn show up in my Setup - Interfaces screen so I can't "ENABLE" it. Not sure where to put it so I just extracted the files into my Homeseer 2 directory.

                        Any ideas on how to get this thing going? Also the zip file doesn't have an .ini file in it so should I create one based on the text in Post #1?

                        Comment


                          #13
                          Inside the Zip file, there is a directory structure starting with "HomeSeer 2"

                          You must copy the unzipped structure to your "HomeSeer 2" directory. You should see the file hspi_di.dll in your "HomeSeer 2" directory.

                          1) Check that the file hspi_di.dll is in the "HomeSeer 2" directory. If it's not, something went wrong when you copied the files.

                          2) Restart HomeSeer

                          3) Go to Setup / Interfaces. You should see an entry for "DI Connector"

                          --

                          There is no default ini file. It should be automaticaly created in the "HomeSeer 2\Config" directory when the plugin is first enabled.

                          stipus
                          --
                          stipus

                          Comment


                            #14
                            Direct Input Connector V0.3 is out.

                            The Direct Input Connector V0.3 has been released (see post #1 to download).

                            The only change is the expiration date that has been removed, as no bug has been signaled for a while, and the plugin seems to be very stable.

                            If you upgrade from a previous version, you can
                            - Stop HomeSeer 2
                            - In the HomeSeer 2 directory, replace the old hspi_di.dll with the new one
                            - Restart HomeSeer 2.
                            --
                            stipus

                            Comment


                              #15
                              Dang - was all set to install this and start testing, then read it only works with HS 2.0. I'm still running HS 1.7 because it works for me and I don't feel 2.0 is stable enough yet. DxDiag shows I have a game port to use but I can't test your sfw
                              Bruce

                              "The universal answer is 42."

                              Comment

                              Working...
                              X