Determine time since last input in bash - linux

I'm building an arcade cabinet and would like to have random games launch after 15 minutes of inactivity. I'm not sure how to determine the time since the last user input. This is a pretty standard screensaver with xserver, however I can't seem to find a way to do it without x running.
Specifically I'm running RetroPie on a Raspberry Pi 2. X is installed but not running. The front end is emulationstation.
Any help would be appreciated, thanks.

Related

Reading USB-midi input live in python

I am looking for a way to read the USB-MIDI input live and have triggers, that run when a certain note is played. For example it should run function x, when an "e" is being played. This is Python 3 based either on windows 10 machine or a raspberry pi.
All the information I found has been years to decades old with pygame, py-midi, pyportmidi. Is there any current library that supports this? Pygame seems to rely on polling causing a short delay, which is a problem for this scenario.
In MIDI-OX, the Monitor displays the notes being played in real-time, though I can't do anything useful with it from there, as I need the python triggers, or events.

Python: Pause some activities but allow other parts of the code to continue

I have a Python 3 script running on a Raspberry Pi (Buster) which writes some instrument data to my Nextion Display using the serial/UART interface. I have, for now, setup my code to sleep for 5 minutes after the current data are displayed. This working.
The Nextion Display is touch sensitive so that if I touch it, it will send a serial data string which can be read via my script and will tell me where on the screen it was touched.
Now, I would like to modify my code such that it will react to the touch-screen even during the sleep period. I could put the program into a tight loop instead of using time.sleep(300) and check the elapsed time and read the serial port during each loop. This sounds to me like I would be overworking the Pi and wasting CPU cycles. Is there a better way to pause certain sections of code while allowing other to continue?

When does linux set the computer's correct time?

In a Linux CentOS 5 machine, I am running process.sh using a cronjob at #reboot, every day (the machine gets shut off every night and turned on every morning).
process.sh takes the 'date' of the computer, and writes it to a log file, then exits.
When I check the logfile, the timestamp in it says "Tue Jan 1 13:14:38 GMT 2008"
When I go to the console of the computer and give it the 'date' command, it prints the correct date.
My best guess is that my cronjob is running BEFORE the computer sets its correct time.
Is there a way to fix this?
The battery that powers the CMOS memory on your motherboard may have run out. Try replacing it by a fresh one. It should look something like this.
This advice is based on the fact that the date of your log entry is "Jan 1 2008" which looks conspicuously like an epoch your motherboard may use. However, the time-of-day 13:14:38 is a little off for this; while the 13 hour shift can be explained if you are in the correct time zone, the nearly 15 minute offset seems odd. Unless your computer takes that long to boot to the point where cron executes your job. And of course, the reason why you eventually see the correct time is probably that ntp fixed the system time, as others have noted.

raspberry pi C program xxxx segmentation fault

I have made a C program, compiled with gcc , combined with some bash scripts, for playing music using mpd/mpc from web & usb.
It works well.
But at times the program exits after a while with
xxxx segmentation fault
where xxxx is a 4 digit number.
Can someone tell me what this means & how to fix it ?
Thanks !
Edited: The number before the message is random, so replaced with xxxx
I found the cause of the problem, after reading through my code.
There was an external program I was calling regularly by means of the 'popen' function.
But I forgot to add the corresponding 'pclose' function !
So, after some time there were too many files open, and my application was terminated.
After doing the correction, I left my application running overnight, and in the morning, it was still running !.
This was the longest it had run without crashing.
So I believe that was the source of the problem.
Edit: its been 24 Hrs that my application has been running without crashing, so I'l have to mark this as the answer.

Raspberry pi picture capture every 5 seconds

I have multiple webcams hooked up to my raspberry pi and they are compatible and work. I want the raspberry to take a picture every 5 seconds (with every camera), save it to /var/www/picture.jpeg (picture2.jpeg and picture3.jpeg) and repeat overwriting the old images. Im not quite sure how to achieve this and need help!
Thanks!
You may use guvcview or motion, I forgot with which argument you need to run, but just lauch it with --help and you will get all the information. Actually, I've never tried with more than onw camera, but I think that it is possible to do it. You may have to search. But for the delay, there is no problem with those to programs.

Resources