meduzapat / LEDSpicer

LEDSpicer a LED Animator and Controller for Linux
GNU General Public License v3.0
33 stars 13 forks source link

Basic Serial outputs option? #23

Closed SeongGino closed 9 months ago

SeongGino commented 11 months ago

Hi! I've stumbled onto your project and seems like it fits my needs, but I'm sort of having trouble navigating around this.

I've been working on an Arduino-based/compatible lightgun system with compatibility for Mame Hooker, which I use on Linux via Wine for sending game outputs as strings of commands sent to the Arduino's serial device. This is how both my system and the similar GUN4IR do serial-operated force feedback, and after working on the feature I wanted to try it on Linux natively with MAME or (preferably) RetroArch.

LEDSpicer seems like the alternative I'm looking for, but through perusing the project I haven't found any references to generic serial devices or sending outputs as a custom string of characters. Sure, there's outputs for specific named/branded devices, but... neither lightgun system are a named brand, it's just writing to the /dev/ttyACM# object. This also isn't a Pi, but a conventional Linux desktop (as I daily drive desktop Linux, EndeavourOS/Arch specifically).

Also, the gun system can use both solenoid as recoil and a controller-type rumble motor for a gun motor. While I see (vague) references to solenoid use, I don't see anything about motor use.

Can you walk me through how I should accomplish this to get Mame Hooker-like functionality for the lightgun? Not expecting the same configuration of course, just seeing if it's possible for this usecase. If not already available, would it be possible to implement? Thank you very much for your time.

meduzapat commented 11 months ago

Hello there, yes serial devices are supported, will be easy to create a new serial device, can you send me the details on how I control the LEDS or SOLENOIDS on the light gun using /dev/ttyACM# ? If you have a piece of code will help a lot. LEDSpicer runs on anything Linux based that can use the USB or serial library. Solenoids are supported. Motor is the same as Solenoids, in both cases you can set the milliseconds to supply power before cutting power off. To use MAME output, you need to set MAME to transmit to the network, then in LEDSpicer you need to set the input plugin called MAME to read the data that MAME sends, is very easy to do and works like charm here is a quick demo with terminator 2, all the lighting is coming out of MAME. VIDEO TERMINATOR 2 I can show you more details later on how to create the input plugin config, but is like this:

    <map
        type="Element"             <<<< what type you want to control
        target="P1_BUTTON1"  <<<< what you want to control
        trigger="led0"                 <<<< MAME output name
        color="White"                  <<<< what color
        filter="Normal"                <<<< special effects filter.
    />

You create one per mapping and you get it. You are welcome, tnx for contacting!! I want to see that lightgus working now :)

SeongGino commented 11 months ago

Thank you for the response!

While I don't necessarily have code examples, I have documented the codes that light gun systems respond to; these were established and somewhat standardized by GUN4IR, so my code reads for and reacts to it as similarly as I am able.

Though just as a practical example, with the gun I have connected which presents a /dev/ttyACM0 (and goes up from that with each player), I can write in a terminal:

echo S > /dev/ttyACM0

will make the gun initiate serial communication mode, and then if I write:

echo F1x1 > /dev/ttyACM0

will start the rumble motor, until I send a F1x0 the same way which stops the motor. Same thing for the solenoid, which uses the F0 prefix; LEDs use F2/F3/F4 for the Red/Green/Blue channels, respectively, with a third value (e.g. F2x1x255) indicating color intensity/brightness. There's also the option for solenoid/rumble/R/G/B led to "pulse" with an x2x#, where the number is how many pulses the peripheral should do which is handled by the gun itself. Once an S signal has been sent, the gun will react to commands like the above sent to its serial port; when the game closes, an E signal needs to be sent for the gun to return to handling force feedback internally.

That's the gist of how guns handle it, though again there's far more in the documentation I linked (it is rough, but I only just finished writing it last night). GUN4IR is a closed source system (that my implementation is inspired from), so the details were all provided to me in a spanish document that I had to loosely translate - info is quite sparse otherwise, and it took me a while to even get this much!

If you're interested in how it works on the gun side, you can get a glimpse at it here: https://github.com/SeongGino/ir-light-gun-plus/blob/43eb5ae0aefbe5067dfa9c3da2089c42b08be6e3/SamcoEnhanced/SamcoEnhanced.ino#L1695-L1929

Anyways, I can already gather that LEDSpicer works much differently to mamehook, so it'll take me some time to get adjusted! I do know that not just MAME, but also Flycast the Dreamcast/Naomi emulator has an outputs option that sends signals similarly to the same port that MAME does - the Libretro core namely, but also presumably the standalone does this too. I do hope much of this for the MAME plugin can be used the same for that!

meduzapat commented 11 months ago

looks very simple, I can write a device for you with that specifications and you will need to test it, I imagine, you can add as many guns to different ttyACM as you wish, right? Oh, based on the code sample you sent, I can actually connect to the USB directly, I will check.

SeongGino commented 11 months ago

Happy to test for sure--whenever you do get around to it anyways, no rush!

To clarify, it's one ttyACM slot per Arduino/gun device. Though you could have as many devices connected as your PC has available USB ports, realistically the maximum amount of players in a lightgun shooter is two-to-four (and really, that's stretching it, with the only example that comes to mind being the 4-player Gaia Attack 4, but that's a Windows arcade game aha - most MAME games are 2 to 3 players).

meduzapat commented 9 months ago

can you join this discord channel ? Discord LEDSpicer channel