def setup(): """Set up the backlight on GFX HAT""" global _sn3218 import sn3218 as _sn3218 _sn3218.enable() _sn3218.enable_leds(0b111111111111111111) _sn3218.output(_buf)
def setup(): global automation_hat, automation_phat, sn3218, _ads1015, _is_setup, _t_update_lights if _is_setup: return True _is_setup = True GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) try: import smbus except ImportError: if version_info[0] < 3: raise ImportError( "This library requires python-smbus\nInstall with: sudo apt install python-smbus" ) elif version_info[0] == 3: raise ImportError( "This library requires python3-smbus\nInstall with: sudo apt install python3-smbus" ) _ads1015 = ads1015(smbus.SMBus(1)) if _ads1015.available() is False: raise RuntimeError("No ADC detected, check your connections") try: import sn3218 except ImportError: raise ImportError( "This library requires sn3218\nInstall with: sudo pip install sn3218" ) except IOError: pass if sn3218 is not None: sn3218.enable() sn3218.enable_leds(0b111111111111111111) automation_hat = True automation_phat = False _t_update_lights = AsyncWorker(_update_lights) _t_update_lights.start() atexit.register(_exit)
def setup(): global _is_setup, sn3218 if _is_setup: return True try: import sn3218 except ImportError: raise ImportError( "This library requires the sn3218 module\nInstall with: sudo pip install sn3218" ) sn3218.enable() sn3218.enable_leds(0b111111111111111111) atexit.register(_exit) _is_setup = True
def off(): """ Turns off the backlight. """ rgb(0, 0, 0) def update(): """ Update backlight with changes to the LED buffer """ sn3218.output(leds) # set gamma correction for backlight to normalise brightness g_channel_gamma = [int(value / 1.6) for value in sn3218.default_gamma_table] sn3218.channel_gamma(1, g_channel_gamma) sn3218.channel_gamma(4, g_channel_gamma) sn3218.channel_gamma(7, g_channel_gamma) r_channel_gamma = [int(value / 1.4) for value in sn3218.default_gamma_table] sn3218.channel_gamma(0, r_channel_gamma) sn3218.channel_gamma(3, r_channel_gamma) sn3218.channel_gamma(6, r_channel_gamma) w_channel_gamma = [int(value / 24) for value in sn3218.default_gamma_table] for i in range(9, 18): sn3218.channel_gamma(i, w_channel_gamma) sn3218.enable()
# set gamma correction for backlight to normalise brightness g_channel_gamma = [int(value / 1.6) for value in sn3218.default_gamma_table] sn3218.channel_gamma(1, g_channel_gamma) sn3218.channel_gamma(4, g_channel_gamma) sn3218.channel_gamma(7, g_channel_gamma) r_channel_gamma = [int(value / 1.4) for value in sn3218.default_gamma_table] sn3218.channel_gamma(0, r_channel_gamma) sn3218.channel_gamma(3, r_channel_gamma) sn3218.channel_gamma(6, r_channel_gamma) w_channel_gamma = [int(value / 24) for value in sn3218.default_gamma_table] for i in range(9, 18): sn3218.channel_gamma(i, w_channel_gamma) sn3218.enable() def use_rbg(): """ Swaps the Green and Blue channels on the LED backlight Use if you have a first batch Display-o-Tron 3K """ global LED_R_G, LED_R_B global LED_M_G, LED_M_B global LED_L_G, LED_L_B (LED_R_G, LED_R_B) = (LED_R_B, LED_R_G) (LED_M_G, LED_M_B) = (LED_M_B, LED_M_G) (LED_L_G, LED_L_B) = (LED_L_B, LED_L_G)
enable_mask = 0b100000010001000000 elif action_level == 3 and one == 0 and two == 1 and three == 1: enable_mask = 0b100000010100000000 elif action_level == 3 and one == 1 and two == 1 and three == 1: enable_mask = 0b100000010101000000 elif action_level == 3 and one == 0 and two == 0 and three == 0: enable_mask = 0b000000000000000000 # Enable/Disable LEDs enable_leds(enable_mask) output([int((math.sin(float(416) / 64.0) + 1.0) * 128.0)] * 18) # Enable GPIO and sn3218 access pi = pigpio.pi() enable() enable_mask = 0b000000000000000000 # If the GPIO connection fails, exit the script if not pi.connected: exit() # Enable/Disable LEDs action_leds(1, pi.read(13), pi.read(19), pi.read(16)) # Read the commandline arguments allArguments = sys.argv # Further arguments argumentList = allArguments[1:]
def test_disable_enable(self): """Enable / disable operations""" sn3218.disable() delay() sn3218.enable() delay()
def setUp(self): """Reset chip for each test""" sn3218.reset() sn3218.enable() sn3218.enable_leds(0b111111111111111111)