Skip to content

Commit

Permalink
Add motion sensor cooldown
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwohlbruck committed May 4, 2022
1 parent 1d9b408 commit a14b781
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions micro/app/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def motion_detected(val):
def user_is_interacting():
global time_since_interactive
time_since_interactive = ticks_ms()
print('time since int:', time_since_interactive)

# If room is lid and motion detected, dequeue pending messages
def dequeue():
Expand Down Expand Up @@ -171,14 +172,13 @@ def pulse_received(data):
global last_motion_detected
global time_since_interactive

# Check if user has interacted with device in the last 10 seconds
user_has_interacted = ticks_ms() - time_since_interactive < 10000
# Check if user has interacted with device in the last 30 seconds
user_has_interacted = ticks_ms() - time_since_interactive < 30000

# Don't light if user has not interacted recently, the room is dark, or motion is not detected
if not user_has_interacted and (not last_room_is_lit or not last_motion_detected):
if active:
message_queue.append(data)
return
if active and not user_has_interacted and (not last_room_is_lit or not last_motion_detected):
message_queue.append(data)
return

global last_active
global last_colors
Expand Down
2 changes: 2 additions & 0 deletions micro/app/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def input_watcher():
# print('motion =', motion_new)
motion_old = motion_new
motion_detected(motion_new == 1)
if motion_new == 1:
user_is_interacting()

# Light sensor
light_values.append(light_new)
Expand Down
5 changes: 4 additions & 1 deletion micro/app/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,13 @@ def flash(color=None):

# Slowly pulse all LEDs
def pulse(color=None, state=None):
global effect
effect = None
sleep_ms(1)

if color:
set_gradient(set_color_gradient(color))

global effect
effect = EFFECT_PULSE
state = state or copy()
start_new_thread(pulse_thread, (state,))
Expand Down

0 comments on commit a14b781

Please sign in to comment.