Page 1 of 1

ESA Eye Strain Avoider !

Posted: Tue Jun 02, 2020 10:47 am
by nullpointer
Hi all,
If you spend long hours working at your computer, you can avoid eye strain with a helpful trick called the 20-20-20 rule:

Every 20 minutes, look at something 20 feet away for 20 seconds.

https://www.juststand.org/blog/prevent- ... 20-20-rule

I've writen this little program as a reminder which rings a bell every 20 min (adjustable).

Choose any sound file "ring.mp3" and put it in your home folder (or any where).
I'm using "mpg123" as a player but u can use any one.

to compile:

Code: Select all

gcc -a esa esa.c
to run it in the backgound:

Code: Select all

./esa & exit
to stop it:

Code: Select all

pkill esa
And here's the code " esa.c":

Code: Select all

/***************************************************
- PROGRAM NAME: ESA (Eye Strain Avoider)
- AUTHOR: M.LAOUAR SEB-SEB.DZ
- VERSION: 0.00
***************************************************/
#include <stdio.h>
#include <sys/types.h> 
#include <unistd.h> 
#include <signal.h>
#include <string.h>
//#include <time.h>


 	int i =0;
  pid_t x;      // a special kind of int
	char kil[20];  // the string for the command kill will be here

  //time_t T;
  //struct  tm t;

void alarm_handler(int signum){
		if(i==0){

			//T= time(NULL);
			//tm = *localtime(&T);
			//printf("Time is: %02d:%02d:%02d ... ",t.tm_hour, t.tm_min, t.tm_sec);
			//printf("Buzz Buzz Buzz ...\n");

			x = fork();  //fork a new process
			//  here put your player and your sound file
			if (x == 0) execlp("mpg123", "mpg123", "-q", "/path/to/your/ring.mp3", 0, NULL);        
      else{
				//printf("from parent: mpg123 is pid %d\n", x); 
				 sprintf(kil,"kill -s 9 %d",x);   // NOTE: space between 9 and %d MANDATORY !!
				//printf("command: %s\n", kil);
			} 
			i = 1;
			alarm(3); // play the sound for 3s
		}

		else{
		//printf("End ... Buzzing\n");
	  system(kil); //stop mpg123
		i=0;
    //set a new alarm 20min
    alarm(20*60); 
		}
}

int main(){
		
   //printf("ESA is working ...\n");

    //set up alarm handler
    signal(SIGALRM, alarm_handler); //install handler

    //schedule the first alarm
    alarm(3); // 3s

    //pause in a loop
    while(1)  pause();
}
/*******************************  THE END  *********************************/

Re: ESA Eye Strain Avoider !

Posted: Thu Jun 04, 2020 5:55 am
by eekee
Thanks! Something I might actually be able to do, although not after dark. Maybe 5 meters will do - 20 feet is 6.1m.

Re: ESA Eye Strain Avoider !

Posted: Thu Jun 04, 2020 9:33 am
by Muazzam
I wrote something similar years ago and set it as auto-start in Ubuntu:

Code: Select all

# !/usr/bin/env python
import os
from datetime import datetime
from time import sleep
notice = "UIAD"
while (1):
	if (int(datetime.now().minute) % 20 == 0):
		os.system("notify-send "+notice)
		sleep(15*60)
	else:
		sleep(1*60)
However, it was too distracting and I disabled it.

Re: ESA Eye Strain Avoider !

Posted: Thu Jun 04, 2020 10:48 am
by Schol-R-LEA
There are a number of free tools of this sort, actually. I have one which comes as a panel tool with XFCE, and there are at least a half dozen around for Windows.

Most Pomodoro or similar time-management-technique utilities can double for this as well, since part of the idea there is to break your taks up into small sections, with breaks after every three or four 'sprints'.

I keep meaning to try them, but never got around to it.