File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,12 @@ def wait_for_connection():
44
44
# This code will check the connection but only query the module if it has been
45
45
# at least 'n_sec' seconds. Otherwise it 'caches' the response, to keep from
46
46
# hogging the Bluefruit connection with constant queries
47
- connect_check_timestamp = None
47
+ connection_timestamp = None
48
48
is_connected = None
49
49
def check_connection (n_sec ):
50
- if (not connect_check_timestamp ) or (time .monotonic () - connection_timestamp > n_sec ):
50
+ # pylint: disable=global-statement
51
+ global connection_timestamp , is_connected
52
+ if (not connection_timestamp ) or (time .monotonic () - connection_timestamp > n_sec ):
51
53
connection_timestamp = time .monotonic ()
52
54
is_connected = bluefruit .connected
53
55
return is_connected
Original file line number Diff line number Diff line change @@ -36,19 +36,21 @@ def wait_for_connection():
36
36
dotcount = (dotcount + 1 ) % 80
37
37
if dotcount == 79 :
38
38
print ("" )
39
- time .sleep (0.5 )
39
+ time .sleep (0.5 )
40
40
41
41
# This code will check the connection but only query the module if it has been
42
42
# at least 'n_sec' seconds. Otherwise it 'caches' the response, to keep from
43
43
# hogging the Bluefruit connection with constant queries
44
- connect_check_timestamp = None
44
+ connection_timestamp = None
45
45
is_connected = None
46
46
def check_connection (n_sec ):
47
- if (not connect_check_timestamp ) or (time .monotonic () - connection_timestamp > n_sec ):
47
+ # pylint: disable=global-statement
48
+ global connection_timestamp , is_connected
49
+ if (not connection_timestamp ) or (time .monotonic () - connection_timestamp > n_sec ):
48
50
connection_timestamp = time .monotonic ()
49
51
is_connected = bluefruit .connected
50
52
return is_connected
51
-
53
+
52
54
# Unlike most circuitpython code, this runs in two loops
53
55
# one outer loop manages reconnecting bluetooth if we lose connection
54
56
# then one inner loop for doing what we want when connected!
You can’t perform that action at this time.
0 commit comments