-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBatteryLevelDigits_210_v2.pbp
194 lines (182 loc) · 4.88 KB
/
BatteryLevelDigits_210_v2.pbp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
; Always display current battery level in statusbar.
; Also displays bluetooth connection status icon.
; It is not currently updated automatically on bt connection gain/lose.
;
; Note that this patch might slightly increase battery consumption
; (though not much more than regular watchface/app showing battery state).
#ver 210 219
; Options:
;@battery_icon_no_stock
; Never show stock battery icon
;@battery_no_digits
; Don't show battery level with number
;@statusbar_no_bluetooth
; Don't show bluetooth status icon
;@statusbar_invert_bluetooth_icon_when_disconnected
; Always show BT icon, but invert when connection lost
; (default behaviour is to only show icon when bluetooth connection is active)
00 BF ?4 ?4 @
1F B5 ?4 8D F8 00 00 C0 F3 07 23 C0 F3 07 40
8D F8 02 00 8D F8 01 30 00 9B 00 20 {
proc battery_state_service_peek
}
0C B4 7F B5 08 9A 05 46 {
proc snprintf
}
F8 B5 00 AF 04 46 {
proc fonts_get_system_font
}
82 B0 F0 B5 0E 46 91 B0 {
proc graphics_draw_text
}
"RESOURCE_ID_GOTHIC_14" 00 {
global res_id_gothic_14
}
03 4b 1b 78 13 b1 03 4b {
proc is_vibro_disabled
}
08 b5 ?4 00 30 18 bf 01 20 08 bd
; and for disambiguation:
38 b5 0c 46 15 46 10 b1
{
proc is_bluetooth_connected
}
1f b5 04 46 c8 68 04 2a {
proc status_bar_draw_icon
}
90 f8 27 30 61 f3 02 03 {
proc graphics_context_set_compositing_mode
}
; for disambiguation (as there seems to be more than one such icon):
"Legal" 00 00
?32
@
?4 04 00 00 10 00 00 00 00 07 00 0b 00
77 00 00 00 67 00 00 00 57 00 00 00 36 00 00 00
55 00 00 00 63 00 00 00 55 00 00 00 36 00 00 00
57 00 00 00 67 00 00 00 77 00 00 00
{
global icon_bluetooth
}
#ifdef battery_icon_no_stock
; This matches middle of status_bar_draw procedure,
; the part responsible for determining desired
; battery level icon and drawing it if needed.
;
; prev: launch custom drawing proc if needed
2B 68 73 B1 20 46 00 21 ?4 14 4B 20 46
19 68 06 22 8D 23 ?4 C0 F1 88 00
05 46 00 E0 8D 25
; next: BL is_vibro_disabled
{
B.W my_code
; Skip unneeded now code to position label correctly
DCB "SkipSkipSkipSkipSkipSkipSkipSkip"
global continue
}
#else
; Use the same mask, but place call after its end
; prev: launch custom drawing proc if needed
; here: draw battery icon if any, and place offset to R5
2B 68 73 B1 20 46 00 21 ?4 14 4B 20 46
19 68 06 22 8D 23 ?4 C0 F1 88 00
05 46 00 E0 8D 25
@ ?4
{
; was: BL is_vibro_disabled
B.W my_code
global continue
}
#endif
; Place our code to floating block
{
proc my_code
#ifdef battery_icon_no_stock
MOV R5, 141 ; initialize offset: there was no battery icon, so just retain few pixel field
#endif
; else - it was initialized when stock icon was (or wasn't) drawn
#ifndef battery_no_digits
BL battery_state_service_peek ; FIXME: doing this at every redraw might be power-consuming?
; now R0 contains a BatteryChargeState structure:
; 00 . is_plugged . is_charging . percent
UXTB R0, R0 ; just throw away charging info for now
MOV R3, R0
ADD R0, SP,16 ; use free space in stack (max is 0x24=36; for this string maximum is 20 chars)
MOV R1, 5 ; buffer size
ADR R2, format
PUSH {R0} ; store it for later use
BL snprintf
; now we have complete "nn%" string at [old_SP+16]
LDR R0, fontname
BL fonts_get_system_font
MOV R2, R0 ; font
POP {R1} ; restore percentage value into R1, and restore old SP value
; now calculate text width
CMP R1, 100
BNE narrow
MOV R1, 15 ; text width
B width_ok
narrow:
MOV R1, 10 ; text width
width_ok:
MOV R0, 0
STR R0, [SP,4] ; overflow_mode
STR R0, [SP,8] ; alignment
STR R0, [SP,12] ; layout
MOV R0, R4 ; ctx
MOV R3, R1 ; text width
ADD R3, R3,0x000E0000 ; height: 0xE = 14 = statusbar height
STR R3, [SP] ; box_2
LDR R3, yminus ; y = -1
ADD R3, R5 ; x: offset from the right...
SUB R3, R1 ; ...minus field width
; now while we hold text width, update R5
SUB R5, R1 ; hold that space from other icons
SUB R5, 2 ; and hold some more space (field)
; and continue calling preparation
ADD R1, SP,16 ; text
; now R3 is box_1
BL graphics_draw_text
#endif
#ifndef statusbar_no_bluetooth
#ifndef statusbar_invert_bluetooth_icon_when_disconnected
BL is_bluetooth_connected
CBZ R0, bluetooth_end ; no connection -> no icon
#endif
#ifdef statusbar_invert_bluetooth_icon_when_disconnected
BL is_bluetooth_connected
MOV R1, R0 ; mode (inversion) depends on connection status
#else
MOV R1, 1 ; always white-on-black
#endif
MOV R0, R4
BL graphics_context_set_compositing_mode
MOV R0, R4 ; context
LDR R1, bticon
MOV R2, 6 ; icon shifted to the right
MOV R3, R5 ; shift value
BL status_bar_draw_icon
SUB R5, R0 ; hold icon width space
SUB R5, 2 ; ... and 2-pixel field
bluetooth_end:
#endif
#ifndef battery_icon_no_stock
BL is_vibro_disabled ; restore overwritten code
#endif
B.W continue
; data block
ALIGN 4
#ifndef battery_no_digits
fontname:
DCD res_id_gothic_14
format:
DCB "%d" 00
ALIGN 4
yminus:
DCD 0xFFFF0000
#endif
#ifndef statusbar_no_bluetooth
bticon:
DCD icon_bluetooth
#endif
}