Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Add brightness control #291

Open
wants to merge 29 commits into
base: aiyprojects
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2942c24
Add brightness control
mpember Mar 2, 2018
0c90568
Sync custom commands
mpember Apr 11, 2018
a6fccfa
Clean up command identification
mpember Apr 29, 2018
83f9f36
Update to power switch controls
mpember May 3, 2018
94279e0
June Updates
mpember Jun 10, 2018
0e3b78c
Add files via upload
mpember Jun 17, 2018
77b3aae
June Updates v2
mpember Jun 17, 2018
ddc0ffc
Tweak to Podcatcher
mpember Jun 18, 2018
91ffeb1
Simplify podcast handling
Jun 22, 2018
ea4c055
Disable dark beacon
Jun 22, 2018
cf71c84
MQTT migration
mpember Jun 28, 2018
096aab7
Podcast updates
mpember Jun 30, 2018
88a6d32
Improve error handling in MQTT
Jul 16, 2018
c575ab0
Tweak logging level for powerswitch module
Jul 19, 2018
b8de720
Resolve toggle support for powerswitch module
Jul 19, 2018
b634c92
Resolve toggle support for powerswitch module
Aug 3, 2018
1cf3d1e
Modify daemon-mode settings
Aug 5, 2018
242b69f
Update status LED brightness controls
Aug 13, 2018
78528ad
Add flexibility to list podcast today or todays's
Aug 22, 2018
2292a26
Improve tv-related voice command syntax
Oct 20, 2018
01b6789
Improve tv-related voice command syntax
Oct 20, 2018
6e5cb37
Merge branch 'aiyprojects' of https://github.com/mpember/aiyprojects-…
Oct 20, 2018
71fd405
Remove debug code in podcast handling
Oct 20, 2018
72bcfb7
Remove missed debug code in podcast handling
Oct 20, 2018
febd21a
Add alternative TV-related command
Oct 20, 2018
648d347
Update MQTT details for power-related commands
Oct 31, 2018
bd6432c
Inform when no podcasts available
Nov 5, 2018
36c0c85
Major upgrade to power commands
Jan 2, 2019
0fab1d5
Update to voice commands, modules
mpember Oct 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/aiy/_drivers/_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import itertools
import threading
import time
import math
import RPi.GPIO as GPIO


Expand All @@ -35,7 +36,7 @@ class LED:
BLINK = 2
BLINK_3 = 3
BEACON = 4
BEACON_DARK = 5
BEACON_DARK = 0
DECAY = 6
PULSE_SLOW = 7
PULSE_QUICK = 8
Expand All @@ -47,6 +48,7 @@ def __init__(self, channel):
self.running = False
self.state = None
self.sleep = 0
self.brightness = 1
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.OUT)
self.pwm = GPIO.PWM(channel, 100)
Expand Down Expand Up @@ -78,6 +80,12 @@ def stop(self):

self.pwm.stop()

def set_brightness(self, brightness):
try:
self.brightness = int(brightness)/100
except ValueError:
raise ValueError('unsupported brightness: %s' % brightness)

def set_state(self, state):
"""Set the LED driver's new state.

Expand Down Expand Up @@ -118,35 +126,35 @@ def _parse_state(self, state):
self.pwm.ChangeDutyCycle(100)
handled = True
elif state == self.BLINK:
self.iterator = itertools.cycle([0, 100])
self.iterator = itertools.cycle([0, int(100 * self.brightness)])
self.sleep = 0.5
handled = True
elif state == self.BLINK_3:
self.iterator = itertools.cycle([0, 100] * 3 + [0, 0])
self.iterator = itertools.cycle([0, int(100 * self.brightness)] * 3 + [0, 0])
self.sleep = 0.25
handled = True
elif state == self.BEACON:
self.iterator = itertools.cycle(
itertools.chain([30] * 100, [100] * 8, range(100, 30, -5)))
itertools.chain([int(30 * self.brightness)] * 100, [int(100 * self.brightness)] * 8, range(int(100 * self.brightness), int(30 * self.brightness), 0 - math.ceil(4 * self.brightness))))
self.sleep = 0.05
handled = True
elif state == self.BEACON_DARK:
self.iterator = itertools.cycle(
itertools.chain([0] * 100, range(0, 30, 3), range(30, 0, -3)))
itertools.chain([0] * 100, range(0, int(30 * self.brightness), math.ceil(2 * self.brightness), range(int(30 * self.brightness), 0, 0 - math.ceil(2 * self.brightness)))))
self.sleep = 0.05
handled = True
elif state == self.DECAY:
self.iterator = itertools.cycle(range(100, 0, -2))
self.iterator = self.iterator = itertools.cycle(range(int(100 * self.brightness), 0, int(math.ceil(-2 * self.brightness))))
self.sleep = 0.05
handled = True
elif state == self.PULSE_SLOW:
self.iterator = itertools.cycle(
itertools.chain(range(0, 100, 2), range(100, 0, -2)))
itertools.chain(range(0, int(100 * self.brightness), math.ceil(2 * self.brightness)), range(int(100 * self.brightness), 0, 0 - math.ceil(2 * self.brightness))))
self.sleep = 0.1
handled = True
elif state == self.PULSE_QUICK:
self.iterator = itertools.cycle(
itertools.chain(range(0, 100, 5), range(100, 0, -5)))
itertools.chain(range(0, int(100 * self.brightness), math.ceil(4 * self.brightness)), range(int(100 * self.brightness), 0, 0 - math.ceil(4 * self.brightness))))
self.sleep = 0.05
handled = True

Expand Down
Loading