forked from creotiv/MiBand2
-
Notifications
You must be signed in to change notification settings - Fork 66
/
main.py
82 lines (73 loc) · 2.49 KB
/
main.py
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
import sys
from auth import MiBand3
from cursesmenu import *
from cursesmenu.items import *
from constants import ALERT_TYPES
import time
import os
def call_immediate():
print 'Sending Call Alert'
time.sleep(1)
band.send_alert(ALERT_TYPES.PHONE)
def msg_immediate():
print 'Sending Message Alert'
time.sleep(1)
band.send_alert(ALERT_TYPES.MESSAGE)
def detail_info():
print 'MiBand'
print 'Soft revision:',band.get_revision()
print 'Hardware revision:',band.get_hrdw_revision()
print 'Serial:',band.get_serial()
print 'Battery:', band.get_battery_info()
print 'Time:', band.get_current_time()
print 'Steps:', band.get_steps()
raw_input('Press Enter to continue')
def custom_message():
band.send_custom_alert(5)
def custom_call():
# custom_call
band.send_custom_alert(3)
def custom_missed_call():
band.send_custom_alert(4)
def l(x):
print 'Realtime heart BPM:', x
def heart_beat():
band.start_raw_data_realtime(heart_measure_callback=l)
raw_input('Press Enter to continue')
def change_date():
band.change_date()
MAC_ADDR = sys.argv[1]
print 'Attempting to connect to ', MAC_ADDR
def updateFirmware():
fileName = raw_input('Enter the file Name with Extension\n')
band.dfuUpdate(fileName)
band = MiBand3(MAC_ADDR, debug=True)
band.setSecurityLevel(level = "medium")
# Authenticate the MiBand
if len(sys.argv) > 2:
if band.initialize():
print("Initialized...")
band.disconnect()
sys.exit(0)
else:
band.authenticate()
menu = CursesMenu("MiBand MAC: " + MAC_ADDR, "Select an option")
detail_menu = FunctionItem("View Band Detail info", detail_info)
call_notif = FunctionItem("Send a High Prority Call Notification", call_immediate)
msg_notif = FunctionItem("Send a Medium Prority Message Notification", msg_immediate)
msg_alert = FunctionItem("Send a Message Notification", custom_message)
call_alert = FunctionItem("Send a Call Notification", custom_call)
miss_call_alert = FunctionItem("Send a Missed Call Notification", custom_missed_call)
change_date_time = FunctionItem("Change Date and Time", change_date)
heart_beat_menu = FunctionItem("Get Heart BPM", heart_beat)
dfu_update_menu = FunctionItem("DFU Update", updateFirmware)
menu.append_item(detail_menu)
menu.append_item(call_notif)
menu.append_item(msg_notif)
menu.append_item(msg_alert)
menu.append_item(call_alert)
menu.append_item(change_date_time)
menu.append_item(miss_call_alert)
menu.append_item(heart_beat_menu)
menu.append_item(dfu_update_menu)
menu.show()