Initial commit
This commit is contained in:
commit
863c5174b2
3 changed files with 144 additions and 0 deletions
10
config.h
Normal file
10
config.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
|
||||
#define STUDY_SESSION_25 1
|
||||
|
||||
#define STUDY_SESSION_50 0
|
||||
|
||||
#define BREAK_TIME_5 1
|
||||
|
||||
#define BREAK_TIME_10 0
|
||||
|
BIN
p
Executable file
BIN
p
Executable file
Binary file not shown.
134
pomodoro.c
Normal file
134
pomodoro.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
|
||||
#if STUDY_SESSION_25
|
||||
#define TIMER_S 25
|
||||
#endif
|
||||
|
||||
|
||||
#if STUDY_SESSION_50
|
||||
#define TIMER_S 50
|
||||
#endif
|
||||
|
||||
|
||||
#if BREAK_TIME_5
|
||||
#define TIMER_B 5
|
||||
#endif
|
||||
|
||||
|
||||
#if BREAK_TIME_10
|
||||
#define TIMER_B 10
|
||||
#endif
|
||||
|
||||
#define STUDY 0
|
||||
#define BREAK 1
|
||||
|
||||
|
||||
|
||||
int n_repeat = 0, time_elapsed = 0, timer_s = TIMER_S, timer_b = TIMER_B, check = 0;
|
||||
long time_started = 0;
|
||||
|
||||
|
||||
void get_stuff(void);
|
||||
void start_timer(int);
|
||||
void countdown(long, short, char*);
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
if( argv[1] != NULL ){
|
||||
|
||||
for(int i = 1; i < argc ; i++){
|
||||
|
||||
if( *(argv[i]+1) == 's')
|
||||
timer_s = atoi(argv[i+1]);
|
||||
|
||||
if( *(argv[i]+1) == 'b' )
|
||||
timer_b = atoi(argv[i+1]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
get_stuff();
|
||||
|
||||
|
||||
system("clear");
|
||||
|
||||
for(int i = 1; i <= n_repeat; i++){
|
||||
|
||||
printf("Session %d\n\n", i);
|
||||
|
||||
start_timer(STUDY);
|
||||
start_timer(BREAK);
|
||||
|
||||
printf("%c[3F%c[2K%c[G", 27, 27, 27);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void get_stuff(void){
|
||||
|
||||
printf("Enter number of pomodoro sessions (%d minute periods with %d minute breaks) : ", timer_s, timer_b);
|
||||
|
||||
if ( !(scanf("%d", &n_repeat)) ){
|
||||
printf("\n\nThat's not a number you globussaire\n\n");
|
||||
fprintf(stderr, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void start_timer(int x){
|
||||
|
||||
time_started = time(0);
|
||||
|
||||
if(x == STUDY)
|
||||
countdown(time_started, timer_s, "STUDY SESSION");
|
||||
|
||||
if(x == BREAK)
|
||||
countdown(time_started, timer_b, "BREAK");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void countdown(long time_started, short timer, char *type){
|
||||
|
||||
struct timespec tim;
|
||||
tim.tv_sec = 0;
|
||||
tim.tv_nsec = 333000000;
|
||||
|
||||
int count_timer = 1;
|
||||
short mins = 0, secs = 0;
|
||||
|
||||
|
||||
while(count_timer > 0){
|
||||
|
||||
nanosleep(&tim, NULL);
|
||||
short old_secs = secs;
|
||||
|
||||
time_elapsed = time(0) - time_started;
|
||||
|
||||
count_timer = (timer * 60) - time_elapsed;
|
||||
|
||||
mins = count_timer / 60;
|
||||
secs = count_timer - mins * 60;
|
||||
|
||||
|
||||
if(old_secs != secs){
|
||||
printf("%s => %d:%02d\n", type, mins, secs);
|
||||
printf("%c[1F%c[2K%c[G", 27, 27, 27);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue