def lcd_add(form): action = '{action} {controller}'.format( action=TRANSLATIONS['add']['title'], controller=TRANSLATIONS['lcd']['title']) error = [] if current_app.config['TESTING']: dep_unmet = False else: dep_unmet, _ = return_dependencies(form.lcd_type.data) if dep_unmet: list_unmet_deps = [] for each_dep in dep_unmet: list_unmet_deps.append(each_dep[0]) error.append("The {dev} device you're trying to add has unmet dependencies: {dep}".format( dev=form.lcd_type.data, dep=', '.join(list_unmet_deps))) try: new_lcd = LCD() new_lcd_data = LCDData() if GPIO.RPI_REVISION == 2 or GPIO.RPI_REVISION == 3: new_lcd.i2c_bus = 1 else: new_lcd.i2c_bus = 0 new_lcd.lcd_type = form.lcd_type.data new_lcd.name = str(LCD_INFO[form.lcd_type.data]['name']) if form.lcd_type.data == '128x32_pioled': new_lcd.location = '0x3c' new_lcd.x_characters = 21 new_lcd.y_lines = 4 elif form.lcd_type.data == '128x64_pioled': new_lcd.location = '0x3c' new_lcd.x_characters = 21 new_lcd.y_lines = 8 elif form.lcd_type.data == '16x2_generic': new_lcd.location = '0x27' new_lcd.x_characters = 16 new_lcd.y_lines = 2 elif form.lcd_type.data == '16x4_generic': new_lcd.location = '0x27' new_lcd.x_characters = 16 new_lcd.y_lines = 4 if not error: new_lcd.save() new_lcd_data.lcd_id = new_lcd.unique_id new_lcd_data.save() display_order = csv_to_list_of_str(DisplayOrder.query.first().lcd) DisplayOrder.query.first().lcd = add_display_order( display_order, new_lcd.unique_id) db.session.commit() except sqlalchemy.exc.OperationalError as except_msg: error.append(except_msg) except sqlalchemy.exc.IntegrityError as except_msg: error.append(except_msg) flash_success_errors(error, action, url_for('routes_page.page_lcd')) if dep_unmet: return 1
def lcd_add(quantity): action = '{action} {controller}'.format( action=gettext("Add"), controller=gettext("LCD")) error = [] for _ in range(0, quantity): try: new_lcd = LCD() new_lcd_data = LCDData() if GPIO.RPI_REVISION == 2 or GPIO.RPI_REVISION == 3: new_lcd.i2c_bus = 1 else: new_lcd.i2c_bus = 0 new_lcd.save() new_lcd_data.lcd_id = new_lcd.unique_id new_lcd_data.save() display_order = csv_to_list_of_str(DisplayOrder.query.first().lcd) DisplayOrder.query.first().lcd = add_display_order( display_order, new_lcd.unique_id) db.session.commit() except sqlalchemy.exc.OperationalError as except_msg: error.append(except_msg) except sqlalchemy.exc.IntegrityError as except_msg: error.append(except_msg) flash_success_errors(error, action, url_for('routes_page.page_lcd'))
def lcd_add(form): action = '{action} {controller}'.format( action=TRANSLATIONS['add']['title'], controller=TRANSLATIONS['lcd']['title']) error = [] if current_app.config['TESTING']: dep_unmet = False else: dep_unmet, _ = return_dependencies(form.lcd_type.data) if dep_unmet: list_unmet_deps = [] for each_dep in dep_unmet: list_unmet_deps.append(each_dep[0]) error.append("The {dev} device you're trying to add has unmet " "dependencies: {dep}".format( dev=form.lcd_type.data, dep=', '.join(list_unmet_deps))) try: new_lcd = LCD() new_lcd_data = LCDData() try: from RPi import GPIO if GPIO.RPI_REVISION == 2 or GPIO.RPI_REVISION == 3: new_lcd.i2c_bus = 1 else: new_lcd.i2c_bus = 0 except: logger.error("RPi.GPIO and Raspberry Pi required for this action") lcd_id = form.lcd_type.data.split(",")[0] lcd_interface = form.lcd_type.data.split(",")[1] new_lcd.lcd_type = lcd_id new_lcd.interface = lcd_interface new_lcd.name = str(LCD_INFO[lcd_id]['name']) if lcd_id in ['128x32_pioled', '128x64_pioled' ] and lcd_interface == 'I2C': new_lcd.location = '0x3c' new_lcd.pin_reset = 19 elif lcd_id in ['16x2_generic', '20x4_generic' ] and lcd_interface == 'I2C': new_lcd.location = '0x27' elif lcd_interface == 'SPI': new_lcd.pin_reset = 19 new_lcd.pin_dc = 16 new_lcd.spi_device = 0 new_lcd.spi_bus = 0 if lcd_id == '128x32_pioled': new_lcd.x_characters = 21 new_lcd.y_lines = 4 elif lcd_id == '128x64_pioled': new_lcd.x_characters = 21 new_lcd.y_lines = 8 elif lcd_id == '16x2_generic': new_lcd.x_characters = 16 new_lcd.y_lines = 2 elif lcd_id == '20x4_generic': new_lcd.x_characters = 20 new_lcd.y_lines = 4 if not error: new_lcd.save() new_lcd_data.lcd_id = new_lcd.unique_id new_lcd_data.save() display_order = csv_to_list_of_str(DisplayOrder.query.first().lcd) DisplayOrder.query.first().lcd = add_display_order( display_order, new_lcd.unique_id) db.session.commit() except sqlalchemy.exc.OperationalError as except_msg: error.append(except_msg) except sqlalchemy.exc.IntegrityError as except_msg: error.append(except_msg) flash_success_errors(error, action, url_for('routes_page.page_lcd')) if dep_unmet: return 1