Пример #1
0
def lcd_begin():
    LCD.backlight()  # turn on backlight
    LCD.clear()
    LCD.setCursor(5, 0)  # row, column
    LCD.write("LCD ready!")
    LCD.setCursor(7, 2)  # row, column
    LCD.write("....")
Пример #2
0
def main():
        global thread_finished
#	logger.info('Player started!')
	
	# Basic commands for play the music
#	currentBackup = ""

	# Initialize LCD
	lcd = LCD()
	lcd.clear()
	lcd.begin(16,1)

        # Stop all players
        run_cmd(cmd_stop_all, False)

	# Start radio or backup
#	ledConnection = 2
#	ledCheck = 3

	GPIO.setmode(GPIO.BCM)
#	GPIO.setup(ledConnection, GPIO.OUT)

	# Start the main program in an infinite loop
	while True: 
		lcd.clear()
		lcd.message("ExeaMusicPlayer")
		sleep(2)
		
		lcd.clear()
		lcd.message("Escuchas:\n")
		lcd.message(title)
		sleep(2)
		
		#Check connection of internet
#		GPIO.output(ledConnection, 1)
		if checkInternetConnection():
#			GPIO.output(ledConnection, 0)
			#sleep(0.5)
                        lcd.clear()
                        lcd.message("Estas conectado\na Internet")
                        sleep(3)
		#Show IP info 
		lcd.clear()
		ipaddr = run_cmd(cmd_ip)
		if not ipaddr:
			lcd.message('Sin Internet\n')
		else:
			lcd.message('IP%s' % ( ipaddr ))

		#Show date for 10 seconds
		i = 0
		while i<10:
			lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
			sleep(1)
			i = i+1
			pass

	thread_finished = True
Пример #3
0
def main():
   #Create unix pipe
   main_pipe, fingerpint_pipe = Pipe()
   LCD_IN, LCD_OUT = Pipe()
   
   # Initializes LCD and LED
   LCD.init()
   LED.init()
   # Create an object of the class Parser and Poller
   parser = Parser()
   poller = Poller(parser, fingerpint_pipe, 1)
   # Create child process
   pid = os.fork()

   # Parent process
   if pid:
      try:
         # start the individual threads for LCD, NFC and poller
         lcd_thread = threading.Thread(target=LCD.new_start, args=(LCD_IN,))
         lcd_thread.daeomon = True
         lcd_thread.start()
         nfc_thread = threading.Thread(target=nfcread.readNFC, args=(parser, fingerpint_pipe, LCD_OUT,))
         nfc_thread.daeomon = True
         nfc_thread.start()
         poll_thread = threading.Thread(target=poller.startPolling)
         poll_thread.daeomon = True
         poll_thread.start()
      except:
         print "Error: unable to start thread"
      try:
         # Poll fingerprint pipe
         while 1:
            if fingerpint_pipe.poll(1):
               parser.course_id = fingerpint_pipe.recv()
      # Kill the threads and clears the LCD screen
      except KeyboardInterrupt:
         LCD.clear()
         os.kill(pid, signal.SIGKILL)
         os.kill(os.getpid(), signal.SIGKILL)
         sys.exit()
         
         
   else:
      # Start fingerprint on child procces
      try:
         fingerprint = Fingerprint()
         fingerprint.start(parser, main_pipe, LCD_OUT)
      # Clear the screen
      except KeyboardInterrupt:
         LCD.clear()
         sys.exit()
Пример #4
0
def buttons():
    global thread_finished
    buttonShutdown = 11
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(buttonShutdown, GPIO.IN)

    while True:
        if (GPIO.input(buttonShutdown)):
            lcd = LCD()
            lcd.clear()
            lcd.begin(16,1)
            lcd.message("Reiniciando\nSistema...")
            sleep(2)
            lcd.clear()
            reboot()
    	sleep(4)
    thread_finished = True
Пример #5
0
def main():
    logger.info('Player started!')
    # Initialize LCD
    lcd = LCD()
    lcd.clear()
    lcd.begin(16,1)
    # Start the main program in an infinite loop
    while True:
        status = run_cmd(cmd_check_device, True)
        status = status[:4]
        lcd.clear()
        lcd.message("ExeaMusicPlayer\n")
        lcd.message( 'Estado: ' + status )
        sleep(2)

        lcd.clear()
        lcd.message("Escuchas:\n")
        lcd.message(title)
        sleep(2)

        #Show Serial
        lcd.clear()
        lcd.message("Serial:\n")
        lcd.message(serial)
        sleep(3)

        #Show IP info
        lcd.clear()
        ipaddr = run_cmd(cmd_ip)

        if not ipaddr:
            lcd.message('Sin Internet\n')
        else:
            lcd.message( ipaddr )

	#Show date for 10 seconds
        i = 0
        while i<10:
            lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
            sleep(1)
            i = i+1
            pass
    thread_finished = True
