OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: ESA Eye Strain Avoider !
PostPosted: Tue Jun 02, 2020 10:47 am 
Offline

Joined: Sat Jun 29, 2019 8:58 am
Posts: 8
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:
gcc -a esa esa.c

to run it in the backgound:
Code:
./esa & exit

to stop it:
Code:
pkill esa


And here's the code " esa.c":
Code:
/***************************************************
- 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  *********************************/


Top
 Profile  
 
 Post subject: Re: ESA Eye Strain Avoider !
PostPosted: Thu Jun 04, 2020 5:55 am 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 812
Location: Hyperspace
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


Top
 Profile  
 
 Post subject: Re: ESA Eye Strain Avoider !
PostPosted: Thu Jun 04, 2020 9:33 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:59 am
Posts: 543
Location: Shahpur, Layyah, Pakistan
I wrote something similar years ago and set it as auto-start in Ubuntu:

Code:
# !/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.


Top
 Profile  
 
 Post subject: Re: ESA Eye Strain Avoider !
PostPosted: Thu Jun 04, 2020 10:48 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group