Skip to content

Instantly share code, notes, and snippets.

@brettbeeson
Created February 18, 2020 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettbeeson/6bbab10e8cd56b44e18315575f73b362 to your computer and use it in GitHub Desktop.
Save brettbeeson/6bbab10e8cd56b44e18315575f73b362 to your computer and use it in GitHub Desktop.
Control pijuice LEDs from the command line
#!/usr/bin/env python3
import sys
from time import sleep
from pijuice import PiJuice
import argparse
argparser = argparse.ArgumentParser("Blink the user LED on a pijuice")
argparser.add_argument("element",choices=['photo','upload','wifi'])
argparser.add_argument("status", choices=['ok','fail'])
args = argparser.parse_args()
lum = 64
if args.element == 'photo' and args.status == 'ok':
rgb1 = [0,lum,0]
period1 = 1000
rgb2 = [0, 0, 0]
period2 = 0
count = 1
elif args.element == 'photo' and args.status == 'fail':
rgb1 = [lum, 0, 0]
period1 = 1000
rgb2 = [0, 0, 0]
period2 = 0
count = 1
elif args.element == 'upload' and args.status == 'ok':
rgb1 = [0, lum, 0]
period1 = 250
rgb2 = [0, 0, 0]
period2 = 250
count = 4
elif args.element == 'upload' and args.status == 'fail':
rgb1 = [lum, 0, 0]
period1 = 250
rgb2 = [0, 0, 0]
period2 = 250
count = 4
elif args.element == 'wifi' and args.status == 'ok':
rgb1 = [0, 0, lum]
period1 = 1000
rgb2 = [0, 0, 0]
period2 = 0
count = 1
elif args.element == 'wifi' and args.status == 'fail':
print ("Not a valid status",file=sys.stderr)
exit (1)
# rgb1 = [0, 0, lum]
# period1 = 250
# rgb2 = [0, 0, 0]
# period2 = 250
# count = 4
else:
raise RuntimeError("Internal error")
led = 'D2'
pijuice = PiJuice()
#SetLedBlink(led, count, rgb1, period1, rgb2, period2)
pijuice.status.SetLedBlink(led, count, rgb1, period1, rgb2, period2)
sleep(count * (period1 + period2) / 1000.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment