def __init__(self): self.words = [ # All the timings are set to change 2 minutes before/3 minutes after # each 5 minute interval instead of on them Word(["*", "*", "*", "*", "3-8,53-58", "*"], wp.MINUTE_FIVE, RandomColourer('FIVE')), Word(["*", "*", "*", "*", "8-13,48-53", "*"], wp.MINUTE_TEN, RandomColourer('TEN')), Word(["*", "*", "*", "*", "13-18,43-48", "*"], wp.MINUTE_QUARTER, RandomColourer('QUARTER')), Word(["*", "*", "*", "*", "18-23,38-43", "*"], wp.MINUTE_TWENTY, RandomColourer('TWENTY')), Word(["*", "*", "*", "*", "23-28,33-38", "*"], wp.MINUTE_TWENTY_FIVE, RandomColourer('TWENTYFIVE')), Word(["*", "*", "*", "*", "28-33", "*"], wp.MINUTE_HALF, RandomColourer('HALF')), Word(["*", "*", "*", "*", "3-33", "*"], wp.PAST, RandomColourer('PAST')), Word(["*", "*", "*", "*", "33-58", "*"], wp.TO, RandomColourer('TO')), Word(["*", "*", "*", "0,12 & 1,13", "33-60 & 0-33", "*"], wp.HOUR_ONE, RandomColourer('ONE')), Word(["*", "*", "*", "1,13 & 2,14", "33-60 & 0-33", "*"], wp.HOUR_TWO, RandomColourer('TWO')), Word(["*", "*", "*", "2,14 & 3,15", "33-60 & 0-33", "*"], wp.HOUR_THREE, RandomColourer('THREE')), Word(["*", "*", "*", "3,15 & 4,16", "33-60 & 0-33", "*"], wp.HOUR_FOUR, RandomColourer('FOUR')), Word(["*", "*", "*", "4,16 & 5,17", "33-60 & 0-33", "*"], wp.HOUR_FIVE, RandomColourer('FIVE')), Word(["*", "*", "*", "5,17 & 6,18", "33-60 & 0-33", "*"], wp.HOUR_SIX, RandomColourer('SIX')), Word(["*", "*", "*", "6,18 & 7,19", "33-60 & 0-33", "*"], wp.HOUR_SEVEN, RandomColourer('SEVEN')), Word(["*", "*", "*", "7,19 & 8,20", "33-60 & 0-33", "*"], wp.HOUR_EIGHT, RandomColourer('EIGHT')), Word(["*", "*", "*", "8,20 & 9,21", "33-60 & 0-33", "*"], wp.HOUR_NINE, RandomColourer('NINE')), Word(["*", "*", "*", "9,21 & 10,22", "33-60 & 0-33", "*"], wp.HOUR_TEN, RandomColourer('TEN')), Word(["*", "*", "*", "10,22 & 11,23", "33-60 & 0-33", "*"], wp.HOUR_ELEVEN, RandomColourer('ELEVEN')), Word(["*", "*", "*", "11,23 & 12,0", "33-60 & 0-33", "*"], wp.HOUR_TWELVE, RandomColourer('TWELVE')), Word(["*", BDAY_MONTH, BDAY_DAY, BDAY_HOURS, "*", "*"], wp.HAPPY, RainbowColourer('HAPPY', 1)), Word(["*", BDAY_MONTH, BDAY_DAY, BDAY_HOURS, "*", "*"], wp.BIRTHDAY, RainbowColourer('BIRTHDAY', 1)) #Word(["*", BDAY_MONTH, BDAY_DAY, BDAY_HOURS, "*", "*"], wp.BLIB, RainbowColourer('BLIB', 1)) ] self.dimmer = Dimmer(["*", "*", "*", DIM_HOURS, "*", "*"])
def perform_test(self, time_table, test_values): logging.basicConfig(level=logging.ERROR) time = StubTime() output = StubOutput() d = Dimmer("dimmer", time, output, time_table) for t, expected in test_values: time.set_time(t) d.update() self.assertEqual( output.get_value(), expected, "invalid output value for time %d, expected %f got %f" % (t, expected, output.get_value()))
def run(): # Get supplied command line arguments commandArgs = args() # Check for led configuration arguments matrixOptions = led_matrix_options(commandArgs) matrixOptions.drop_privileges = False # Initialize the matrix matrix = Matrix(RGBMatrix(options=matrixOptions)) # Print some basic info on startup debug.info("{} - v{} ({}x{})".format(SCRIPT_NAME, SCRIPT_VERSION, matrix.width, matrix.height)) # Read scoreboard options from config.json if it exists config = ScoreboardConfig("config", commandArgs, matrix.width, matrix.height) debug.set_debug_status(config) data = Data(config) if data.config.dimmer_enabled: dimmer = Dimmer(data, matrix) dimmerThread = threading.Thread(target=dimmer.run, args=()) dimmerThread.daemon = True dimmerThread.start() MainRenderer(matrix, data).render()
def showMeWhatYouGot(self): dimmer = Dimmer(self._fakePotentiometer, self._consumer, 100) dimmer.start() self.upwardDimmmer() self.downwardDimmer() dimmer.terminate() dimmer.join() for x in range(3): self.flash() time.sleep(0.5)
def run(self): self.setup_logging() scheduler = BlockingScheduler() #weather = Weather(scheduler, zip=self._args['zip'], station=self._args['station']) dimmer = Dimmer(scheduler) #display = Display(weather, dimmer) display = Display(dimmer) display.start() scheduler.start()
def test_async(): relay = Dimmer(2) asyncio.create_task(relay.async_blink()) for i in range(0,10): print(i) if i == 4: relay.stop_async_blink() await asyncio.sleep(1) asyncio.create_task(relay.async_fading(10, 1000)) for i in range(0,30): print(i) if i == 20: relay.stop_async_fading() await asyncio.sleep(1)
def test_calc_brightness_special(self): dim = Dimmer(None, None) max = 15 dim._day_percentage = 25 dim._night_percentage = 5 # this mocks after sunrise and before sunset br = dim._calculate_brightness(max, 1, 0, 2) self.assertEquals(3, br) # this mocks after sunrise and after sunset br = dim._calculate_brightness(max, 2, 0, 1) self.assertEquals(0, br)
def test_calc_brightness_simple(self): dim = Dimmer(None, None) max = 100 dim._day_percentage = 10 dim._night_percentage = 20 # this mocks before sunrise and before sunset br = dim._calculate_brightness(max, 0, 1, 2) self.assertEquals(20, br) # this mocks after sunrise and before sunset br = dim._calculate_brightness(max, 1, 0, 2) self.assertEquals(10, br) # this mocks after sunrise and after sunset br = dim._calculate_brightness(max, 2, 0, 1) self.assertEquals(20, br)
def run(): # Get supplied command line arguments commandArgs = args() # Check for led configuration arguments matrixOptions = led_matrix_options(commandArgs) matrixOptions.drop_privileges = False # Initialize the matrix matrix = RGBMatrix(options=matrixOptions) # Print some basic info on startup debug.info("{} - v{} ({}x{})".format(SCRIPT_NAME, SCRIPT_VERSION, matrix.width, matrix.height)) # Read scoreboard options from config.json if it exists config = ScoreboardConfig("config", commandArgs) debug.set_debug_status(config) data = Data(config) # Event used to sleep when rendering # Allows API to cancel the sleep sleepEvent = threading.Event() # Dimmer routine to automatically dim display scheduler = BackgroundScheduler() dimmer = Dimmer(scheduler, sleepEvent) scheduler.start() # Initialize API and run on separate thread api = ScoreboardApi(data, dimmer, sleepEvent) apiThread = threading.Thread(target=api.run, args=()) apiThread.daemon = True apiThread.start() MainRenderer(matrix, data, dimmer, sleepEvent).render()
def __init__(self, name, addr): Dimmer.__init__(self, name, addr)
def __init__(self): self.tasks = {} for dimmer in 'dimmer1', 'dimmer2', 'dimmer3': self.tasks[dimmer] = Dimmer(conf.get_conf(dimmer))
import sys import os import subprocess import time import paho.mqtt.client as mqtt import paho.mqtt.publish as publish from dimmer import Dimmer sys.path.append(os.path.relpath("../config")) from mqtt_topics import * from mqtt_server import * dimmer = Dimmer() mqtt_client = mqtt.Client() def setup_mqtt_client(): mqtt_client.username_pw_set(mqtt_username, mqtt_password) mqtt_client.connect(mqtt_host, mqtt_port, 60) mqtt_client.on_connect = on_mqtt_connect mqtt_client.on_message = on_mqtt_message mqtt_client.loop_start() def on_mqtt_connect(client, userdata, flags, rc): print("MQTT connected with status code " + str(rc)) mqtt_subscribe(client, sunlight_lamp_set) mqtt_subscribe(client, sunlight_lamp_query) def on_mqtt_message(client, userdata, msg): print("Received message: [" + msg.topic + "] " + str(msg.payload))
def on_kill(signum, frame): screen_manager.shutdown() signal.signal(signal.SIGTERM, on_kill) signal.signal(signal.SIGINT, on_kill) if DIM_AFTER is not None or OFF_AFTER is not None: Dimmer( screen_manager, keyboard_manager, DIM_AFTER, OFF_AFTER, # these buttons must be reported to the current screen even if they were used to wake screen up # currently only <UP> is consumed, rest wake up the screen and are passed through [ KeyboardManager.RIGHT, KeyboardManager.DOWN, KeyboardManager.LEFT, KeyboardManager.CENTER, KeyboardManager.A, KeyboardManager.B ]) status_screen = StatusScreen(screen_manager, keyboard_manager, mpd_client) main = MainScreen(screen_manager, keyboard_manager, mpd_client, status_screen, volume_manager) screen_manager.set_screen(main) screen_manager.run() # main loop keyboard_manager.stop()
from demo import Demo from messenger import Messenger GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) ledPin = 27 adc = Ads1115(address=0x48, busNumber=1, range=32767) light = Consumer( ledPin, GPIO ) # consumer can be reused for other purposes (fan, etc.) - Scalability potentiometer = AnalogPotentiometer( adc ) # tie classes to interfaces (potentiometer -> adc) - Modularity (change adc easily) dimmer = Dimmer(potentiometer, light, range=100) dimmer.start() demo = Demo(light) f = FlaskThread() f.start() while True: if Messenger.message == "demo": dimmer.pause.value = True demo.showMeWhatYouGot() Messenger.message = "" dimmer.pause.value = False # socketio.emit("sliderValue", potentiometer.resistance) # DON'T do this! Avoid two processes accessing the same source (ADC in this case) socketio.emit("sliderValue", dimmer.volume) time.sleep(0.1)