Joystick
Quote from Gowtham on April 14, 2022, 4:30 pmI've integrated a time stamp comparison for each button so "taps" and
"holds" may be differentiated. I left debug prints where programmers may
insert their own code (myself included). The values are reported from a PS2
"dual shock"-style USB controller, a Logitech "DUAL ACTION" $30 piece of
history. Here it is, for better or worse:' Gambas module file
' Player input modulePUBLIC pad_device AS Process ' Device to accept gamepad input.
PUBLIC pad_time AS Integer ' Current time input occurred.
PUBLIC pad_data AS Short ' Current input data (stick data, 0=press,
1=release).
PUBLIC pad_type AS Byte ' Current input type (1 = button, 2 =
stick).
' Current button or axis number.
' (0 - 11 = buttons, 0 = left horizontal, 1 = left verticle, 2 = right
horizontal, 3 = right verticle, 4 = d-pad horizontal, 5 = d-pad verticle).
PUBLIC pad_number AS Byte
PUBLIC button AS Integer[12, 2] ' Button number, old button status (true =
pressed, false = released) and time stamp.
PUBLIC taptime AS Integer = 375 ' Number of milliseconds to elapse after
holding a button for it to become a hold command.PUBLIC SUB Initialize()
' Perform player input initialization.
' Set up the gamepad.
pad_device = EXEC ["cat", "/dev/input/js0"] FOR READ AS "Gamepad"
WAIT 1END
PUBLIC SUB Gamepad_READ()
' General declarations.
DIM counter AS Byte' Read new gamepad data.
READ #pad_device, pad_time, 4
READ #pad_device, pad_data, 2
READ #pad_device, pad_type, 1
READ #pad_device, pad_number, 1' Deal with button mashing.
IF pad_type = 1 THEN
' Button mashing has occurred.
IF pad_data = 1 THEN
' Button was pressed.
button[pad_number, 0] = TRUE
button[pad_number, 1] = pad_time
ELSE
' Button was released.
FOR counter = 0 TO 11
' Determine if button was tapped or held.
IF pad_number = counter THEN
IF Abs(pad_time - button[counter, 1]) < taptime THEN
PRINT "tapped", Abs(pad_time - button[counter, 1])
ELSE
PRINT "held", Abs(pad_time - button[counter, 1])
ENDIF
ENDIF
NEXT
' Preserve command history.
button[pad_number, 0] = FALSE
button[pad_number, 1] = pad_time
ENDIF
ENDIF
' Deal with stick flailing.
IF pad_type = 2 THEN
' Stick flailing has occurred.
SELECT CASE pad_number
CASE 0
' Left analog, horizontal.
IF pad_data < 0 THEN PRINT "Left analog: Move left"
IF pad_data > 0 THEN PRINT "Left analog: Move right"
CASE 1
' Left analog, vertical.
IF pad_data < 0 THEN PRINT "Left analog: Move up"
IF pad_data > 0 THEN PRINT "Left analog: Move down"
CASE 2
' Right analog, horizontal.
IF pad_data < 0 THEN PRINT "Right analog: Move left"
IF pad_data > 0 THEN PRINT "Right analog: Move right"
CASE 3
' Right analog, vertical.
IF pad_data < 0 THEN PRINT "Right analog: Move up"
IF pad_data > 0 THEN PRINT "Right analog: Move down"
CASE 4
' D-pad, horizontal.
IF pad_data < 0 THEN PRINT "D-pad: Move left"
IF pad_data > 0 THEN PRINT "D-pad: Move right"
CASE 5
' D-pad, vertical.
IF pad_data < 0 THEN PRINT "D-pad: Move up"
IF pad_data > 0 THEN PRINT "D-pad: Move down"
END SELECT
ENDIF' Debug info.
PRINT "pad_time: " & Str$(pad_time), "pad_data: " & Str$(pad_data),
"pad_type: " & Str$(pad_type), "pad_number: " & Str$(pad_number)END
I've integrated a time stamp comparison for each button so "taps" and
"holds" may be differentiated. I left debug prints where programmers may
insert their own code (myself included). The values are reported from a PS2
"dual shock"-style USB controller, a Logitech "DUAL ACTION" $30 piece of
history. Here it is, for better or worse:
' Gambas module file
' Player input modulePUBLIC pad_device AS Process ' Device to accept gamepad input.
PUBLIC pad_time AS Integer ' Current time input occurred.
PUBLIC pad_data AS Short ' Current input data (stick data, 0=press,
1=release).
PUBLIC pad_type AS Byte ' Current input type (1 = button, 2 =
stick).
' Current button or axis number.
' (0 - 11 = buttons, 0 = left horizontal, 1 = left verticle, 2 = right
horizontal, 3 = right verticle, 4 = d-pad horizontal, 5 = d-pad verticle).
PUBLIC pad_number AS Byte
PUBLIC button AS Integer[12, 2] ' Button number, old button status (true =
pressed, false = released) and time stamp.
PUBLIC taptime AS Integer = 375 ' Number of milliseconds to elapse after
holding a button for it to become a hold command.PUBLIC SUB Initialize()
' Perform player input initialization.
' Set up the gamepad.
pad_device = EXEC ["cat", "/dev/input/js0"] FOR READ AS "Gamepad"
WAIT 1END
PUBLIC SUB Gamepad_READ()
' General declarations.
DIM counter AS Byte' Read new gamepad data.
READ #pad_device, pad_time, 4
READ #pad_device, pad_data, 2
READ #pad_device, pad_type, 1
READ #pad_device, pad_number, 1' Deal with button mashing.
IF pad_type = 1 THEN
' Button mashing has occurred.
IF pad_data = 1 THEN
' Button was pressed.
button[pad_number, 0] = TRUE
button[pad_number, 1] = pad_time
ELSE
' Button was released.
FOR counter = 0 TO 11
' Determine if button was tapped or held.
IF pad_number = counter THEN
IF Abs(pad_time - button[counter, 1]) < taptime THEN
PRINT "tapped", Abs(pad_time - button[counter, 1])
ELSE
PRINT "held", Abs(pad_time - button[counter, 1])
ENDIF
ENDIF
NEXT
' Preserve command history.
button[pad_number, 0] = FALSE
button[pad_number, 1] = pad_time
ENDIF
ENDIF
' Deal with stick flailing.
IF pad_type = 2 THEN
' Stick flailing has occurred.
SELECT CASE pad_number
CASE 0
' Left analog, horizontal.
IF pad_data < 0 THEN PRINT "Left analog: Move left"
IF pad_data > 0 THEN PRINT "Left analog: Move right"
CASE 1
' Left analog, vertical.
IF pad_data < 0 THEN PRINT "Left analog: Move up"
IF pad_data > 0 THEN PRINT "Left analog: Move down"
CASE 2
' Right analog, horizontal.
IF pad_data < 0 THEN PRINT "Right analog: Move left"
IF pad_data > 0 THEN PRINT "Right analog: Move right"
CASE 3
' Right analog, vertical.
IF pad_data < 0 THEN PRINT "Right analog: Move up"
IF pad_data > 0 THEN PRINT "Right analog: Move down"
CASE 4
' D-pad, horizontal.
IF pad_data < 0 THEN PRINT "D-pad: Move left"
IF pad_data > 0 THEN PRINT "D-pad: Move right"
CASE 5
' D-pad, vertical.
IF pad_data < 0 THEN PRINT "D-pad: Move up"
IF pad_data > 0 THEN PRINT "D-pad: Move down"
END SELECT
ENDIF' Debug info.
PRINT "pad_time: " & Str$(pad_time), "pad_data: " & Str$(pad_data),
"pad_type: " & Str$(pad_type), "pad_number: " & Str$(pad_number)END
Quote from Guest on April 5, 2023, 1:26 amIncredible all kinds of amazing data.
[url=https://service-essay.com/]pay someone to write paper[/url] ico white paper writing service [url=https://custompaperwritingservices.com/]top paper writing services[/url] custom research paper writing service
Incredible all kinds of amazing data.
pay someone to write paper ico white paper writing service top paper writing services custom research paper writing service
Quote from Guest on April 5, 2023, 1:26 amVery good posts. With thanks.
writing an essay for college https://quality-essays.com essay editing service online https://bestonlinepaperwritingservices.com
Very good posts. With thanks.
writing an essay for college https://quality-essays.com essay editing service online https://bestonlinepaperwritingservices.com
Quote from Guest on April 5, 2023, 1:26 amMany thanks! I value it!
do my finance homework for me homework 123 do my physics homework online my son will not do his homework
Many thanks! I value it!
do my finance homework for me homework 123 do my physics homework online my son will not do his homework
Quote from Guest on April 10, 2023, 12:13 amYou actually suggested that perfectly!
essays online to buy [url=https://seoqmail.com/]buy essay paper[/url]
You actually suggested that perfectly!
essays online to buy buy essay paper
Quote from Guest on April 10, 2023, 2:22 amThis is nicely put. !
help writing essays for college essays to write about write my essay for me reviews
This is nicely put. !
help writing essays for college essays to write about write my essay for me reviews
Quote from Guest on April 11, 2023, 5:24 pmVery good info. Thanks a lot.
juegos de casino online [url=https://bestonlinecasinoreal.us/]slots casino online[/url] stardust online casino
Very good info. Thanks a lot.
juegos de casino online slots casino online stardust online casino
Quote from Guest on April 12, 2023, 6:20 amThank you. Very good information.
i cant write my college essay i need someone to write a resume for me someone do my essay
Thank you. Very good information.
i cant write my college essay i need someone to write a resume for me someone do my essay
Quote from Guest on April 14, 2023, 1:40 amExcellent data. Regards.
automatic essay writer write a research paper term paper writer custom paper writers
Excellent data. Regards.
automatic essay writer write a research paper term paper writer custom paper writers
Quote from Guest on April 14, 2023, 1:52 amYou said it nicely.!
need help writing an essay essay helper essay help online essay writing helper
You said it nicely.!
need help writing an essay essay helper essay help online essay writing helper