-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
46 lines (36 loc) · 1.12 KB
/
app.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
import asyncio
import ble
import mac
import numpy as np
stack = np.array([])
stack_size = 5
threshold = -65
address="9F9AEDF7-D29B-41E7-B291-765EC3E53C77"
def on_tick(rssi):
global stack
global stack_size
global threshold
print(rssi, not mac.is_screen_locked())
if(not mac.is_screen_locked()):
if(len(stack) >= stack_size ):
stack = stack[1:stack_size ]
stack = np.append(stack,rssi)
median_value = np.median(stack)
print(median_value)
if(abs(median_value) >= abs(threshold) ):
print(median_value)
stack = np.array([])
print("mac.lock_screen()")
def on_tick2(rssi):
print(rssi)
def on_scan_device(device_uuids):
return address in device_uuids
def on_found_device():
ble.use_device(address, on_tick, on_error)
def on_error(err):
err = str(err)
if(err == 'Bluetooth device is turned off'):
print(err)
if(err == 'disconnected' or err.find("was not found")):
ble.scan_devices_loop(on_scan_device, on_error,on_found_device)
ble.scan_devices_loop(on_scan_device, on_error,on_found_device)