Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

[solved] touch very inaccurate under rc.local

Fri Dec 14, 2018 8:17 am

Hey all, apologies if this is a dumb question I've searched but struggled to find an answer.

I did originally post this in the python section but I think it might be better off here.

I'm building a screen for my truck to give speed, gps, fuel consumption ect. I can boot into the python / pygame application and in theory shutdown via an on screen button press, my issue is that if I boot into the application using rc.local the touch screen mouse is badly out of calibration and is very difficult to click on a button, the physical mouse is much more accurate but cant reach all areas of the screen.

If I boot into rc.local manually all is fine.

Here is the start of my code;

Code: Select all

import pygame
import time
import os
from pygame.locals import*

pygame.init()
pygame.font.init()



#gameDisplay=pygame.display.set_mode ((800,400))
gameDisplay=pygame.display.set_mode ((800,400),pygame.FULLSCREEN)
clock = pygame.time.Clock()

#pygame.mouse.set_visible(False)

darkblue = (0,0,100)
blue = (0,0,255)
red = (255,0,0)
green = (0,255,0)
yellow = (232,220,28)
black = (0,0,0)


gameExit = False

#clock.tick(10)

def button(text, x, y, width, hight, inactive_color, active_color, action = None):

    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    
    if x + width > (mouse[0]) > x and y + hight > (mouse [1])> y:
        pygame.draw.rect (gameDisplay, active_color, [x,y,width,hight],1)
        if click[0] ==1 and action != None:
            
            if action == "quit":
                pygame.quit()
            
            if action == "call_menu":
                menu_screen()

            if action == "night":
                bl.set_brightness(50)

            if action == "day":
                bl.set_brightness(255)
                
            if action == "shutdown":
                os.system('sudo poweroff')
              #  pygame.quit()

                
    else:

        pygame.draw.rect (gameDisplay, inactive_color, [x,y,width,hight],1)
       # text_to_button (text, blue, x, y, width, height)

        myfont = pygame.font.SysFont(None,35)
        textSurface = myfont.render(text,False, (yellow))
        gameDisplay.blit(textSurface,(x + 20,y+10))
        pygame.display.update()
Text in rc.local;

sudo python /home/pi/truck_display.py &

Interestingly if I boot via rc.local at start-up the mouse appears near the top on the left, if I run rc.local manually the mouse is at the centre of the screen.

I have done an upgrade install incase it was a bug but no difference, any ideas??

Second dumb question, am I right in thinking that if I add 'disable_splash = 1' to /boot/config.txt that should remove the colour square at startup?? I have read some people have managed to remove it while others say its impossible, If I change it to 'disable_splash = 0' I get the colour square twice.

This is a bit of an issue at night as in the dark the screen lights up with the intensity of a thousand watt light bulb destroying any sort of night vision! If I have to I can blank the screen backlight upon shutdown and then return it once the program boots, this might be an issue if something throws a wobbly as if the code doesn't boot for any reason the backlight won't get turned on.

I am using the 7 inch touch screen with the latest version of stretch.

Many thanks.
Last edited by Dangermoth on Tue Dec 18, 2018 8:15 am, edited 1 time in total.

User avatar
RaTTuS
Posts: 10415
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: touch very inaccurate under rc.local

Fri Dec 14, 2018 8:34 am

this is wrong on so many levels
1) you odn't need sudo in rc.lcoal
2) don't use rc.local
3) use a systemd.service file if this is not x based
4) use the lxde autostart features if this is a x based thingy

how do you start it normally when it works fine
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: touch very inaccurate under rc.local

Fri Dec 14, 2018 10:35 am

Thanks I appreciate your reply.

I used 'sudo' because I used this example that used it;

https://www.dexterindustries.com/howto/ ... t-startup/

When I start it normally I right click on the file icon and open with python2, or when I said I open it via rc.local manually I type in the same phrase that I entered into 'sudo nano /etc/rc.local' but into the text editor window, both of these methods launch my application correctly.

I will look into what is involved with using systemd or lxde autostart once I find out what 'x based' is.

fbe
Posts: 494
Joined: Thu Aug 17, 2017 9:08 pm

Re: touch very inaccurate under rc.local

Fri Dec 14, 2018 1:33 pm

https://en.wikipedia.org/wiki/X_Window_System
If your python application is part of your desktop, it should be started by the autostart feature of your desktop. You can see what happens when you logout and login to the desktop again instead of rebooting (don't forget to have a keyboard available before you logout ;)). If you place your command line into rc_local, your application won't run after that.

The mouse cursor is always placed to the upper left corner when you login to the Raspberry Pi Desktop with default configuration. This is caused by point-rpi in the autostart file.

disable_splash=1 in /boot/config.txt disables the "Rainbow Screen" at the very beginning. There is also a "Welcome to the Raspberry Pi Desktop" splash screen that can be disabled using raspi-config or the "Raspberry Pi Configuration" application.

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: touch very inaccurate under rc.local

Fri Dec 14, 2018 2:16 pm

Ok thanks, that makes perfect sense now about rc.local, I have found a tutorial for systemd which sounds a lot more promising so I will try that.

Adding 'disable_splash=1' doesn't appear to make any difference, I may have read somewhere that if using NOOBS the system boots twice I wonder if that might be why I can't banish the rainbow screen?

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: touch very inaccurate under rc.local

Fri Dec 14, 2018 7:29 pm

OK, I'm going to try autostart, this looks very intimidating and is way deeper than I want to get into linux, in my experience typing cryptic commands into the text editor always ends badly, before I take the plunge how do I get the text editor back up when the pi fails to boot?

I'm more than happy writing pygame and python code but linux to the uninitiated is akin to witchcraft, any words of encouragement would be hugely appreciated.

thanks.

Dangermoth
Posts: 59
Joined: Wed Oct 25, 2017 7:34 am
Location: Sheffield

Re: [solved] touch very inaccurate under rc.local

Mon Dec 17, 2018 7:55 pm

Hey guys, the autostart thing works a treat, mouse calibration now spot on, many thanks for you help. :P

Return to “Troubleshooting”