def __init__(self): self.pixels = neopixel.NeoPixel( board.D18, AppConfig.instance().conf["pixel_count"], brightness=AppConfig.instance().conf["brightness"], pixel_order="GRB", ) self.pixels.fill((0, 0, 0)) # Clear Board self.synthesia_pixels = [(0, 0, 0) for _ in range(AppConfig.instance().conf["pixel_count"])] self.in_song = False
def keyboard_position(self): if self.note > 92: note_offset = 2 elif self.note > 55: note_offset = 1 else: note_offset = 0 pos = (self.note - 20) * 2 - note_offset if AppConfig.instance().conf['invert']: pos = AppConfig.instance().conf.get('pixel_count') - pos return pos
def set_led(self, msg, color): adjusted_color = tuple([int(val * msg.brightness) for val in color]) pos = msg.keyboard_position() if msg.from_synthesia: self.pixels[pos] = adjusted_color self.synthesia_pixels[pos] = adjusted_color elif self.in_song: if self.synthesia_pixels[pos] == (0, 0, 0): self.pixels[pos] = hex_to_rgb(AppConfig.instance().conf["colors"]["error"]) else: self.pixels[pos] = adjusted_color else: self.pixels[pos] = adjusted_color
def lambda_handler(event, context): AppLogging.init('info') app_config = AppConfig( config_file=os.environ['config_file'] ) config = app_config.asdict() database_connection_info_func = lambda: DatabaseConnectionInfo( user=config['database']['user'], password=config['database']['password'], host=config['database']['host'], port=config['database']['port'], database=config['database']['name'] ) database_connector = MySqlConnector( connection_info=database_connection_info_func() ) database_inventory_repository = DatabaseInventoryRepository( database_connector=database_connector ) file_inventory_repository = FileInventoryRepository() inventory_repositories = { 'file': file_inventory_repository, 'database': database_inventory_repository } inventory_repository = inventory_repositories[inventory_repository_selector(app_config)] http_utils = HttpUtils( func_get_headers=lambda: (event['headers'] or dict()).items() ) def behavior_factory(name, value): if name == "throw": return ThrowException() elif name == "compute": return Compute(value) elif name == "malloc": return Malloc(value) elif name == "invalid_query": return InvalidQuery(database_inventory_repository) else: return None behavior_repository = Repository( app_id=app_config.get_app_id(), behavior_factory_func=behavior_factory ) AppLogging.init('info') if(inventory_repository_selector(app_config) == 'database'): setup_database = SetupDatabaseAction(database_connector, database_connection_info_func(), get_inventory_data()) setup_database.execute() endpoint = (event['resource'] or "").lower() if endpoint == "/": index = IndexHandler(app_config, behavior_repository) resp = index.index_message() elif endpoint == "/validatemessage": message = MessageHandler(app_config, http_utils, behavior_repository) resp = message.validate() elif endpoint == "/help": resp = help_message() elif endpoint == "/inventory": inventory = InventoryHandler(app_config, inventory_repository, http_utils, behavior_repository) resp = inventory.get_inventory() elif endpoint == "/inventory/{id+}": inventory = InventoryHandler(app_config, inventory_repository, http_utils, behavior_repository) item_id = event['pathParameters']['id'] resp = inventory.get_inventory_item(item_id) else: body = "Unsupported endpoint: " + endpoint resp = TronResponse(body, dict(), 404) return get_lambda_reponse(resp)
def test_get_dependency(self): app_config = AppConfig(self.arguments) result = app_config.get_dependency_endpoint('app2') assert (len(result) > 0)
def test_get_app_port_no_value(self): app_config = AppConfig(self.arguments) with self.assertRaises(Exception): app_config.get_app_port()
def test_get_delay_start_ms(self): app_config = AppConfig(self.arguments) result = app_config.get_delay_start_ms() self.assertEqual(result, 123)
def test_get_app_port(self): app_config = AppConfig(self.arguments) result = app_config.get_app_port() self.assertEqual(result, 5000)
def test_get_app_id(self, request_mock): app_config = AppConfig(self.arguments) result = app_config.get_app_id() self.assertEqual(result, 'app1')
def end_synthesia_song(self): self.synthesia_pixels = [(0, 0, 0) for _ in range(AppConfig.instance().conf["pixel_count"])] self.in_song = False
import time from lib.midi_message import MidiMessage from lib.app_config import AppConfig from lib.light_strip import LightStrip from lib.midi_device import MidiDevice from helpers.functions import hex_to_rgb from lib.lcd_manager import LcdManager CONFIG = AppConfig.instance().conf lcd_manager = LcdManager.instance() synthesia = MidiDevice(CONFIG["devices"]["synthesia"]) piano = MidiDevice(CONFIG["devices"]["piano"]) light_strip = LightStrip.instance() light_strip.play_boot_sequence() def play_note(msg): color_conf = CONFIG["colors"] color = color_conf["default"] if msg.is_left_hand() and msg.is_black_key(): color = color_conf["left_black"] elif msg.is_left_hand() and not msg.is_black_key(): color = color_conf["left"] elif msg.is_right_hand() and msg.is_black_key(): color = color_conf["right_black"] elif msg.is_right_hand() and not msg.is_black_key(): color = color_conf["right"]