diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-16 19:18:20 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-16 19:18:20 +0200 |
commit | 754010fba962a7fe859e7f2efb977ec4eff04920 (patch) | |
tree | c0fbd9dd5513d43f0bf0ba84bd91a3117409078f | |
parent | Read function is good (diff) | |
download | lowbat-bsd-754010fba962a7fe859e7f2efb977ec4eff04920.tar.gz lowbat-bsd-754010fba962a7fe859e7f2efb977ec4eff04920.tar.bz2 lowbat-bsd-754010fba962a7fe859e7f2efb977ec4eff04920.tar.xz lowbat-bsd-754010fba962a7fe859e7f2efb977ec4eff04920.tar.zst lowbat-bsd-754010fba962a7fe859e7f2efb977ec4eff04920.zip |
Better read function
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | asm/jo_f_status.asm | 34 | ||||
-rwxr-xr-x | lowbat | bin | 14512 -> 14832 bytes | |||
-rw-r--r-- | src/jo_lowbat.h | 5 | ||||
-rw-r--r-- | src/jo_main.c | 8 | ||||
-rw-r--r-- | src/jo_main.h | 1 |
6 files changed, 25 insertions, 25 deletions
@@ -31,7 +31,7 @@ LINK = -lc TARGET = lowbat # ========================================== ASSEMBLER =========================================== # ASM = nasm -ASMFLAGS = -f +ASMFLAGS = -g -f ASMARCH = elf64 # ============================================ UNIX ============================================== # RM = rm -f diff --git a/asm/jo_f_status.asm b/asm/jo_f_status.asm index cc1deb2..c4f517c 100644 --- a/asm/jo_f_status.asm +++ b/asm/jo_f_status.asm @@ -10,10 +10,16 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; apm status +;; ---------- +;; 0: high +;; 1: low +;; 2: critical +;; 3: charging + section .text extern system - extern malloc - extern printf + extern atoi global jo_f_status jo_f_status: @@ -24,15 +30,9 @@ jo_f_status: mov rax, 0x5 syscall jc err - push rax - mov rdi, 0x5 - call malloc - cmp rax, 0x0 - je err - mov rsi, rax - pop rax mov rdi, rax - mov rdx, 0x4 + mov rsi, buff + mov rdx, 0x1 push rax mov rax, 0x3 syscall @@ -41,17 +41,15 @@ jo_f_status: mov rdi, rax mov rax, 0x6 syscall - mov byte [rsi + 0x4], 0x0 - mov rax, rsi + mov rdi, rsi + call atoi retq err: - mov rax, 0x0 + mov rax, 0xff retq section .data - f_cmd: db "apm | grep Status | awk -F ' ' '{print $3}' > /tmp/lowbat.status", 0x0 - st_file: db "/tmp/lowbat.status", 0x0 - - ;; charging - ;; discharg + f_cmd: db "apm -b > /tmp/lowbat.status", 0x0 + st_file: db "/tmp/lowbat.status", 0x0 + buff: db 0x0, 0x0 Binary files differdiff --git a/src/jo_lowbat.h b/src/jo_lowbat.h index ddc6679..b39243e 100644 --- a/src/jo_lowbat.h +++ b/src/jo_lowbat.h @@ -13,11 +13,14 @@ #ifndef JO_LOWBAT_H #define JO_LOWBAT_H +#include <inttypes.h> + enum { JO_RET_FINE, JO_RET_RD_FAILED }; -char *jo_f_status(void); + +int8_t jo_f_status(void); #endif diff --git a/src/jo_main.c b/src/jo_main.c index 2d19ab8..e5576b3 100644 --- a/src/jo_main.c +++ b/src/jo_main.c @@ -21,13 +21,11 @@ int main(void) { - char *status; + int8_t status; - if (!(status = jo_f_status())) { + if ((status = jo_f_status()) < 0) { return (JO_RET_RD_FAILED); } - printf("status: %s\n", status); - free(status); - status = NULL; + printf("status: %d\n", status); return (JO_RET_FINE); } diff --git a/src/jo_main.h b/src/jo_main.h index 8feabe9..742f1d9 100644 --- a/src/jo_main.h +++ b/src/jo_main.h @@ -17,5 +17,6 @@ #include <stdio.h> #include <stdlib.h> #include <stddef.h> +#include <inttypes.h> #endif |