From e3258d2893a1cb515e6e81d054da910b54634815 Mon Sep 17 00:00:00 2001 From: Jon Stephens Date: Tue, 29 Dec 2020 06:03:24 +0000 Subject: [PATCH] Adding unsafe flag to disable warnings while running --- documentation/Function-reference.md | 8 +++++++- library/UnicornHat/unicornhat.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/documentation/Function-reference.md b/documentation/Function-reference.md index 4626f6b..ffdbe19 100644 --- a/documentation/Function-reference.md +++ b/documentation/Function-reference.md @@ -97,4 +97,10 @@ Sets the pixel at x,y to colour r,g,b. The x value should be between 0 and 7, th Note that for compatibility with Unicorn HAT y values between 4 and 7 will be accepted but wrap around the range. In other words they are technically acceptable but should be avoided when writing programs designed for the pHAT. -All other functions detailed in the HAT sections are otherwise valid and identical. \ No newline at end of file +```python +set_unsafe( True ) +``` + +Disables warnings about brightness while running. + +All other functions detailed in the HAT sections are otherwise valid and identical. diff --git a/library/UnicornHat/unicornhat.py b/library/UnicornHat/unicornhat.py index 872dee4..87f20c5 100644 --- a/library/UnicornHat/unicornhat.py +++ b/library/UnicornHat/unicornhat.py @@ -54,6 +54,8 @@ 'indigo':(75,0,130) } +# Don't show warnings if UNSAFE +UNSAFE = False """ Store the rotation of UnicornHat, defaults to @@ -120,6 +122,9 @@ def setup(): _is_setup = True +def set_unsafe(safe=False): + global UNSAFE + UNSAFE=safe def set_gamma(gamma): setup() @@ -222,6 +227,7 @@ def brightness(b=0.2): :param b: Brightness from 0.0 to 1.0 (default 0.2) """ + global UNSAFE setup() if b > 1 or b < 0: @@ -233,7 +239,7 @@ def brightness(b=0.2): brightness = int(b*128.0) - if brightness < 30: + if brightness < 30 and not UNSAFE: print("Warning: Low brightness chosen, your UnicornHAT might not light up!") ws2812.setBrightness(brightness)