aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-04-18 21:36:37 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-04-18 21:36:37 +0200
commit20c5cfb47c32b0c4f0f1050b457cde869462014a (patch)
treed427471d1e4c67993b2d21ffa4d757aecc149ea6
parentSomething is not quite right (diff)
downloadlowbat-bsd-20c5cfb47c32b0c4f0f1050b457cde869462014a.tar.gz
lowbat-bsd-20c5cfb47c32b0c4f0f1050b457cde869462014a.tar.bz2
lowbat-bsd-20c5cfb47c32b0c4f0f1050b457cde869462014a.tar.xz
lowbat-bsd-20c5cfb47c32b0c4f0f1050b457cde869462014a.tar.zst
lowbat-bsd-20c5cfb47c32b0c4f0f1050b457cde869462014a.zip
Finished main program
-rw-r--r--Makefile1
-rw-r--r--asm/jo_r_cpyhead.asm40
-rw-r--r--asm/jo_r_loop.asm46
3 files changed, 59 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index cd09c6c..f97f5b1 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ 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
diff --git a/asm/jo_r_cpyhead.asm b/asm/jo_r_cpyhead.asm
new file mode 100644
index 0000000..421b17c
--- /dev/null
+++ b/asm/jo_r_cpyhead.asm
@@ -0,0 +1,40 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; ;;
+;; 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 ; 17
+ 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 ; 17, notification head len
diff --git a/asm/jo_r_loop.asm b/asm/jo_r_loop.asm
index 43cbc8a..7aa68ac 100644
--- a/asm/jo_r_loop.asm
+++ b/asm/jo_r_loop.asm
@@ -15,13 +15,11 @@
section .text
extern sleep
- extern memset
- extern sprintf
- extern dprintf
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:
@@ -32,31 +30,24 @@ jo_r_loop:
jmp bigloop
bigloop:
- call jo_f_status
+ 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
+ call jo_f_percent ; check the capacity
cmp rax, 0xfe ; in case we couldn't read
je err
- ;; cmp rax, 0xf ; 15%
- cmp rax, 60; 15%
+ cmp rax, 0xf ; 15%
jge sleepalot
- mov rdi, buff
- mov rsi, 0x0
- mov rdx, 17
- call memset
- lea rsi, [rel n_head]
- mov rdx, rax
- call sprintf ; get notification head via sprintf
- mov rsi, rdi
- mov rdi, 0x1
- call dprintf
+ 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(rdi, rsi, rdx, rcx)
+ call jo_n_notify ; jo_n_notify(head: rdi, body: rsi,
+ ; urgency: rdx, timeout: rcx)
speak:
cmp ebp, 0x1
@@ -66,13 +57,12 @@ speak:
sleepabit:
mov rdi, 0x14 ; 20s
- call sleep
+ call sleep ; sleep 20 seconds before next check/notification
jmp bigloop
sleepalot:
- ;; mov rdi, 0xf0 ; 240s
- mov rdi, 40 ; 240s
- call sleep
+ mov rdi, 0xf0 ; 240s
+ call sleep ; sleep 4m if it's fine
jmp bigloop
return:
@@ -82,14 +72,14 @@ return:
err:
mov rdi, 0x2 ; stderr
lea rsi, [rel errmsg]
- call dprintf
- mov rax, 0x1
+ mov rdx, errlen
+ mov rax, 0x4
+ syscall ; write error message on stderr
+ xor rax, rax
retq
section .data
- n_head: db "Low battery: %d%%", 0x0
n_body: db "Please plug in computer", 0x0
+ fmt: db "%s", 0xa, 0x0
errmsg: db "Failed to read battery informations", 0xa, 0x0
-
-section .bss
- buff: resb 17
+ errlen: equ $ - errmsg