Skip to content

Instantly share code, notes, and snippets.

@kurosuke
Created September 21, 2020 23:32
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 kurosuke/cdf91e867652797e506f6b3539194e2d to your computer and use it in GitHub Desktop.
Save kurosuke/cdf91e867652797e506f6b3539194e2d to your computer and use it in GitHub Desktop.
import sys
import blinkt
def usage():
print("Usage: {} L0 L1 L2 L3 L4 L5".format(sys.argv[0]))
print(" L0 ... LAN ok/ng")
print(" L1 ... WLAN ok/ng")
print(" L2 ... on/off")
print(" L3 ... on/off")
print(" L5-L7 ... Delay (100msec)")
sys.exit(1)
class RpiStatus():
def __init__(self, blinkt):
self.blinkt = blinkt
self.blinkt.set_clear_on_exit(False)
return
def set_color(self, l, color):
# R G B
# #FFFFFF -> [255, 255, 255]
r = int(color[0:2], 16)
g = int(color[2:4], 16)
b = int(color[4:6], 16)
print("COLOR ({}) R {} G {}, B {}".format(l, r, g, b))
self.blinkt.set_pixel(l, r, g, b)
def set_rgb(self, l, r, g, b):
# R G B
print("RGB ({}) R {} G {}, B {}".format(l, r, g, b))
self.blinkt.set_pixel(l, r, g, b)
def set_lan(self, status):
if status == "ok":
self.set_color(0, "003000")
else:
self.set_color(0, "300000")
def set_wlan(self, status):
if status == "ok":
self.set_color(1, "003000")
else:
self.set_color(1, "300000")
def set_delay_msec(self, msec):
#
# 100msec - 1,600msec
#
vol = int(int(msec) /100) # 1-16
color = "303000"
if vol >= 10: # 1sec over
color = "300010"
elif vol < 5:
color = "000030"
binary = ("000" + bin(vol)[2:])[-4:]
for l in range(4, 8): # L4, L5, L6, L7
if binary[l-4] == '1':
self.set_color(l, color)
else:
self.set_color(l, "000000")
def show(self):
self.blinkt.show()
if __name__ == "__main__":
if len(sys.argv) != 7:
usage()
# class
rs = RpiStatus(blinkt)
# set attributes
rs.set_lan(sys.argv[1])
rs.set_wlan(sys.argv[2])
rs.set_delay_msec(sys.argv[6])
rs.show()
# vi:set ts=4 sw=4 sts=4 ft=sh et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment