Page 1 of 2

Gimx autostart at boot (without X) and led bonus

Posted: Sun Apr 17, 2016 5:22 pm
by minWi
I've done a few interesting tweaks that maybe someone finds interesting:

* Start gimx at boot as a systemd unit (no X needed)
* Led turns on to confirm gimx is running
* Hardware button to shutdown the raspberry pi

It is all documented in my blog http://b.minwi.com/2016/04/17/using-a-p ... with-gimx/ and I'll paste it here as I don't want you to mark it as spam :D
I had a Driving Force GT wheel which is not supported and it doesn't work in PS4, so it was basically covering in dust... but the community is awesome and there exists a project called gimx that enables support for old wheels in new systems like PS4, so I decided to give it a try, and after a few hours understanding what I needed and getting my hands dirty, it is working perfect with the DIY adapter (using a Chinese atmega32u4 + CP2102 converter) and a Raspberry PI 2.

The official wiki is pretty well documented, so I'm going to explain the addons I've made to fit what I wanted :)

Autostart at boot in without X
Instead using a .desktop file that will start X and then gimx, I've created a simple systemd init file that starts gimx.

Simply create a file /etc/systemd/system/gimx.service with the following content:

Code: Select all

[Unit]
Description=GIMX  
After=syslog.target network.target

[Service]
User=pi  
Type=simple  
ExecStart=/usr/bin/gimx -p /dev/ttyUSB0 -c LogitechDrivingForceGT_G29.xml --nograb  
Restart=always  
RestartSec=5

[Install]
WantedBy=multi-user.target  
Run systemctl daemon-reload to notify systemd about the new file and systemctl enable gimx && systemctl start gimx to enable the gimx service start at boot and start it in the same line.

Please note LogitechDrivingForceGT_G29.xml file should be available in the pi home directory as /home/pi/LogitechDrivingForceGT_G29.xml

Notify when gimx is running
In order to have a proper confirmation about if the gimx service is up and running, I've created a simple python script that turns a led on if the gimx service is running.

The file is located at /home/pi/blink.py:

Code: Select all

#!/usr/bin/python
import os  
import time  
import RPi.GPIO as GPIO

led = 23  
button = 18  
GPIO.setmode(GPIO.BCM)  
GPIO.setup(led, GPIO.OUT)  
GPIO.setup(button, GPIO.IN, pull_up_down = GPIO.PUD_UP)

def Shutdown(channel):  
  GPIO.output(led, True)
  time.sleep(0.2)
  GPIO.output(led, False)
  time.sleep(0.2)
  GPIO.output(led, True)
  time.sleep(0.2)
  GPIO.output(led, False)
  os.system("sudo shutdown -h now")

GPIO.add_event_detect(18, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while True:  
  found = False
  time.sleep(5)
  pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
  for pid in pids:
    try:
      cmd = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read()
      if "gimx" in cmd:
        found = True
    except IOError: # proc has already terminated
      continue
  if found == True:
    GPIO.output(led, True)
  else:
    GPIO.output(led, False)
As a bonus, I've also added a button so when it is pressed, there is a little blink effect, and the pi is shutted down. Pretty cool uh? :D

The schema is the following:

Image

To start at boot, simply add it to the pi user crontab (crontab -e) as @reboot /home/pi/blink.py

Order
All the wires, pi, etc. is hidden inside a Samsung Galaxy S6 box, which makes it pretty convenient.

Image
Image


Enjoy!

Re: Gimx autostart at boot (without X) and led bonus

Posted: Sun Apr 17, 2016 6:42 pm
by Matlo
Thanks. This definitely should be added on the RPi page of the wiki.

Re: Gimx autostart at boot (without X) and led bonus

Posted: Mon Apr 18, 2016 3:09 am
by cortega1
I said it before in the other post and I'll say it again...

That is f'ing cool. I might need to try and replicate one of those. Maybe with longer cables so the switch is closer to my wheel.

Re: Gimx autostart at boot (without X) and led bonus

Posted: Tue Apr 19, 2016 10:47 am
by minWi
I've added it to the wiki, but the schema picture is missing as I didn't find the "upload image" section in mediawiki, so if anyone can do it, it would be nice :)
Thanks!!!

Re: Gimx autostart at boot (without X) and led bonus

Posted: Thu Apr 21, 2016 9:46 am
by Matlo
Thanks.
The upload image function is intentionally left disabled. I'll upload the image manually.

Shouldn't the config directory be /home/pi/.gimx/config?

Re: Gimx autostart at boot (without X) and led bonus

Posted: Sat Apr 23, 2016 1:24 pm
by minWi
The thing is it looks like gimx always uses the user folder to look for the configuration. I've tried to store the config file in /etc/gimx/myconfig.xml but it fails at it tries to load /home/pi/etc/gimx/myconfig.xml

Re: Gimx autostart at boot (without X) and led bonus

Posted: Mon May 02, 2016 8:10 pm
by talolike
its time for a smartphone app to change quickly the configs connected to the raspberrypi xD

Re: Gimx autostart at boot (without X) and led bonus

Posted: Sun May 29, 2016 1:49 pm
by sephirotdnf
I don't have bord with LED but auto start works like a charm :D

Re: Gimx autostart at boot (without X) and led bonus

Posted: Fri Jun 10, 2016 2:40 pm
by superbalza
just a pair of questions:

do I need the led, or I can just use the button wiring it on the GPIO 18?
where I can find the PCB where you put the button and the led?
How much is the resistor?

Pretty awesome!
Thanks!

Re: Gimx autostart at boot (without X) and led bonus

Posted: Mon Jun 20, 2016 6:32 pm
by Rudi Rastelli
@superbalza
Check out my tutorial here : http://gimx.fr/forum/viewtopic.php?f=11&t=1687
Even if you don't follow it to the point it has the answer ure looking 4.

Regards
Rudi