ESA Eye Strain Avoider !

Programming, for all ages and all languages.
Post Reply
nullpointer
Posts: 8
Joined: Sat Jun 29, 2019 8:58 am

ESA Eye Strain Avoider !

Post 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  *********************************/
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: ESA Eye Strain Avoider !

Post 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.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: ESA Eye Strain Avoider !

Post 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.
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: ESA Eye Strain Avoider !

Post 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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
Post Reply