def __init__(self): """ constructeur """ print('Démarrage jeux ... ') self.lcd = Lcd() # affichage LCD du jeux self.lcd.write_char('robot_ok', pos=(0, 0)) self.lcd.msg_centre('SinS', 'Initialisation') self.lcd.write_char('robot_ok', pos=(15, 0)) self.buzzer = Buzz() # buzzer du jeux self.rackleds = RackLeds() # rack de leds self.rackbuttons = RackButtons(self.rackleds, self.buzzer) # rack de boutons self.color = ['V', 'B', 'J', 'R'] # couleur du jeux self.dic_color = {'V': 0, 'B': 1, 'J': 2, 'R': 3} self.file_scores = '/flash/scores.txt' # fichier des records self.scores = self.read_scores() # dictionnaire des record self.total_keys = 10 # nb_clés à trouver #mode de difficulté du jeux self.dic_mode = { 'V': ['Vert', 'Facile'], 'B': ['Bleu', 'Moyen'], 'J': ['Jaune', 'Difficile'], 'R': ['Rouge', 'Expert'], } self.mode = 'V' self.nb_portes = 3 # nb de portes par niveau à ouvrir self.niveau = self.nb_portes # nb de leds dans la séquence en cours self.init_seq() # initialise séquences
def __init__(self, leds, switches, countdown, game_time, score_increment): self.LEDS = leds self.SWITCHES = switches self.COUNTDOWN = countdown self.GAME_TIME = game_time self.SCORE_INCREMENT = score_increment self.gpio = Gpio self.lcd = Lcd() self.db = TinyDB('data/database.json') if len(self.LEDS) != len(self.SWITCHES): print( "[Game][error] There isn't the same number of LEDS as SWITCHES" ) exit() try: self.gpio.setmode(self.gpio.BCM) for switch in self.SWITCHES: self.gpio.setup(switch, self.gpio.IN) self.gpio.add_event_detect(switch, self.gpio.RISING, bouncetime=300) self.gpio.add_event_callback(switch, self.__button_press) for led in self.LEDS: self.gpio.setup(led, self.gpio.OUT) self.gpio.output(led, False) except AttributeError: print("[Game][error] An error occurred initialising game")
def __init__(self, config, core): super(TestFrontend, self).__init__() self.core = core self._now_playing_track = None self.lcd = Lcd() self.radioMenu = RadioMenu(self.lcd, self) logger.info("My plugin has loaded!") # set up fallback image self.plugin_dir = os.path.dirname(os.path.realpath(__file__)) self.fallback_image = self.plugin_dir + "/images/on_the_air.jpg" self.radioMenu.loading()
def write_to_lcd_and_lock_failure(lcd, message, led_buzzer): led_buzzer.trigger_failure() write_to_lcd_and_lock(lcd, message) def display_date_time(lcd, lcd_lock): while True: lcd_lock.wait_empty() write_to_lcd(lcd, get_current_date_time().strftime("%Y-%m-%d %H:%M:%S").split(' ')) sys_time.sleep(0.5) if __name__ == "__main__": logging.info("nfc main func started") nfc_reader_output_queue = queue.Queue() keypad = Keypad() lcd = Lcd(LCD_RS_PIN, LCD_E_PIN, LCD_DATA_PINS) led_buzzer = LedBuzzer(GREEN_LED_AND_BUZZER_PIN, RED_LED_PIN) system_state = SystemState() lcd_lock = LcdLock() threads = [] threads.append(threading.Thread(target=start_nfc_poll_producer, \ args=(nfc_reader_output_queue,))) threads.append(threading.Thread(target=start_nfc_poll_consumer, \ args=(nfc_reader_output_queue,keypad,lcd,led_buzzer,system_state,lcd_lock))) threads.append(threading.Thread(target=display_date_time, args=(lcd, lcd_lock))) for func in [lambda t: t.start(), lambda t: t.join()]: for thread in threads: func(thread)
def __init__(self): # Inicialização de logging self.logger = logging.getLogger('Apontamento') self.logger.setLevel('DEBUG') formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler = TimedRotatingFileHandler( 'apontamento.log', when='d', interval=1, backupCount=30) handler.setFormatter(formatter) self.logger.addHandler(handler) self.lcd = Lcd() self.cp = configparser.ConfigParser() try: self.cp.read('config.ini') except Exception as e: self.logger.error('Erro ao recuperar informações de configuração') self.lcd.write_line('Erro', 0, 1, 1) sys.exit() self.logger.info('Inicializando') server = self.cp.get('sistema', 'server') database = self.cp.get('sistema', 'database') user = self.cp.get('sistema', 'user') pwd = self.cp.get('sistema', 'password') self.logger.info('Incialização da base de dados') self.db = Database(server, database, user, pwd) self.logger.info('Carregando dados de apontamento') self.codemp = int(self.cp.get('apontamento', 'codemp')) self.codfil = int(self.cp.get('apontamento', 'codfil')) self.codope = int(self.cp.get('apontamento', 'codope')) self.codori = self.cp.get('apontamento', 'codori') self.numorp = int(self.cp.get('apontamento', 'numorp')) self.qtdprv = int(self.cp.get('apontamento', 'qtdprv')) self.qtdfrd = int(self.cp.get('apontamento', 'qtdfrd')) self.numfrd = int(self.cp.get('apontamento', 'numfrd')) self.last_codbar = 0 self.logger.info('Início da leitura do código de barras') try: while True: self.status() codbar: str = input() self.logger.info('Cod. Barras lido: {0}'.format(codbar)) if (7 <= len(codbar) <= 11) and codbar[4].__eq__('-'): if self.last_codbar == codbar: self.lcd.write_line('Apontado', 0, 1, 1) continue try: op, contcel = codbar.split('-') cont, cel = int( contcel[0:(len(contcel)-1)]), int(contcel[-1]) op = int(op) except: self.logger.info('Código invalido lido') self.lcd.write_line('Nao reconhecido', 0, 1, 1) continue if self.numorp == op: result = self.db.insert_entry(self.codemp, self.codfil, self.codope, self.codori, self.numorp, codbar, cont, cel) if result == 0: self.lcd.write_line('Ja apontado', 0, 1, 2) if result == 1: self.last_codbar = codbar self.lcd.write_line( 'Apontado: {0}'.format(codbar), 0, 1, 1) self.logger.info('Apontado: {0}'.format(codbar)) if self.numfrd == self.qtdfrd: self.numfrd = 1 else: self.numfrd = self.numfrd + 1 self.config_update( 'apontamento', 'numfrd', self.numfrd) else: self.logger.warning( 'Tentativa de fazer apontamento com OP errada: ' + str(codbar)) self.lcd.write_line('OP nao confere', 0, 1, 2) elif len(codbar) == 24 and codbar[0:2].__eq__('04'): nova_op = int(codbar[2:11]) if self.numorp != 0 and nova_op != self.numorp: self.logger.warning( 'Não é possível iniciar nova OP sem finalizar a última') self.lcd.write_line('OP nao fechada', 0, 1, 2) elif self.numorp != 0 and nova_op == self.numorp: self.logger.info('OP fechada: {0}'.format(self.numorp)) self.lcd.write_line('OP fechada', 0, 1, 2) self.numorp = 0 self.qtdprv = 0 self.qtdfrd = 0 self.config_update( 'apontamento', 'numorp', self.numorp) self.config_update( 'apontamento', 'qtdprv', self.qtdprv) self.config_update( 'apontamento', 'qtdfrd', self.qtdfrd) else: op, qtdprv, fardo = self.db.get_newop(nova_op) if op: self.numorp = op self.qtdfrd = fardo self.qtdprv = qtdprv self.numfrd = 0 self.logger.info('Dados de OP atualizados: OP - {0}, Qtde prev. - {1}, Qtde fardo - {2}' .format(op, fardo, qtdprv)) self.config_update('apontamento', 'numorp', op) self.config_update('apontamento', 'qtdfrd', fardo) self.config_update('apontamento', 'qtdprv', qtdprv) self.config_update( 'apontamento', 'numfrd', self.numfrd) self.lcd.write_line('Nova OP: ' + str(op), 0, 1, 2) else: self.lcd.write_line('Erro OP', 0, 1, 2) else: self.lcd.write_line('Nao reconhecido', 0, 1, 2) self.status() except Exception as e: self.logger.exception('Erro fatal') self.lcd.write_line("Fim", 0, 0, 0) self.logger.error("Programa passou do While, verificar")
import _thread import time import json from pyb import Timer import os from adc import Adc from lcd import Lcd from scan import Scan from outctl import Outctl from networks import Network adc = Adc() lcd = Lcd() scan = Scan() outctl = Outctl() network = Network() up_state_cnt = 0 #上位机状态计数器 file_flag = 0 #是否写入文件 adc_freq = 1000 #adc采样频率 voltage_b = 0 current_b = 0 warnvalue = 10 warntime = 20 stopvalue = 20 stoptime = 20 time_now = '' def up_state(tt):
import ubinascii import time import machine import json from connect import Connect from led_pwm import LedPwm from lcd import Lcd from temperature_dht11 import TemperatureSensor as Dht from mqtt import Mqtt dht = Dht(4) led = LedPwm(2) lcd = Lcd(spi=1, cs=2, dc=15, rst=0, bl=12) config = json.loads(open('config.json').read()) client_id = ubinascii.hexlify(machine.unique_id()) try: mqtt = Mqtt(client_id, config['broker_ip']) except: mqtt = False while True: # Connect to wifi Connect.check_and_reconnect() try: data = { 'temperature': dht.read_temp_and_hum()[0], 'humidity': dht.read_temp_and_hum()[1] } print(str(time.localtime()) + ' ' + str(data)) if not mqtt: try: mqtt = Mqtt(client_id, config['broker_ip'])
# pin config IO.pinMode(REDPIN, IO.OUTPUT) IO.pinMode(YELPIN, IO.OUTPUT) IO.pinMode(GRNPIN, IO.OUTPUT) IO.pinMode(SRNPIN, IO.OUTPUT) IO.pinMode(BTNPIN, IO.INPUT) # audio, maps to existing pwm channel for line out audio jack IO.pinMode(AUDIOPIN, IO.PWM_OUTPUT) # Set PWM range to 100 (duty cycle can be 0-100) wiringpi.softPwmCreate(REDPIN, 0, 100) wiringpi.softPwmCreate(YELPIN, 0, 100) wiringpi.softPwmCreate(GRNPIN, 0, 100) LCD = Lcd(LCD_ROWS, LCD_CHARS, LCD_BITS, PIN_LCD_RS, PIN_LCD_E, PINS_LCD_DB) SPEECH = Speech() # Siren state machine functions def siren_on(fsm): """Turn on Siren""" IO.digitalWrite(SRNPIN, IO.HIGH) time.sleep(1.7) def siren_off(fsm): """Turn off Siren""" IO.digitalWrite(SRNPIN, IO.LOW) time.sleep(0.5)
ap = argparse.ArgumentParser(description='AUV LCD Daemon') ap.add_argument('--virtual', action='store_const', const=True, help='Enable virtual testing mode (gtk LCD display)') args = ap.parse_args() if args.virtual: # Use GTK lcd screen window instead of hardware LCD from virtual_lcd import VirtualLcd screen = VirtualLcd() else: # Connect to the hardware LCD from lcd import Lcd screen = Lcd() screen.init() dispatch = ScreenDispatcher() def interrupt_handler(signal, frame): print "\nExiting" dispatch.stop_all() surface, cr = screen.new_surface() exitscreen = ExitScreen() exitscreen.draw(cr) screen.write_surface(surface) sys.exit(0)