From ea0eca4f717d7f4408273613a566f3550d27085b Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 27 Apr 2020 01:02:18 +0200 Subject: Rewrite started --- Makefile | 45 ++++++++++++++-------------- README.org | 2 +- asm/c_args.asm | 47 +++++++++++++++++++++++++++++ asm/f_percent.asm | 47 +++++++++++++++++++++++++++++ asm/f_status.asm | 51 +++++++++++++++++++++++++++++++ asm/jo_c_args.asm | 47 ----------------------------- asm/jo_f_percent.asm | 47 ----------------------------- asm/jo_f_status.asm | 51 ------------------------------- asm/jo_r_cpyhead.asm | 40 ------------------------- asm/jo_r_loop.asm | 85 ---------------------------------------------------- asm/jo_r_lowbat.asm | 33 -------------------- asm/r_cpyhead.asm | 40 +++++++++++++++++++++++++ asm/r_loop.asm | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ asm/r_lowbat.asm | 33 ++++++++++++++++++++ src/jo_n_notify.c | 31 ------------------- src/jo_n_notify.h | 29 ------------------ src/jo_n_speak.c | 45 ---------------------------- src/jo_n_speak.h | 34 --------------------- src/n_notify.c | 31 +++++++++++++++++++ src/n_notify.h | 29 ++++++++++++++++++ src/n_speak.c | 45 ++++++++++++++++++++++++++++ src/n_speak.h | 34 +++++++++++++++++++++ 22 files changed, 466 insertions(+), 465 deletions(-) create mode 100644 asm/c_args.asm create mode 100644 asm/f_percent.asm create mode 100644 asm/f_status.asm delete mode 100644 asm/jo_c_args.asm delete mode 100644 asm/jo_f_percent.asm delete mode 100644 asm/jo_f_status.asm delete mode 100644 asm/jo_r_cpyhead.asm delete mode 100644 asm/jo_r_loop.asm delete mode 100644 asm/jo_r_lowbat.asm create mode 100644 asm/r_cpyhead.asm create mode 100644 asm/r_loop.asm create mode 100644 asm/r_lowbat.asm delete mode 100644 src/jo_n_notify.c delete mode 100644 src/jo_n_notify.h delete mode 100644 src/jo_n_speak.c delete mode 100644 src/jo_n_speak.h create mode 100644 src/n_notify.c create mode 100644 src/n_notify.h create mode 100644 src/n_speak.c create mode 100644 src/n_speak.h diff --git a/Makefile b/Makefile index 99e2e0b..4a2b3b1 100644 --- a/Makefile +++ b/Makefile @@ -12,25 +12,25 @@ default: all -C_SRCS_DIR = src -A_SRCS_DIR = asm +C_SRCS_DIR = src +A_SRCS_DIR = asm PREFIX ?= /usr/local BINPREFIX ?= ${PREFIX}/bin MANPREFIX ?= ${PREFIX}/share/man -C_SRCS += ${C_SRCS_DIR}/jo_n_speak.c -C_SRCS += ${C_SRCS_DIR}/jo_n_notify.c +C_SRCS += ${C_SRCS_DIR}/n_speak.c +C_SRCS += ${C_SRCS_DIR}/n_notify.c -C_OBJS = ${C_SRCS:.c=.o} +C_OBJS = ${C_SRCS:.c=.o} -A_SRCS = ${A_SRCS_DIR}/jo_r_lowbat.asm -A_SRCS += ${A_SRCS_DIR}/jo_r_loop.asm -A_SRCS += ${A_SRCS_DIR}/jo_r_cpyhead.asm -A_SRCS += ${A_SRCS_DIR}/jo_c_args.asm -A_SRCS += ${A_SRCS_DIR}/jo_f_status.asm -A_SRCS += ${A_SRCS_DIR}/jo_f_percent.asm +A_SRCS = ${A_SRCS_DIR}/r_lowbat.asm +A_SRCS += ${A_SRCS_DIR}/r_loop.asm +A_SRCS += ${A_SRCS_DIR}/r_cpyhead.asm +A_SRCS += ${A_SRCS_DIR}/c_args.asm +A_SRCS += ${A_SRCS_DIR}/f_status.asm +A_SRCS += ${A_SRCS_DIR}/f_percent.asm -A_OBJS = ${A_SRCS:.asm=.o} +A_OBJS = ${A_SRCS:.asm=.o} CC = clang CFLAGS += -std=c89 @@ -59,11 +59,12 @@ LDLIBS += -lnotify LDLIBS += -lespeak LDLIBS += -lc -TARGET = lowbat +TARGET = lowbat -ASM = nasm -# ASMFLAGS = -g -ASMARCH = -f elf64 +ASM = yasm +ASMFLAGS = -f elf64 +ASMFLAGS += -p gas +# ASMFLAGS += -g LDFLAGS ?= LDLIBS = ${LDFLAGS} @@ -72,16 +73,16 @@ LDLIBS += -lnotify LDLIBS += -lespeak SHELL := /bin/sh -RM = rm -f -MKDIR = mkdir -p -CP = cp -pf -MV = mv -SED = sed +RM = rm -f +MKDIR = mkdir -p +CP = cp -pf +MV = mv +SED = sed .SUFFIXES: .asm .c .o .asm.o: - ${ASM} ${ASMFLAGS} ${ASMARCH} -o ${.TARGET} ${.IMPSRC} + ${ASM} ${ASMFLAGS} -o ${.TARGET} ${.IMPSRC} .c.o: ${CC} -c ${CFLAGS} ${CINCS} -o ${.TARGET} ${.IMPSRC} diff --git a/README.org b/README.org index ed8486c..da6d27b 100644 --- a/README.org +++ b/README.org @@ -7,7 +7,7 @@ This version will only run on 64-bits BSD systems. It was only tested on FreeBSD - ~libnotify~ - ~espeak~ - ~BSD make~ -- ~nasm~ +- ~yasm~ - ~clang/llvm~ ** Installation diff --git a/asm/c_args.asm b/asm/c_args.asm new file mode 100644 index 0000000..dcca5d3 --- /dev/null +++ b/asm/c_args.asm @@ -0,0 +1,47 @@ +/* ************************************************************************************ */ +/* */ +/* File : c_args.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Check args | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +;; jo_c_args(argc: rdi, *argv[]: rsi) +;; ---------------------------------- +;; returns 0 if args are invalid +;; returns 1 if args are valid + +section .text + extern strncmp + global jo_c_args + +jo_c_args: + cmp rdi, 0x2 + jle no_args + mov rax, [rsi + 0x8 * 0x2] + cmp byte [rax + 0x0], 0x0 + je no_args + push rdi + mov rdi, [rsi + 0x8 * 0x1] + push rsi + mov rsi, reference + mov rdx, reflen + call strncmp + pop rsi + pop rdi + cmp rax, 0x0 + jne no_args + mov rax, 0x1 + retq + +no_args: + xor rax, rax + retq + +section .data + reference: db "--say", 0x0 + reflen: equ $ - reference diff --git a/asm/f_percent.asm b/asm/f_percent.asm new file mode 100644 index 0000000..3a5c1c8 --- /dev/null +++ b/asm/f_percent.asm @@ -0,0 +1,47 @@ +/* ************************************************************************************ */ +/* */ +/* File : f_percent.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Gets batt remaining capacity | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +section .text + extern system + extern atoi + global jo_f_percent + +jo_f_percent: + mov rdi, f_cmd + call system + mov rdi, pr_file + mov rsi, 0x0 + mov rax, 0x5 + syscall + jc err + mov rdi, rax + mov rsi, buff + mov rdx, 0x3 + mov rax, 0x3 + syscall + jc err + mov rax, 0x6 + syscall + xor rax, rax + mov rdi, rsi + call atoi + retq + +err: + mov rax, 0xfe + retq + + +section .data + f_cmd: db "apm -l > /tmp/lowbat.percent", 0x0 + pr_file: db "/tmp/lowbat.percent", 0x0 + buff: db 0x0, 0x0, 0x0, 0x0 diff --git a/asm/f_status.asm b/asm/f_status.asm new file mode 100644 index 0000000..81ff3d8 --- /dev/null +++ b/asm/f_status.asm @@ -0,0 +1,51 @@ +/* ************************************************************************************ */ +/* */ +/* File : f_status.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Gets batt status | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +;; apm status +;; ---------- +;; 0: high +;; 1: low +;; 2: critical +;; 3: charging + +section .text + extern system + global jo_f_status + +jo_f_status: + mov rdi, f_cmd + call system + mov rdi, st_file + mov rsi, 0x0 + mov rax, 0x5 + syscall + jc err + mov rdi, rax + mov rsi, buff + mov rdx, 0x1 + mov rax, 0x3 + syscall + jc err + mov rax, 0x6 + syscall + movsx rax, byte [rsi + 0x0] + sub rax, 0x30 + retq + +err: + mov rax, 0xfe + retq + +section .data + f_cmd: db "apm -b > /tmp/lowbat.status", 0x0 + st_file: db "/tmp/lowbat.status", 0x0 + buff: db 0x0, 0x0 diff --git a/asm/jo_c_args.asm b/asm/jo_c_args.asm deleted file mode 100644 index 67a83c8..0000000 --- a/asm/jo_c_args.asm +++ /dev/null @@ -1,47 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_c_args.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : Check args | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; jo_c_args(argc: rdi, *argv[]: rsi) -;; ---------------------------------- -;; returns 0 if args are invalid -;; returns 1 if args are valid - -section .text - extern strncmp - global jo_c_args - -jo_c_args: - cmp rdi, 0x2 - jle no_args - mov rax, [rsi + 0x8 * 0x2] - cmp byte [rax + 0x0], 0x0 - je no_args - push rdi - mov rdi, [rsi + 0x8 * 0x1] - push rsi - mov rsi, reference - mov rdx, reflen - call strncmp - pop rsi - pop rdi - cmp rax, 0x0 - jne no_args - mov rax, 0x1 - retq - -no_args: - xor rax, rax - retq - -section .data - reference: db "--say", 0x0 - reflen: equ $ - reference diff --git a/asm/jo_f_percent.asm b/asm/jo_f_percent.asm deleted file mode 100644 index 6a41c2f..0000000 --- a/asm/jo_f_percent.asm +++ /dev/null @@ -1,47 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_f_percent.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : Gets batt remaining capacity | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -section .text - extern system - extern atoi - global jo_f_percent - -jo_f_percent: - mov rdi, f_cmd - call system - mov rdi, pr_file - mov rsi, 0x0 - mov rax, 0x5 - syscall - jc err - mov rdi, rax - mov rsi, buff - mov rdx, 0x3 - mov rax, 0x3 - syscall - jc err - mov rax, 0x6 - syscall - xor rax, rax - mov rdi, rsi - call atoi - retq - -err: - mov rax, 0xfe - retq - - -section .data - f_cmd: db "apm -l > /tmp/lowbat.percent", 0x0 - pr_file: db "/tmp/lowbat.percent", 0x0 - buff: db 0x0, 0x0, 0x0, 0x0 diff --git a/asm/jo_f_status.asm b/asm/jo_f_status.asm deleted file mode 100644 index 0c1c39f..0000000 --- a/asm/jo_f_status.asm +++ /dev/null @@ -1,51 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_f_status.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : Gets batt status | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; apm status -;; ---------- -;; 0: high -;; 1: low -;; 2: critical -;; 3: charging - -section .text - extern system - global jo_f_status - -jo_f_status: - mov rdi, f_cmd - call system - mov rdi, st_file - mov rsi, 0x0 - mov rax, 0x5 - syscall - jc err - mov rdi, rax - mov rsi, buff - mov rdx, 0x1 - mov rax, 0x3 - syscall - jc err - mov rax, 0x6 - syscall - movsx rax, byte [rsi + 0x0] - sub rax, 0x30 - retq - -err: - mov rax, 0xfe - retq - -section .data - f_cmd: db "apm -b > /tmp/lowbat.status", 0x0 - st_file: db "/tmp/lowbat.status", 0x0 - buff: db 0x0, 0x0 diff --git a/asm/jo_r_cpyhead.asm b/asm/jo_r_cpyhead.asm deleted file mode 100644 index 4b51542..0000000 --- a/asm/jo_r_cpyhead.asm +++ /dev/null @@ -1,40 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_r_cpyhead.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : Formats and returns notification head title | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -section .text - extern memset - extern sprintf - global jo_r_cpyhead - -jo_r_cpyhead: ; jo_r_cpyhead(percent: rdi) - push rdi - mov rdi, buff - mov rsi, 0x0 - mov rdx, 0x11 - call memset ; memset 0 notification head - lea rsi, [rel n_head] - pop rdi - mov rdx, rdi - mov rdi, rax - xor rax, rax - mov al, 0x1 - push rdi - call sprintf - pop rdi - mov rax, rdi - retq - -section .data - n_head: db "Low battery: %d%%", 0x0 - -section .bss - buff: resb 0x11 diff --git a/asm/jo_r_loop.asm b/asm/jo_r_loop.asm deleted file mode 100644 index 987f68f..0000000 --- a/asm/jo_r_loop.asm +++ /dev/null @@ -1,85 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_r_loop.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : The main loop | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; jo_r_loop(speak (0-1), *argv[]) -;; ------------------------------- - -section .text - extern sleep - extern jo_f_percent - extern jo_f_status - extern jo_n_speak - extern jo_n_notify - extern jo_r_cpyhead - global jo_r_loop - -jo_r_loop: - push rbp - push rbx - mov rbx, rsi - mov ebp, edi - jmp bigloop - -bigloop: - call jo_f_status ; check the status - cmp rax, 0xfe ; in case we couldn't read - je err - cmp rax, 0x3 - je sleepalot - call jo_f_percent ; check the capacity - cmp rax, 0xfe ; in case we couldn't read - je err - cmp rax, 0xf - jge sleepalot - mov rdi, rax - call jo_r_cpyhead - mov rdi, rax - mov rsi, n_body ; notification body - mov rdx, 0x3 ; ciritcal notification - mov rcx, 0x3a98 ; 15000ms notification timeout - call jo_n_notify ; jo_n_notify(head: rdi, body: rsi, - ; urgency: rdx, timeout: rcx) - -speak: - cmp ebp, 0x1 - jne sleepabit - mov rdi, [rbx + 0x8 * 0x2] - call jo_n_speak - -sleepabit: - mov rdi, 0x14 - call sleep ; sleep 20 seconds before next check/notification - jmp bigloop - -sleepalot: - mov rdi, 0xf0 - call sleep ; sleep 240s (4m) if it's fine - jmp bigloop - -return: - xor rax, rax - retq - -err: - mov rdi, 0x2 ; stderr - lea rsi, [rel errmsg] - mov rdx, errlen - mov rax, 0x4 - syscall ; write error message on stderr - xor rax, rax - retq - -section .data - n_body: db "Please plug in computer", 0x0 - fmt: db "%s", 0xa, 0x0 - errmsg: db "Failed to read battery informations", 0xa, 0x0 - errlen: equ $ - errmsg diff --git a/asm/jo_r_lowbat.asm b/asm/jo_r_lowbat.asm deleted file mode 100644 index 4bc6126..0000000 --- a/asm/jo_r_lowbat.asm +++ /dev/null @@ -1,33 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; ;; -;; File : jo_r_lowbat.asm /_________/ ;; -;; Author : Joe | ;; -;; Date : 04/2020 | ;; -;; Info : The main program | ;; -;; / | ;; -;; \ / ;; -;; \_____/ ;; -;; ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; Files prefixes -;; -------------- -;; f: fetch -;; n: notify -;; r: run -;; c: check - -section .text - extern jo_c_args - extern jo_r_loop - global main - -main: - call jo_c_args - mov rdi, rax - call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[]) - - xor rax, rax - xor rdi, rdi - mov rax, 0x1 - syscall diff --git a/asm/r_cpyhead.asm b/asm/r_cpyhead.asm new file mode 100644 index 0000000..15b0d9e --- /dev/null +++ b/asm/r_cpyhead.asm @@ -0,0 +1,40 @@ +/* ************************************************************************************ */ +/* */ +/* File : r_cpyhead.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Formats and returns notification head title | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +section .text + extern memset + extern sprintf + global jo_r_cpyhead + +jo_r_cpyhead: ; jo_r_cpyhead(percent: rdi) + push rdi + mov rdi, buff + mov rsi, 0x0 + mov rdx, 0x11 + call memset ; memset 0 notification head + lea rsi, [rel n_head] + pop rdi + mov rdx, rdi + mov rdi, rax + xor rax, rax + mov al, 0x1 + push rdi + call sprintf + pop rdi + mov rax, rdi + retq + +section .data + n_head: db "Low battery: %d%%", 0x0 + +section .bss + buff: resb 0x11 diff --git a/asm/r_loop.asm b/asm/r_loop.asm new file mode 100644 index 0000000..308a9f4 --- /dev/null +++ b/asm/r_loop.asm @@ -0,0 +1,85 @@ +/* ************************************************************************************ */ +/* */ +/* File : r_loop.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : The main loop | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +;; jo_r_loop(speak (0-1), *argv[]) +;; ------------------------------- + +section .text + extern sleep + extern jo_f_percent + extern jo_f_status + extern jo_n_speak + extern jo_n_notify + extern jo_r_cpyhead + global jo_r_loop + +jo_r_loop: + push rbp + push rbx + mov rbx, rsi + mov ebp, edi + jmp bigloop + +bigloop: + call jo_f_status ; check the status + cmp rax, 0xfe ; in case we couldn't read + je err + cmp rax, 0x3 + je sleepalot + call jo_f_percent ; check the capacity + cmp rax, 0xfe ; in case we couldn't read + je err + cmp rax, 0xf + jge sleepalot + mov rdi, rax + call jo_r_cpyhead + mov rdi, rax + mov rsi, n_body ; notification body + mov rdx, 0x3 ; ciritcal notification + mov rcx, 0x3a98 ; 15000ms notification timeout + call jo_n_notify ; jo_n_notify(head: rdi, body: rsi, + ; urgency: rdx, timeout: rcx) + +speak: + cmp ebp, 0x1 + jne sleepabit + mov rdi, [rbx + 0x8 * 0x2] + call jo_n_speak + +sleepabit: + mov rdi, 0x14 + call sleep ; sleep 20 seconds before next check/notification + jmp bigloop + +sleepalot: + mov rdi, 0xf0 + call sleep ; sleep 240s (4m) if it's fine + jmp bigloop + +return: + xor rax, rax + retq + +err: + mov rdi, 0x2 ; stderr + lea rsi, [rel errmsg] + mov rdx, errlen + mov rax, 0x4 + syscall ; write error message on stderr + xor rax, rax + retq + +section .data + n_body: db "Please plug in computer", 0x0 + fmt: db "%s", 0xa, 0x0 + errmsg: db "Failed to read battery informations", 0xa, 0x0 + errlen: equ $ - errmsg diff --git a/asm/r_lowbat.asm b/asm/r_lowbat.asm new file mode 100644 index 0000000..f721867 --- /dev/null +++ b/asm/r_lowbat.asm @@ -0,0 +1,33 @@ +/* ************************************************************************************ */ +/* */ +/* File : r_lowbat.asm /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : The main program | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +;; Files prefixes +;; -------------- +;; f: fetch +;; n: notify +;; r: run +;; c: check + +section .text + extern jo_c_args + extern jo_r_loop + global main + +main: + call jo_c_args + mov rdi, rax + call jo_r_loop ; jo_r_loop(speak: 0-1, *argv[]) + + xor rax, rax + xor rdi, rdi + mov rax, 0x1 + syscall diff --git a/src/jo_n_notify.c b/src/jo_n_notify.c deleted file mode 100644 index f98ea1d..0000000 --- a/src/jo_n_notify.c +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************************/ -/* */ -/* 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(JO_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 deleted file mode 100644 index a72395a..0000000 --- a/src/jo_n_notify.h +++ /dev/null @@ -1,29 +0,0 @@ -/****************************************************************************************/ -/* */ -/* 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 - -#define JO_LOWBAT "lowbat" - -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 deleted file mode 100644 index 48fcbaa..0000000 --- a/src/jo_n_speak.c +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************************/ -/* */ -/* 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_ERROR err; - int32_t samplerate; - - samplerate = espeak_Initialize - (AUDIO_OUTPUT_PLAYBACK, - 500, - NULL, - 0); - if (samplerate == -1) { - dprintf(2, "Failed to initialize espeak\n"); - exit(JO_RET_ESPEAK_FAILED); - } - espeak_SetVoiceByName(JO_ESPEAK_VOICE); - err = espeak_Synth - (msg, - strlen(msg) + 1, - 0, - POS_CHARACTER, - 0, - espeakCHARS_AUTO | espeakENDPAUSE, - NULL, - NULL); - if (err != EE_OK) { - dprintf(STDERR_FILENO, "espeak synth error\n"); - } - espeak_Synchronize(); - espeak_Terminate(); -} diff --git a/src/jo_n_speak.h b/src/jo_n_speak.h deleted file mode 100644 index 79ca683..0000000 --- a/src/jo_n_speak.h +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************************/ -/* */ -/* 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 -#include -#include -#include -#include - -enum -{ - JO_RET_FINE, - JO_RET_RD_FAILED, - JO_RET_ESPEAK_FAILED -}; - -#define JO_ESPEAK_VOICE "English" - -void jo_n_speak(const char *); - -#endif diff --git a/src/n_notify.c b/src/n_notify.c new file mode 100644 index 0000000..3ed6d40 --- /dev/null +++ b/src/n_notify.c @@ -0,0 +1,31 @@ +/* ************************************************************************************ */ +/* */ +/* File : 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(JO_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/n_notify.h b/src/n_notify.h new file mode 100644 index 0000000..0c69fa7 --- /dev/null +++ b/src/n_notify.h @@ -0,0 +1,29 @@ +/* ************************************************************************************ */ +/* */ +/* File : 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 + +#define JO_LOWBAT "lowbat" + +void jo_n_notify( + const char[], + const char[], + NotifyUrgency, + int32_t + ); + +#endif diff --git a/src/n_speak.c b/src/n_speak.c new file mode 100644 index 0000000..c6d46f0 --- /dev/null +++ b/src/n_speak.c @@ -0,0 +1,45 @@ +/* ************************************************************************************ */ +/* */ +/* File : n_speak.c /_________/ */ +/* Author : Joe | */ +/* Date : 04/2020 | */ +/* Info : Uses espeak lib to speak | */ +/* / | */ +/* \ / */ +/* \_____/ */ +/* */ +/* ************************************************************************************ */ + +#include + +void +jo_n_speak(const char *msg) +{ + espeak_ERROR err; + int32_t samplerate; + + samplerate = espeak_Initialize + (AUDIO_OUTPUT_PLAYBACK, + 500, + NULL, + 0); + if (samplerate == -1) { + dprintf(2, "Failed to initialize espeak\n"); + exit(JO_RET_ESPEAK_FAILED); + } + espeak_SetVoiceByName(JO_ESPEAK_VOICE); + err = espeak_Synth + (msg, + strlen(msg) + 1, + 0, + POS_CHARACTER, + 0, + espeakCHARS_AUTO | espeakENDPAUSE, + NULL, + NULL); + if (err != EE_OK) { + dprintf(STDERR_FILENO, "espeak synth error\n"); + } + espeak_Synchronize(); + espeak_Terminate(); +} diff --git a/src/n_speak.h b/src/n_speak.h new file mode 100644 index 0000000..dd65b7e --- /dev/null +++ b/src/n_speak.h @@ -0,0 +1,34 @@ +/* ************************************************************************************ */ +/* */ +/* File : 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 +#include +#include +#include +#include + +enum +{ + JO_RET_FINE, + JO_RET_RD_FAILED, + JO_RET_ESPEAK_FAILED +}; + +#define JO_ESPEAK_VOICE "English" + +void jo_n_speak(const char *); + +#endif -- cgit v1.2.3