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

Commit

Permalink
Update status LED brightness controls
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pemberton committed Aug 12, 2018
1 parent 1cf3d1e commit de8b89e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/aiy/_drivers/_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def stop(self):

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

Expand All @@ -107,7 +107,7 @@ def _animate(self):
if not self._parse_state(state):
raise ValueError('unsupported state: %d' % state)
if self.iterator:
self.pwm.ChangeDutyCycle(next(self.iterator) * self.brightness)
self.pwm.ChangeDutyCycle(next(self.iterator))
time.sleep(self.sleep)
else:
# We can also wait for a state change here with a Condition.
Expand All @@ -119,41 +119,41 @@ def _parse_state(self, state):
handled = False

if state == self.OFF:
self.pwm.ChangeDutyCycle(0 * self.brightness)
self.pwm.ChangeDutyCycle(0)
handled = True
elif state == self.ON:
self.pwm.ChangeDutyCycle(100 * self.brightness)
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), int(-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), int(2 * self.brightness), range(int(30 * self.brightness), 0, int(-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(-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), int(2 * self.brightness)), range(int(100 * self.brightness), 0, int(-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), int(4 * self.brightness)), range(int(100 * self.brightness), 0, int(-4 * self.brightness))))
self.sleep = 0.05
handled = True

Expand Down
11 changes: 8 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ def process_event(assistant, event):

elif text == 'brightness low':
assistant.stop_conversation()
aiy.voicehat.get_led().set_brightness(10)
aiy.voicehat.get_led().set_brightness(20)

elif text == 'brightness medium':
assistant.stop_conversation()
aiy.voicehat.get_led().set_brightness(60)

elif text == 'brightness high':
assistant.stop_conversation()
Expand All @@ -257,9 +261,9 @@ def main():
help='File containing our process id for monitoring')
parser.add_argument('--trigger-sound', default=None,
help='Sound when trigger is activated (WAV format)')
parser.add_argument('--brightness-max', default=1,
parser.add_argument('--brightness-max', type=int, default=1,
help='Maximum LED brightness')
parser.add_argument('--brightness-min', default=1,
parser.add_argument('--brightness-min', type=int, default=1,
help='Minimum LED brightness')
parser.add_argument('-d', '--daemon', action='store_true',
help='Daemon Mode')
Expand All @@ -269,6 +273,7 @@ def main():
aiy.i18n.set_language_code(args.language)
_createPID(args.pid_file)

logging.info('Setting brightness to %d %%' % args.brightness_max)
aiy.voicehat.get_led().set_brightness(args.brightness_max)

credentials = aiy.assistant.auth_helpers.get_assistant_credentials()
Expand Down

0 comments on commit de8b89e

Please sign in to comment.