Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring/reordering the band display #63

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
28 changes: 27 additions & 1 deletion miband.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -689,3 +689,29 @@ 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)

# 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:
# <i> 00 ff <d>
# The excluded items are as follows:
# <i> 01 ff <d>
# 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)