From 29835759655b94e7f45b68489ee14e3b4308570d Mon Sep 17 00:00:00 2001
From: JozanLeClerc <bousset.rudy@gmail.com>
Date: Thu, 16 Apr 2020 19:45:51 +0200
Subject: Now getting percent

---
 Makefile             |  1 +
 asm/jo_f_percent.asm | 29 +++++++++++++++++++++++++++++
 src/jo_lowbat.h      |  1 +
 src/jo_main.c        |  6 +++++-
 4 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 asm/jo_f_percent.asm

diff --git a/Makefile b/Makefile
index 27c8b92..206a3f7 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ C_SRCS		 = ${C_SRCS_DIR}/jo_main.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 ============================================ #
diff --git a/asm/jo_f_percent.asm b/asm/jo_f_percent.asm
new file mode 100644
index 0000000..765ca99
--- /dev/null
+++ b/asm/jo_f_percent.asm
@@ -0,0 +1,29 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;                                                                                      ;;
+;;  File      : jo_f_percent.asm                                          /_________/   ;;
+;;  Author    : Joe                                                             |       ;;
+;;  Date      : 04/2020                                                         |       ;;
+;;  Info      : gets batt remaining capacity                                    |       ;;
+;;                                                                      /       |       ;;
+;;                                                                      \       /       ;;
+;;                                                                       \_____/        ;;
+;;                                                                                      ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+section .text
+	extern system
+	global jo_f_percent
+
+jo_f_percent:
+	mov		rdi, f_cmd
+	call	system
+	retq
+
+err:
+	mov		rax, 0xff
+	retq
+
+
+section .data
+	f_cmd:	db "apm -l > /tmp/lowbat.percent", 0x0
+	buff:	db 0x0, 0x0, 0x0, 0x0
diff --git a/src/jo_lowbat.h b/src/jo_lowbat.h
index b39243e..9a3b9e3 100644
--- a/src/jo_lowbat.h
+++ b/src/jo_lowbat.h
@@ -22,5 +22,6 @@ enum
 };
 
 int8_t	jo_f_status(void);
+int8_t	jo_f_percent(void);
 
 #endif
diff --git a/src/jo_main.c b/src/jo_main.c
index e5576b3..7ee0c83 100644
--- a/src/jo_main.c
+++ b/src/jo_main.c
@@ -22,10 +22,14 @@ int
 main(void)
 {
 	int8_t	status;
+	int8_t	percent;
 
 	if ((status = jo_f_status()) < 0) {
 		return (JO_RET_RD_FAILED);
 	}
-	printf("status: %d\n", status);
+	if ((percent = jo_f_percent()) < 0) {
+		return (JO_RET_RD_FAILED);
+	}
+	printf("status: %hhd, %hhd%%\n", status, percent);
 	return (JO_RET_FINE);
 }
-- 
cgit v1.2.3