Gimx autostart at boot (without X) and led bonus

General Chat, Feel Free To talk about anything here.
minWi
Posts: 7
Joined: Sun Apr 17, 2016 5:18 pm

Gimx autostart at boot (without X) and led bonus

Post 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!
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

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

Post by Matlo »

Thanks. This definitely should be added on the RPi page of the wiki.
GIMX creator
cortega1
Posts: 34
Joined: Wed Mar 30, 2016 3:34 pm

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

Post 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.
minWi
Posts: 7
Joined: Sun Apr 17, 2016 5:18 pm

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

Post 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!!!
User avatar
Matlo
Posts: 5768
Joined: Wed Jul 06, 2011 7:01 am
Location: France
Contact:

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

Post 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?
GIMX creator
minWi
Posts: 7
Joined: Sun Apr 17, 2016 5:18 pm

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

Post 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
talolike
Posts: 48
Joined: Sat Apr 04, 2015 3:42 pm

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

Post by talolike »

its time for a smartphone app to change quickly the configs connected to the raspberrypi xD
sephirotdnf
Posts: 69
Joined: Sat Feb 23, 2013 4:11 pm

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

Post by sephirotdnf »

I don't have bord with LED but auto start works like a charm :D
superbalza
Posts: 13
Joined: Fri Jan 29, 2016 2:52 pm

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

Post 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!
User avatar
Rudi Rastelli
Posts: 16
Joined: Sat Jun 04, 2016 3:17 pm

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

Post 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
Post Reply