Skip to content

Commit

Permalink
Move data to external hardware file (Fixes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwohlbruck committed May 11, 2022
1 parent a14b781 commit 8a8e652
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
20 changes: 10 additions & 10 deletions docs/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
- [Signing out](#signing-out)

## LED indicator colors
| | Color | Lamp mode |
|--------------------------------------------------------|------------------------|------------------------|
| <img src="indicators/dot-blue-pulse.svg" width='12'> | Blue pulsing | Bluetooth pairing mode |
| <img src="indicators/dot-blue.svg" width='12'> | Blue solid | Bluetooth connected |
| <img src="indicators/dot-amber-pulse.svg" width='12'> | Amber pulsing | Connecting to wifi |
| <img src="indicators/dot-amber.svg" width='12'> | Amber solid | Connected to wifi |
| <img src="indicators/dot-green-pulse.svg" width='12'> | Green pulsing | Connecting to server |
| <img src="indicators/dot-green.svg" width='12'> | Green solid | Successfully set up |
| <img src="indicators/dot-red.svg" width='12'> | Red solid | Error |
| <img src="indicators/dot-white-pulse.svg" width='12'> | White pulsing | Factory resetting |
| | Color | Lamp mode |
|--------------------------------------------------------|------------------------|---------------------------------------|
| <img src="indicators/dot-blue-pulse.svg" width='12'> | Blue pulsing | Bluetooth pairing mode |
| <img src="indicators/dot-blue.svg" width='12'> | Blue solid | Bluetooth connected |
| <img src="indicators/dot-amber-pulse.svg" width='12'> | Amber pulsing | Connecting to wifi |
| <img src="indicators/dot-amber.svg" width='12'> | Amber solid | Connected to wifi |
| <img src="indicators/dot-green-pulse.svg" width='12'> | Green pulsing | Connecting to server |
| <img src="indicators/dot-green.svg" width='12'> | Green solid | Successfully set up |
| <img src="indicators/dot-red.svg" width='12'> | Red solid | Error |
| <img src="indicators/dot-white-pulse.svg" width='12'> | White pulsing | Factory resetting or firmware update |



Expand Down
4 changes: 2 additions & 2 deletions micro/app/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def pulse_received(data):
# 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 active and not user_has_interacted and (not last_room_is_lit or not last_motion_detected):
# Don't light if user has not interacted recently or the room is dark
if active and not user_has_interacted and (not last_room_is_lit):
message_queue.append(data)
return

Expand Down
28 changes: 16 additions & 12 deletions micro/app/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from time import sleep_ms
from time import sleep, sleep_ms, ticks_ms
from machine import Pin, ADC
from hardware import *
from app.rotary.rotary_irq_esp import RotaryIRQ
from app.led import set_color, rgb_to_hex, hsl_to_rgb, turn_off
from app.commander import activate, toggle_reading_light, deactivate, factory_reset, room_is_lit, motion_detected, user_is_interacting, MINIMUM_LIGHT_LEVEL
Expand All @@ -17,15 +18,15 @@
LOOP_WAIT = 5
LIGHT_WAIT = 2000 # How long to wait to register light change

pushbutton = Pin(27, Pin.IN, Pin.PULL_UP)
builtin = Pin(2, Pin.OUT)
motion_sensor = Pin(17, Pin.IN, Pin.PULL_UP)
light_sensor = ADC(Pin(33, Pin.IN, Pin.PULL_UP))
pushbutton = Pin(PUSHBUTTON, Pin.IN, Pin.PULL_UP)
builtin = Pin(BUILTIN, Pin.OUT)
motion_sensor = Pin(MOTION_SENSOR, Pin.IN, Pin.PULL_UP)
light_sensor = ADC(Pin(LIGHT_SENSOR, Pin.IN, Pin.PULL_UP))
light_sensor.atten(ADC.ATTN_11DB)

r = RotaryIRQ(
pin_num_clk=32,
pin_num_dt=25,
pin_num_clk=ROTARY_CLK,
pin_num_dt=ROTARY_DT,
min_val=0,
max_val=(ROTARY_STEPS-1),
reverse=False,
Expand All @@ -44,6 +45,7 @@ def input_watcher():
pushbutton_old = pushbutton.value()
pressed_time = ticks_ms()
released_time = ticks_ms()
last_pressed = ticks_ms()
press_count = 0
holding = False

Expand Down Expand Up @@ -96,6 +98,7 @@ def input_watcher():
# Send signal if single press is held for more than fraction of a second
if not holding and press_count == 1 and pushbutton_new == 0 and now - pressed_time > DOUBLE_PRESS_WAIT:
holding = True
last_pressed = now
activate(last_color)

# Check if user has held double press for a few seconds
Expand All @@ -107,12 +110,13 @@ def input_watcher():

# Rotary input
if rotary_old != rotary_new:
user_is_interacting()
rotary_old = rotary_new
val = int((rotary_new / ROTARY_STEPS) * 360)
last_color = hsl_to_rgb(val, 1, 0.5)
set_color(last_color, top=True)
# print('result =', rotary_new)
if ticks_ms() - last_pressed >= 1000:
user_is_interacting()
rotary_old = rotary_new
val = int((rotary_new / ROTARY_STEPS) * 360)
last_color = hsl_to_rgb(val, 1, 0.5)
set_color(last_color, top=True)
# print('result =', rotary_new)

# Motion sensor
if motion_old != motion_new:
Expand Down
26 changes: 14 additions & 12 deletions micro/app/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,18 @@ def set(state):
for i in range(led_count):
np[i] = state[i]
np.write()

# Update the current effect
def set_effect(name):
global effect
effect = None
if effect:
sleep_ms(1)
effect = name

# TODO: Fade new color
def set_color(color, brightness=None, top=False, duration=100):
global effect
effect = None
set_effect(None)
brightness = brightness or DEFAULT_BRIGHTNESS

# If top is set, get top eighth of leds
Expand Down Expand Up @@ -422,8 +429,7 @@ def set_gradient(colors, fade=True):
# # state: list of rgb tuples [(R, G, B)]
def transition(state1, state2, duration):
step_duration = 1 # duration of each step in ms
global effect
effect = EFFECT_TRANSITION
set_effect(EFFECT_TRANSITION)
state1 = state1 or copy()
state2 = state2 or copy()

Expand All @@ -446,9 +452,8 @@ def transition_to(state, duration):
def flash(color=None):
if color:
set_color(color)

global effect
effect = None

set_effect(None)
state = copy()

# Turn off all LEDs
Expand All @@ -465,14 +470,11 @@ 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))

set_effect(EFFECT_PULSE)

effect = EFFECT_PULSE
state = state or copy()
start_new_thread(pulse_thread, (state,))

Expand Down
6 changes: 6 additions & 0 deletions micro/hardware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PUSHBUTTON = 27
BUILTIN = 2
MOTION_SENSOR = 17
LIGHT_SENSOR = 33
ROTARY_CLK = 32
ROTARY_DT = 25

0 comments on commit 8a8e652

Please sign in to comment.