Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unsafe flag to disable warnings while running #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion documentation/Function-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```python
set_unsafe( True )
```

Disables warnings about brightness while running.

All other functions detailed in the HAT sections are otherwise valid and identical.
8 changes: 7 additions & 1 deletion library/UnicornHat/unicornhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
'indigo':(75,0,130)
}

# Don't show warnings if UNSAFE
UNSAFE = False

"""
Store the rotation of UnicornHat, defaults to
Expand Down Expand Up @@ -120,6 +122,9 @@ def setup():

_is_setup = True

def set_unsafe(safe=False):
global UNSAFE
UNSAFE=safe

def set_gamma(gamma):
setup()
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down