Пример #6
0
    # initialize video stream from camera
    vs = VideoStream(src=0).start()
    #    vs = cv2.VideoCapture(0)
    time.sleep(2.0)
    fps = FPS().start()

    totalFrames = 0
    totalCount = 0

    cor_trackers = []
    point_tracker = Tracker()
    trackable_objects = {}

    inbox.put(imutils.resize(vs.read(), W))
    screen.clear()
    screen.display("\n  PEOPLE COUNT\n       0")

    while True:

        if inbox.empty() and outbox.empty():
            #            print("putting frame")
            frame_queue.put(imutils.resize(vs.read(), W))

        if not outbox.empty():

            print("QUEUE:", frame_queue.qsize())
            print(datetime.datetime.now())

            #empty trackers
            cor_trackers = []
Пример #7
0
class DeployModule(object):
    bob_api = None
    deployed = False
    logout_time = None

    def __init__(self):
        self.deploy_button = Button(DEPLOY_BUTTON_PORT, self.deploy)
        self.select_repo_next_button = Button(
            REPO_BUTTON_NEXT_PORT,
            lambda on: self.select_change('repo next', on))
        self.select_repo_prev_button = Button(
            REPO_BUTTON_PREV_PORT,
            lambda on: self.select_change('repo prev', on))
        self.select_pr_next_button = Button(
            PR_BUTTON_NEXT_PORT, lambda on: self.select_change('pr next', on))
        self.select_pr_prev_button = Button(
            PR_BUTTON_PREV_PORT, lambda on: self.select_change('pr prev', on))
        self.lcd = LCD()
        self.button_matchers = [
            NetworkInfo(self.lcd, LOG_IN_MESSAGE),
            RestartApp(self.lcd)
        ]

        self.selected_repo_index = 0
        self.selected_pr_index = 0
        self.repo_list = []
        self.pull_requests = []

        self.rfid = RFID(self.startup)
        self.listen_for_rfid()

    def listen_for_rfid(self):
        self.bob_api = None
        print(LOG_IN_MESSAGE)
        self.lcd.clear()
        self.lcd.write(LOG_IN_MESSAGE, 0)

    def startup(self, tag):
        print('Got tag ' + tag)
        [button_matcher.reset() for button_matcher in self.button_matchers]
        self.bob_api = BobApi(tag)
        self.refresh_repos(show_welcome=True)
        if self.repo_list:
            self.bump_logout_time()
        else:
            self.listen_for_rfid()

    def is_logged_in(self):
        return self.bob_api is not None

    def bump_logout_time(self):
        self.logout_time = datetime.now() + timedelta(
            minutes=LOGOUT_IN_MINUTES)

    def logout_time_expired(self):
        return self.logout_time < datetime.now()

    def logout(self):
        self.logout_time = None
        self.listen_for_rfid()

    def refresh_repos(self, show_welcome=False):
        self.lcd.clear()
        self.lcd.write('Loading...', 0)
        self.fetch_repos(show_welcome)
        self.update_repo()

    def fetch_repos(self, show_welcome):
        try:
            data = self.bob_api.get_repos_and_user_name()

            if data.get('user') and show_welcome:
                self.lcd.write('Welcome {name}!'.format(name=data.get('user')),
                               0)
                sleep(2)

            self.repo_list = data.get('repos')
            if self.repo_list and len(self.repo_list) is 0:
                self.repo_list = [
                    {
                        'display_name': '-- No repos found'
                    },
                ]
        except Exception:
            self.lcd.write('Repo loading err', 0)
            self.lcd.write('Please try again', 1)
            sleep(2)

    def fetch_pull_requests(self):
        self.pull_requests = self.bob_api.get_pull_requests(
            self.repo_list[self.selected_repo_index]['id'])
        self.selected_pr_index = 0

        if len(self.pull_requests) is 0:
            self.pull_requests = [
                {
                    'id': 0,
                    'title': '-- No PRs'
                },
            ]

    def update_repo(self):
        if self.repo_list:
            self.lcd.write(
                self.repo_list[self.selected_repo_index]['display_name'], 0)
            self.lcd.write('Loading...', 1)
            self.fetch_pull_requests()
            self.update_pr()

    def update_pr(self):
        self.lcd.write(self.pull_requests[self.selected_pr_index]['title'], 1)

    def handle_after_deploy_input(self):
        self.bump_logout_time()
        self.deployed = False
        self.refresh_repos()

    def deploy(self, pressed_down):
        if self.is_logged_in() and pressed_down:
            if self.deployed:
                self.handle_after_deploy_input()
            elif len(self.pull_requests
                     ) and not self.pull_requests[0]['id'] == 0:
                self.bump_logout_time()
                pr = self.pull_requests[self.selected_pr_index]
                print('Deploying ' + pr['title'])
                self.lcd.clear()
                self.lcd.write('Deploying...', 0)
                response = self.bob_api.deploy(
                    self.repo_list[self.selected_repo_index]['id'], pr['id'])
                self.lcd.write(response['message'], 1)
                self.deployed = True

    def create_select_change_handler(self, type):
        def handler(on):
            self.select_change(type, on)

        return handler

    def select_change(self, type, on):
        if on:
            if not self.is_logged_in():
                [
                    button_matcher.button_changed(type)
                    for button_matcher in self.button_matchers
                ]
            elif self.deployed:
                self.handle_after_deploy_input()
            else:
                self.bump_logout_time()
                if type == 'repo prev':
                    if self.selected_repo_index is 0:
                        self.selected_repo_index = len(self.repo_list) - 1
                    else:
                        self.selected_repo_index -= 1
                elif type == 'repo next':
                    if self.selected_repo_index is len(self.repo_list) - 1:
                        self.selected_repo_index = 0
                    else:
                        self.selected_repo_index += 1
                elif type == 'pr prev':
                    if self.selected_pr_index is 0:
                        self.selected_pr_index = len(self.pull_requests) - 1
                    else:
                        self.selected_pr_index -= 1
                elif type == 'pr next':
                    if self.selected_pr_index is len(self.pull_requests) - 1:
                        self.selected_pr_index = 0
                    else:
                        self.selected_pr_index += 1

                if 'repo' in type:
                    self.update_repo()
                elif 'pr' in type:
                    self.update_pr()

    def process(self):
        self.deploy_button.read_input()
        self.select_repo_next_button.read_input()
        self.select_repo_prev_button.read_input()
        self.select_pr_next_button.read_input()
        self.select_pr_prev_button.read_input()
        if (not self.is_logged_in()) and int(time() % 1 * 100) == 0:
            self.rfid.read()
        elif self.is_logged_in() and self.logout_time_expired():
            self.logout()

    def destroy(self):
        self.lcd.clear()
        self.lcd.write('Shutdown', 0)
        self.lcd.destroy()
