From 97e13678d07e66942a1028c72d61140f850d35af Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sun, 16 Apr 2023 19:56:21 -0500 Subject: [PATCH 1/3] Allow configuring/reordering the band display --- constants.py | 13 +++++++++++++ miband.py | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/constants.py b/constants.py index 4e97bd4..4e5d765 100644 --- a/constants.py +++ b/constants.py @@ -101,3 +101,16 @@ class Weekdays(object): saturday = 0x01 << 5 sunday = 0x01 << 6 everyday = 0x01 << 7 + +class DISPLAY_ITEMS(object): + + __metaclass__ = Immutable + STATUS = 0x01 + HEART_RATE = 0x02 + WORKOUT = 0x03 + WEATHER = 0x04 + MI_HOME = 0x05 # I have no clue what this does. Pressing it does nothing for me + NOTIFICATIONS = 0x06 + MORE = 0x07 # While the app doesn't allow you to remove this, I tried and it works perfectly + + ALL_ITEMS = [STATUS, HEART_RATE, WORKOUT, WEATHER, NOTIFICATIONS, MORE] diff --git a/miband.py b/miband.py index a5802e3..2bdeb87 100644 --- a/miband.py +++ b/miband.py @@ -1,7 +1,7 @@ import sys,os,time import logging from bluepy.btle import Peripheral, DefaultDelegate, ADDR_TYPE_RANDOM,ADDR_TYPE_PUBLIC, BTLEException -from constants import UUIDS, AUTH_STATES, ALERT_TYPES, QUEUE_TYPES, MUSICSTATE +from constants import UUIDS, AUTH_STATES, ALERT_TYPES, QUEUE_TYPES, MUSICSTATE, DISPLAY_ITEMS import struct from datetime import datetime, timedelta from Crypto.Cipher import AES @@ -689,3 +689,21 @@ def setMusic(self): buf = bytes([flag, self.pp_state, 0x00]) + position + buf self.writeChunked(3, buf) + + def setBandDisplay(self, included_display_items): + if any(i for i in included_display_items if i not in DISPLAY_ITEMS.ALL_ITEMS): + print("Some of those display items are not valid") + return + + excluded_display_items = [i for i in DISPLAY_ITEMS.ALL_ITEMS if i not in included_display_items] + + included_display_items.insert(0, 0x12) # 0x12 is the band homescreen + + num_included = len(included_display_items) + + included_bytes = [byte for i, d in enumerate(included_display_items) for byte in [i, 0, 0xff, d]] + excluded_bytes = [byte for i, d in enumerate(excluded_display_items) for byte in [i + num_included, 1, 0xff, d]] + + buf = bytes([0x1e, *included_bytes, *excluded_bytes]) + self.writeChunked(2, buf) + From 30052ac4bc877201a423281de9eda2f7fb7cfa42 Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sun, 16 Apr 2023 22:23:00 -0500 Subject: [PATCH 2/3] Add comments explaining band display --- miband.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/miband.py b/miband.py index 2bdeb87..e6b52ad 100644 --- a/miband.py +++ b/miband.py @@ -694,16 +694,24 @@ def setBandDisplay(self, included_display_items): if any(i for i in included_display_items if i not in DISPLAY_ITEMS.ALL_ITEMS): print("Some of those display items are not valid") return - + excluded_display_items = [i for i in DISPLAY_ITEMS.ALL_ITEMS if i not in included_display_items] - + included_display_items.insert(0, 0x12) # 0x12 is the band homescreen - + num_included = len(included_display_items) - + + # The format for the band display has a 1e for a constant header, and 4 bytes for each display item + # i is the item index and d is the display item ID (look in constants.py) + # The included items always show up before the excluded (hidden) items, and are as follows: + # 00 ff + # The excluded items are as follows: + # 01 ff + # So including only the homescreen and "more" display item would be like this + # 1e 00 00 ff 12 01 00 ff 07 02 01 ff 01 03 01 ff 02 04 01 ff 03 05 01 ff 04 06 01 ff 06 + included_bytes = [byte for i, d in enumerate(included_display_items) for byte in [i, 0, 0xff, d]] excluded_bytes = [byte for i, d in enumerate(excluded_display_items) for byte in [i + num_included, 1, 0xff, d]] - + buf = bytes([0x1e, *included_bytes, *excluded_bytes]) self.writeChunked(2, buf) - From fbe90944f49fe0f8f4f541085b14dd7ca7270a23 Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sun, 16 Apr 2023 22:24:22 -0500 Subject: [PATCH 3/3] Remove whitespace --- miband.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miband.py b/miband.py index e6b52ad..12ce24c 100644 --- a/miband.py +++ b/miband.py @@ -694,7 +694,7 @@ def setBandDisplay(self, included_display_items): if any(i for i in included_display_items if i not in DISPLAY_ITEMS.ALL_ITEMS): print("Some of those display items are not valid") return - + excluded_display_items = [i for i in DISPLAY_ITEMS.ALL_ITEMS if i not in included_display_items] included_display_items.insert(0, 0x12) # 0x12 is the band homescreen