aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--asm/jo_f_status.asm34
-rwxr-xr-xlowbatbin14512 -> 14832 bytes
-rw-r--r--src/jo_lowbat.h5
-rw-r--r--src/jo_main.c8
-rw-r--r--src/jo_main.h1
6 files changed, 25 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 06dddc7..27c8b92 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/lowbat b/lowbat
index 5de9a67..f5a864d 100755
--- a/lowbat
+++ b/lowbat
Binary files differ
diff --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