From 4a41fd428bfd4ed95446e6f24bbd6ec60d87bf50 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 17 Apr 2020 16:32:09 +0200 Subject: Using libespeak and libnotify --- Makefile | 82 +++++++++++++++++++++++++++++++++---------------------- src/jo_lowbat.c | 45 ++++++++++++++++++++++++++++++ src/jo_lowbat.h | 8 +++++- src/jo_main.c | 37 ------------------------- src/jo_main.h | 22 --------------- src/jo_n_notify.c | 32 ++++++++++++++++++++++ src/jo_n_notify.h | 27 ++++++++++++++++++ src/jo_n_speak.c | 29 ++++++++++++++++++++ src/jo_n_speak.h | 21 ++++++++++++++ 9 files changed, 210 insertions(+), 93 deletions(-) create mode 100644 src/jo_lowbat.c delete mode 100644 src/jo_main.c delete mode 100644 src/jo_main.h create mode 100644 src/jo_n_notify.c create mode 100644 src/jo_n_notify.h create mode 100644 src/jo_n_speak.c create mode 100644 src/jo_n_speak.h diff --git a/Makefile b/Makefile index bc3350e..9c092ba 100644 --- a/Makefile +++ b/Makefile @@ -11,70 +11,86 @@ ########################################################################################## default: all - -SHELL := /bin/sh -# ============================================ DIRS ============================================== # +# ====================================== DIRS ========================================== # C_SRCS_DIR = src A_SRCS_DIR = asm -# =========================================== FILES ============================================== # -C_SRCS = ${C_SRCS_DIR}/jo_main.c -# ------------------------------------------------------------------------------------------------ # +# ====================================== FILES ========================================= # +C_SRCS = ${C_SRCS_DIR}/jo_lowbat.c +C_SRCS += ${C_SRCS_DIR}/jo_n_speak.c +C_SRCS += ${C_SRCS_DIR}/jo_n_notify.c +# -------------------------------------------------------------------------------------- # C_OBJS = ${C_SRCS:.c=.o} -# ------------------------------------------------------------------------------------------------ # +# -------------------------------------------------------------------------------------- # A_SRCS = ${A_SRCS_DIR}/jo_f_status.asm A_SRCS += ${A_SRCS_DIR}/jo_f_percent.asm -# ------------------------------------------------------------------------------------------------ # +# -------------------------------------------------------------------------------------- # A_OBJS = ${A_SRCS:.asm=.o} -# ========================================== COMPILER ============================================ # +# ===================================== COMPILER ======================================= # CC = clang -# ------------------------------------------------------------------------------------------------ # -CFLAGS = -std=c89 +# -------------------------------------------------------------------------------------- # +CFLAGS = -std=c89 CFLAGS += -Wall CFLAGS += -Wextra +CFLAGS += -Wno-comment +CFLAGS += -Wno-long-long +CFLAGS += -Wno-c99-extensions +CFLAGS += -Wno-variadic-macros CFLAGS += -Werror CFLAGS += -pedantic CFLAGS += ${DEBUG} +# -------------------------------------------------------------------------------------- # # CFLAGS += ${OPTI} -# ------------------------------------------------------------------------------------------------ # +# -------------------------------------------------------------------------------------- # OPTI = -O2 -pipe -DEBUG = -glldb -# ------------------------------------------------------------------------------------------------ # -LINK = -lc -# ------------------------------------------------------------------------------------------------ # +# -------------------------------------------------------------------------------------- # +DEBUG = -glldb +# DEBUG += -fsanitize=address +# -------------------------------------------------------------------------------------- # +CINCS = -Isrc/ +CINCS += -I/usr/local/include +CINCS += -I/usr/local/include/glib-2.0 +CINCS += -I/usr/local/lib/glib-2.0/include +CINCS += -I/usr/local/include/gdk-pixbuf-2.0 +# -------------------------------------------------------------------------------------- # +LINK = -L/usr/local/lib +LINK += -lnotify +LINK += -lespeak +LINK += -lc +# -------------------------------------------------------------------------------------- # TARGET = lowbat -# ========================================== ASSEMBLER =========================================== # +# ===================================== ASSEMBLER ====================================== # ASM = nasm ASMFLAGS = -g -f ASMARCH = elf64 -# ============================================ UNIX ============================================== # +# ======================================= UNIX ========================================= # +SHELL := /bin/sh RM = rm -f MKDIR = mkdir -p CP = cp MV = mv SED = sed -# ============================================ RULES ============================================= # - +# ======================================= RULES ======================================== # .SUFFIXES: .asm .c .o - +.PHONY: all clean fclean re depend +# -------------------------------------------------------------------------------------- # .asm.o: ${ASM} ${ASMFLAGS} ${ASMARCH} -o ${.TARGET} ${.IMPSRC} - +# -------------------------------------------------------------------------------------- # .c.o: - ${CC} -c ${CFLAGS} -I${C_SRCS_DIR} -o ${.TARGET} ${.IMPSRC} - + ${CC} -c ${CFLAGS} ${CINCS} -o ${.TARGET} ${.IMPSRC} +# -------------------------------------------------------------------------------------- # ${TARGET}: ${A_OBJS} ${C_OBJS} - ${CC} ${CFLAGS} -I${C_SRCS_DIR} -o ${.TARGET} ${.ALLSRC} ${LINK} - + ${CC} ${CFLAGS} ${CINCS} -o ${.TARGET} ${.ALLSRC} ${LINK} +# -------------------------------------------------------------------------------------- # depend: - ${CC} -I${C_SRCS_DIR} -E -MM ${C_SRCS} > .depend + ${CC} ${CINCS} -E -MM ${C_SRCS} > .depend ${SED} 's/^/${C_SRCS_DIR}\//' .depend > .depend.tmp ${MV} .depend.tmp .depend - +# -------------------------------------------------------------------------------------- # all: depend ${TARGET} - +# -------------------------------------------------------------------------------------- # clean: ${RM} ${C_OBJS} ${A_OBJS} ${TARGET}.core .depend .depend.tmp ${TARGET} - -re: fclean all - -.PHONY: all clean fclean re depend +# -------------------------------------------------------------------------------------- # +re: clean all +# ======================================== EOF ========================================= # diff --git a/src/jo_lowbat.c b/src/jo_lowbat.c new file mode 100644 index 0000000..da7c575 --- /dev/null +++ b/src/jo_lowbat.c @@ -0,0 +1,45 @@ +/****************************************************************************************/ +/* */ +/* File : jo_lowbat.c /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : The main | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#include +#include + +/* +** Files prefixes +** -------------- +** f: fetch +** n: notify +*/ + +int +main( + int argc, + const char *argv[] + ) +{ + int8_t status; + int8_t percent; + + (void)argc; + (void)argv; + if ((status = jo_f_status()) == -2) { + return (JO_RET_RD_FAILED); + } + if ((percent = jo_f_percent()) == -3) { + return (JO_RET_RD_FAILED); + } + printf("status: %hhd, %hhd%%\n", status, percent); + /* NOTIFY-SEND */ + jo_n_notify("VEGA: Yo", "Welcome", NOTIFY_URGENCY_LOW, 5000); + jo_n_speak("Heya!"); + return (JO_RET_FINE); +} diff --git a/src/jo_lowbat.h b/src/jo_lowbat.h index 9a3b9e3..9e1fa7f 100644 --- a/src/jo_lowbat.h +++ b/src/jo_lowbat.h @@ -13,7 +13,13 @@ #ifndef JO_LOWBAT_H #define JO_LOWBAT_H -#include +#include +#include +#include +#include +#include +#include +#include enum { diff --git a/src/jo_main.c b/src/jo_main.c deleted file mode 100644 index a6d05b1..0000000 --- a/src/jo_main.c +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************************/ -/* */ -/* File : jo_main.c /_________/ */ -/* Author : Joe | */ -/* Date : 04/2020 | */ -/* Info : The main | */ -/* / | */ -/* \ / */ -/* \_____/ */ -/* */ -/****************************************************************************************/ - -#include - -/* -** Files prefixes -** -------------- -** f: fetch -** n: notify -*/ - -int -main(void) -{ - int8_t status; - int8_t percent; - - if ((status = jo_f_status()) == -2) { - return (JO_RET_RD_FAILED); - } - if ((percent = jo_f_percent()) == -3) { - return (JO_RET_RD_FAILED); - } - printf("status: %hhd, %hhd%%\n", status, percent); - /* ESPEAK */ - return (JO_RET_FINE); -} diff --git a/src/jo_main.h b/src/jo_main.h deleted file mode 100644 index 742f1d9..0000000 --- a/src/jo_main.h +++ /dev/null @@ -1,22 +0,0 @@ -/****************************************************************************************/ -/* */ -/* File : jo_main.h /_________/ */ -/* Author : Joe | */ -/* Date : 04/2020 | */ -/* | */ -/* / | */ -/* \ / */ -/* \_____/ */ -/* */ -/****************************************************************************************/ - -#ifndef JO_MAIN_H -#define JO_MAIN_H - -#include -#include -#include -#include -#include - -#endif diff --git a/src/jo_n_notify.c b/src/jo_n_notify.c new file mode 100644 index 0000000..7abb827 --- /dev/null +++ b/src/jo_n_notify.c @@ -0,0 +1,32 @@ +/****************************************************************************************/ +/* */ +/* File : jo_n_notify.c /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Uses libnotify lib to notify | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#include + +void +jo_n_notify( + const char head[], + const char body[], + NotifyUrgency u, + int32_t t + ) +{ + NotifyNotification *n; + + notify_init("lowbat"); + n = notify_notification_new(head, body, NULL); + notify_notification_set_urgency(n, u); + notify_notification_set_timeout(n, t); + notify_notification_show(n, NULL); + notify_uninit(); + n = NULL; +} diff --git a/src/jo_n_notify.h b/src/jo_n_notify.h new file mode 100644 index 0000000..7011baa --- /dev/null +++ b/src/jo_n_notify.h @@ -0,0 +1,27 @@ +/****************************************************************************************/ +/* */ +/* File : jo_n_notify.h /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Uses libnotify lib to notify | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#ifndef JO_N_NOTIFY_H +#define JO_N_NOTIFY_H + +#include +#include +#include + +void jo_n_notify( + const char[], + const char[], + NotifyUrgency, + int32_t + ); + +#endif diff --git a/src/jo_n_speak.c b/src/jo_n_speak.c new file mode 100644 index 0000000..4db4113 --- /dev/null +++ b/src/jo_n_speak.c @@ -0,0 +1,29 @@ +/****************************************************************************************/ +/* */ +/* File : jo_n_speak.c /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Uses espeak lib to speak | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#include + +void +jo_n_speak(const char *msg) +{ + espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 0, 0x0, 0); + espeak_Synth(msg, + strlen(msg), + 0, + POS_CHARACTER, + 0, + espeakCHARS_UTF8 | espeakENDPAUSE, + 0x0, + 0x0); + espeak_Synchronize(); + espeak_Terminate(); +} diff --git a/src/jo_n_speak.h b/src/jo_n_speak.h new file mode 100644 index 0000000..36dced4 --- /dev/null +++ b/src/jo_n_speak.h @@ -0,0 +1,21 @@ +/****************************************************************************************/ +/* */ +/* File : jo_n_speak.h /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Use espeak lib to speak | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/****************************************************************************************/ + +#ifndef JO_N_SPEAK_H +#define JO_N_SPEAK_H + +#include +#include + +void jo_n_speak(const char *); + +#endif -- cgit v1.2.3