Пример #8
0
    ip_address = ''
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    ip_address = s.getsockname()[0]
    s.close()
    return ip_address


rfid = RFID()

host_ip = get_ip_address()

while True:

    tag_id, tag_text = rfid.read_no_block()

    print(tag_id)

    lcd.clear()

    if tag_id is None:
        lcd.write(host_ip)
        led.value = False
    else:
        lcd.write(tag_text)
        if tag_id == 989699569615:

            led.value = True

GPIO.cleanup()
Пример #9
0
 def loop():
     global lcd
     print("lcd LOADED")
     lcd = LCD()
     lcd.clear()
     lcd.message("Hello")
Пример #10
0
class Ticker:
    def __init__(self, symbol: str) -> None:
        self.symbol = symbol

        print("init BTC ticker...")
        self.lcd = LCD()
        self.client = Client(api_key=API_KEY, api_secret=API_SECRET)

        # init screen
        self.lcd.clear()
        self.lcd.writeLine1("BTC / EUR")

        self.running: bool = False
        self.currentPrice: float = 0

    def getMethod(self):
        """ Poll price by sending an active request to the binance server """
        while True:
            try:
                #client.ping()
                #price: dict = client.get_avg_price(symbol="BTCEUR")
                price: dict = self.client.get_symbol_ticker(symbol=self.symbol)
            except KeyboardInterrupt:
                print("exiting....")
                sys.exit()

            self.lcd.writeLine2(price.get("price"))
            time.sleep(1)
            #print(price.get("price"))

    def wsMethod(self):
        """ Get current price by using a websocket connection """
        bm = BinanceSocketManager(self.client)

        signal.signal(signal.SIGINT, self._closeConnection)
        signal.signal(signal.SIGTERM, self._closeConnection)

        bm.start_trade_socket(self.symbol, self._wsCallback)
        bm.start()

        self.running = True
        self.writeThread = Thread(target=self.writeLCD)
        self.writeThread.start()

    def _wsCallback(self, msg: dict):
        self.currentPrice = float(msg.get("p"))
        print(f'Preis: {self.currentPrice}')

    def writeLCD(self):
        while self.running:
            print(f"LCD {self.currentPrice}")
            self.lcd.writeLine2(str(self.currentPrice))
            time.sleep(1)

    def _closeConnection(self, signum, frame):
        print("exiting...")
        self.running = False
        reactor.stop()
        self.writeThread.join()

        self.lcd.close()
