We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LDController
#1
Hi folks,  can anyone help me with some issues with the LDController actions ?
I have a generic USB SNES controller.
From the Windows Game Controller settings and properties, I can see that all the buttons are registering correctly, and continue to register whilst held down.

I have SlimDX runtime for .NET 4.0 installed .

In SB, using the LDController.Buttons query, the array returned is completely spasmodic.  I have the following code in a While ("True") loop...
  LDButtons = LDController.Buttons(1)
  GraphicsWindow.Title = LDButtons

E.g. I press button 1 and hold it. For a few seconds there is no response, then Button 1 may register as "True" for a brief moment, and then return to "False" almost instantly.
All other buttons exhibit similar behaviour. Sometimes a button may not register "True" at all while being held down, even though the Controller settings show that the button is depressed.


Here's what the array looks like for a brief period while I am holding Button 1 down... Notice that it is registered as "True" for 2 loop passes.
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=True;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=True;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;
1=False;2=False;3=False;4=False;5=False;6=False;7=False;8=False;9=False;10=False;

Any help to resolve this so I can get a true reading of current buttons depressed will be much appreciated.

regards,  Gordon
Reply
#2
(translated by Google translator)

Hi all.  Shy
It's very good that we have started discussing the topic of interaction with the controller.
I don't use the controller in my projects yet, but I hope to use the controller in the future.  Rolleyes

I will be following this discussion closely.
Reply
#3
Hi Gordon,

I tried with an old USB joystick (Logitec X3D) and it worked well for me.  Here is the import link for my test code (you may have to delete bits of the code that don't apply to your device), NDFS957.000-0

If this fails for you, or you wish to share a small complete sample code you have that isn't working, then please reply.
Reply
#4
Sorry to ask a dumb question,  but what is an import link ?  ( NDFS957.000-0  ?)

...cheers...
Reply
#5
Hi,

Its not a dumb question.  Small Basic programs can be shared by using the Publish button and imported using the Import button.  For each published code there is a set or letters/numbers identifying it.  Paste this into the Import button dialogue.  Depending on the IDE you use (the default or SB-Prime) it may look like below.

   
Reply
#6
Thanks,   that seems to be working fine.  I'm a bit perplexed...  Here's the final debug code I had running...
Code:
While ("True")
 
  LDButtons = LDController.Buttons(1)
  LDRecord = LDButtons + "  " + Clock.ElapsedMilliseconds
  File.WriteLine(DebugFile, DebugLineNo, LDRecord)
  DebugLineNo = DebugLineNo + 1
 

  Program.Delay(5)

EndWhile

...and I don't quite see why that wasn't producing the correct results...  I put the clock onto the output to see how long the action was taking and it seemed to be averaging around 140 - 160 ms...

Cheers
Reply
#7
I suspect the time delay is mostly the file operations, apart from the first one that creates the device connection.  Your code (slightly modified to run) worked as expected for me with typically less than 1ms for each LDController.Buttons call.

Code:
DebugFile = Program.Directory+"\LDController.txt"
File.DeleteFile(DebugFile)
DebugLineNo = 1

While ("True")
 
  time1 = Clock.ElapsedMilliseconds
  LDButtons = LDController.Buttons(1)
  time2 = Clock.ElapsedMilliseconds
  LDRecord = LDButtons + "  " + (time2-time1)
  File.WriteLine(DebugFile, DebugLineNo, LDRecord)
  DebugLineNo = DebugLineNo + 1

  Program.Delay(5)

EndWhile
Reply
#8
I edited your comment and added mycode.
https://litdev.uk/mybb/misc.php?action=help&hid=7
ZS
Reply
#9
Thanks for your help.  I now have the LDController working for versions of PacMan and Pong that I have been playing with.

However,   last night, after running the test code above that you gave me (with the Debug file included),  I am now getting the following error every time I try to write to any file, from any SB program...

  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.IO.Path.InternalGetTempFileName(Boolean checkHost)
  at Microsoft.SmallBasic.Library.File.WriteLine(Primitive filePath, Primitive lineNumber, Primitive contents)
  at _SmallBasicProgram._Main()

I've tried clearing the %temp% folder, and rebooting.   Doesn't solve it.

I've tried looking this up on various forums,  and most seem to be saying that its because the same method has the file locked 

As far as I know,  I haven't changed anything apart from running the test code

Any help would be _very_ much appreciated.

...cheers...  Gordon
Reply
#10
Could you provide a simple code in which this error occurs.
Or may be try saving the sb file first in a directory other than on C drive sometime it requires admin permission.
ZS
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)