Untitled
unknown
plain_text
4 months ago
3.5 kB
1
Indexable
import time from rpi_ws281x import * import argparse # LED strip configuration: LED_COUNT = 30 # Number of LED pixels LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_DMA = 10 # DMA channel to use for generating a signal (try 10) LED_BRIGHTNESS = 65 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 class ServiceStatus: HEALTHY = {"name": "HEALTHY", "rbg": (0, 255, 0)} UNHEALTHY = {"name": "UNHEALTHY", "rbg": (255, 0, 0)} UNKNOWN = {"name": "UNKNOWN", "rbg": (255, 255, 0)} class GingerBreadPart: def __init__(self, led_start, led_end, service_name): self.service_name = service_name self.status = ServiceStatus.UNKNOWN self.led_start = led_start self.led_end = led_end def set_status(self, status): self.status = status # azure_devops # azure # citrix # github # kong head = GingerBreadPart(0, 20, "head") head = [0, 20] r_arm = [21, 40] r_leg = [40, 60] l_leg = [61, 80] l_arm = [81, 100] # status of each service # Possible statuses: {HEALTHY, UNHEALTHY, UNKNOWN} head = "HEALTHY" r_arm = "HEALTHY" r_leg = "HEALTHY" l_leg = "HEALTHY" l_arm = "HEALTHY" def set_led_lights(led_strip, led_start, led_end, color: Color): """ Set the color of the LEDs in the range led_start to led_end to the list color""" for led in range(led_start, led_end): print("set_light(led_strip, rgb[0], rgb[1], rgb[2])") led_strip.setPixelColor(led, color) led_strip.show() # def set_service_status(led_strip: Adafruit_NeoPixel, service: GingerBreadPart, set_status: ServiceStatus): # if GingerBreadPart.status == set_status: # print(f"Service is already in the desired state") # return # color_tuple = (255, 0, 0) # set_led_lights(led_strip, service.led_start, service.led_end, color_tuple) # Define functions which animate LEDs in various ways. def colorWipe(strip, color, wait_ms=50): """Wipe color across display a pixel at a time.""" for i in range(strip.numPixels()): strip.setPixelColor(i, color) strip.show() time.sleep(wait_ms/1000.0) if __name__ == '__main__': # Process arguments parser = argparse.ArgumentParser() parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit') args = parser.parse_args() # Create NeoPixel object with appropriate configuration. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) # Intialize the library (must be called once before other functions). strip.begin() try: # Init: Set all services to unknown while True: time.sleep(5) set_led_lights(strip, 0, 20, Color(255, 0, 0)) time.sleep(5) set_led_lights(strip, 21, 40, Color(255, 0, 0)) time.sleep(5) set_led_lights(strip, 41, 60, Color(255, 0, 0)) time.sleep(5) set_led_lights(strip, 61, 80, Color(255, 0, 0)) except KeyboardInterrupt: if args.clear: colorWipe(strip, Color(0,0,0), 10)
Editor is loading...
Leave a Comment