Пример #11
0
def main():
	global thread_finished
	logger.info('Player started!')

	# Read arguments
	if len(sys.argv) >= 3:	
		url = sys.argv[1]
		# Read the title of the streaming
		if len(sys.argv) > 3:
			title = sys.argv[2]
			for x in xrange(3,len(sys.argv)):
				title = title + " " + sys.argv[x]
		else:
			title = sys.argv[2]
	else:
		print "Usage: player.py {url} {title}";
		logger.error("Usage: player.py {url} {title}")
		return

	print "The url of the streaming is:",colored(url, "green")
	print "The name of the radio is:", colored(title, "green")
	logger.info('The url of the streaming is: ' + url)
	logger.info('The name of the radio is: ' + title)

	# Initialize variables
	
	# Basic commands for play the music
	cmd_play_streaming = "mpg123 " + url + " &"
	currentBackup = ""

	# Initialize LCD
	lcd = LCD()
	lcd.clear()
	lcd.begin(16,1)

	# Stop all players
	run_cmd(cmd_stop_all, False)

	# Start radio or backup
	ledConnection = 2
	ledCheck = 3

	GPIO.setmode(GPIO.BCM)
	GPIO.setup(ledConnection, GPIO.OUT)
	GPIO.setup(ledCheck, GPIO.OUT)

	playingRadio = True
	if checkInternetConnection():
		run_cmd(cmd_play_streaming, False)
		logger.info("Playing streamming from " + url)
	else:
		playBackup()
		playingRadio = False

	# Start the main program in an infinite loop

	while 1:
		lcd.clear()
		lcd.message("ExeaMusicPlayer")
		sleep(2)
		
		if playingRadio:
			# Check Internet status
			if checkInternetConnection():
				lcd.clear()
				lcd.message("Escuchas:\n")
				lcd.message(title)
				sleep(2)
				pass
			else:
				# Play backup
				lcd.clear()
				lcd.message("Reproduciendo\nrespaldo")
				sleep(1)
				currentBackup = playBackup()
				lcd.clear()
				lcd.message("Respaldo\n")
				lcd.message(currentBackup)
				sleep(2)
				playingRadio = False
				pass
			pass
		else:
			# Restore streaming radio or show status of "backup"
			if checkInternetConnection():
				run_cmd(cmd_stop_all, False)
				run_cmd(cmd_play_streaming, False)
				logger.info('Playing streamming from ' + url)
				playingRadio = True
				pass
			else:
				lcd.clear()
				lcd.message("Respaldo\n")
				lcd.message(currentBackup)
				sleep(2)
		#Check connection of internet
		GPIO.output(ledConnection, 1)
		if checkInternetConnection():
			GPIO.output(ledConnection, 0)
			sleep(0.5)

		#Check Play the Backup or Stream
		if playingRadio == True:
			GPIO.output(ledCheck, 1)
		else:
			GPIO.output(ledCheck, 0)

		#Show IP info 
		lcd.clear()
		ipaddr = run_cmd(cmd_ip)
		if not ipaddr:
			lcd.message('Sin Internet\n')
		else:
			lcd.message('IP %s' % ( ipaddr ))

		#Show date for 10 seconds
		i = 0
		while i<10:
			lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
			sleep(1)
			i = i+1
			pass

	thread_finished = True
Пример #12
0
def buttons():
	global thread_finished
	
	buttonReboot = 9
	buttonRestart = 10 
	buttonShutdown = 11
	
	GPIO.setmode(GPIO.BCM)

	GPIO.setup(buttonReboot, GPIO.IN)
	GPIO.setup(buttonShutdown, GPIO.IN)
	GPIO.setup(buttonRestart, GPIO.IN)

	while True:

		# if the last reading was low and this one high, print
		if (GPIO.input(buttonReboot)):
			lcd = LCD()
			lcd.clear()
			lcd.begin(16,1)
			lcd.message("Reiniciando\nSistema")
			sleep(3)
			lcd.clear()
			reboot()
			sleep(0.5)
			
			
		if (GPIO.input(buttonShutdown)):
			lcd = LCD()
			lcd.clear()
			lcd.begin(16,1)
			lcd.message("Apagando\nSistema...")
			sleep(3)
			lcd.clear()
			shutdown()
			sleep(0.5)
			

		if (GPIO.input(buttonRestart)):
			lcd = LCD()
			lcd.clear()
			lcd.begin(16,1)
			lcd.message("Reiniciando\nReproductor")
			sleep(3)
			lcd.clear()
			restart()
			sleep(0.5)

	thread_finished = True