ESA Eye Strain Avoider !
Posted: Tue Jun 02, 2020 10:47 am
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:
to run it in the backgound:
to stop it:
And here's the code " esa.c":
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
Code: Select all
./esa & exit
Code: Select all
pkill esa
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 *********************************/