Exemplo n.º 1
0
class ClockThread(threading.Thread):
    def __init__(self, settings):
        threading.Thread.__init__(self)
        self.segment = SevenSegment(address=0x70)
        self.stopping = False
        # self.settings = Settings.Settings()
        self.settings = settings
        self.colon = 0

    def stop(self):
        self.segment.disp.clear()
        self.stopping = True

    def run(self):
        while (not self.stopping):
            now = datetime.datetime.now(
                pytz.timezone(self.settings.get('timezone')))
            # hour = now.hour
            hour = int(now.strftime("%I").lstrip("0"))

            minute = now.minute
            second = now.second

            # Set hours
            self.segment.writeDigit(0, int(hour / 10))  # Tens
            self.segment.writeDigit(1, hour % 10)  # Ones
            # Set minutes
            self.segment.writeDigit(3, int(minute / 10))  # Tens
            self.segment.writeDigit(4, minute % 10)  # Ones
            # Toggle colon
            self.segment.writeDigitRaw(2, self.colon)
            self.colon = self.colon ^ 0x2

            time.sleep(1)
Exemplo n.º 2
0
class ClockThread(threading.Thread):
    def __init__(self, settings):
        threading.Thread.__init__(self)
        self.segment = SevenSegment(address=0x70)
        self.stopping = False
        # self.settings = Settings.Settings()
        self.settings = settings
        self.colon = 0

    def stop(self):
        self.segment.disp.clear()
        self.stopping = True

    def run(self):
        while (not self.stopping):
            now = datetime.datetime.now(pytz.timezone(self.settings.get('timezone')))
            # hour = now.hour
            hour = int(now.strftime("%I").lstrip("0"))

            minute = now.minute
            second = now.second

            # Set hours
            self.segment.writeDigit(0, int(hour / 10))  # Tens
            self.segment.writeDigit(1, hour % 10)  # Ones
            # Set minutes
            self.segment.writeDigit(3, int(minute / 10))  # Tens
            self.segment.writeDigit(4, minute % 10)  # Ones
            # Toggle colon
            self.segment.writeDigitRaw(2, self.colon)
            self.colon = self.colon ^ 0x2

            time.sleep(1)
Exemplo n.º 3
0
class SevenSegDisplay:

  def __init__(self, num_digits=4, address=0x70):
    self.num_digits = num_digits
    self.digit = 0
    self.seg = SevenSegment(address)

  def setup(self):
    return None

  def cleanup(self):
    return None

  def start(self):
    self.digit = 0

  def latch(self):
    return None

  def send_raw(self, segments):
    self.seg.writeDigitRaw(self.digit, segments)
    self.digit += 1
    # digits 2 is the colon, skip 
    if self.digit == 2:
      self.digit += 1

  def output(self, value):
    """ Outputs a string or a integer number onto 7-segment display."""
    raw = sevenseg.text(value, self.num_digits)
    self.start()
    for c in raw:
      self.send_raw(c)

  def blank(self):
    """ Blanks the display (all LED off). """
    raw = sevenseg.blanks(self.num_digits)
    self.start()
    for c in raw:
      self.send_raw(c)
Exemplo n.º 4
0
    segment2.writeDigit(0,0)
    segment2.writeDigit(1,0)

    segment2.writeDigit(4,0)
    segment3.writeDigit(0,0)

    segment3.writeDigit(3,0)
    segment3.writeDigit(4,0)

display_zeros()
time.sleep(2)

while(True):
    try:
        print "fetching predictions"
        segment1.writeDigitRaw(4,65)
        predictions = train_predictions()
    except:
        print "error while fetching predictions"
        display_dashes()
        subprocess.call(['./wifi_rebooter.sh'])
        time.sleep(REFRESH_INTERVAL)
        print "continuing"
        continue

    customink_str = output_string(predictions["customink"])
    downtown_str = output_string(predictions["downtown"])
    
    print "customink: " + customink_str.replace(" ", "_")
    print "downtown:  " + downtown_str.replace(" ", "_")
    
Exemplo n.º 5
0
print datetime.datetime.now()
print API_data
print temp


# Continually update the time on a 4 char, 7-segment display
# while True:
#     now = datetime.datetime.now()
#     hour = now.hour
#     minute = now.minute
#     second = now.second
#     # Set hours
#     segment.writeDigit(0, int(hour / 10))     # Tens
#     segment.writeDigit(1, hour % 10)          # Ones
#     # Set minutes
#     segment.writeDigit(3, int(minute / 10))   # Tens
#     segment.writeDigit(4, minute % 10)        # Ones
#     # Toggle color
#     segment.setColon(second % 2)              # Toggle colon at 1Hz
#     # Wait one second
#     time.sleep(1)
#
while True:

    segment.writeDigit(0, int(temp / 10))
    segment.writeDigit(1, temp % 10)
    segment.writeDigitRaw(2, 0x2)
    segment.writeDigit(3, 8)
    segment.writeDigit(4, 8)
    time.sleep(10)
    break
Exemplo n.º 6
0
print "Press CTRL+Z to exit."

digit2_colon = 0x02
digit2_dot = 0x10
digit0 = 0

while(True):
  now = datetime.datetime.now()
  hour = now.hour
  minute = now.minute
  second = now.second
  dots = 0x0
  dots = dots^digit2_dot if (hour >= 12) else dots
  dots = dots^digit2_colon if (second % 2) else dots
  if hour == 0:
    hour = 12
  if hour > 12:
    hour = hour - 12
  if (hour >= 10 and digit0 == 0):
    segment.writeDigit(0, 1)
    digit0 = 1
  if (hour < 10 and digit0 == 1):
    segment.disp.clear()
    digit0 = 0
  segment.writeDigit(1, hour % 10)
  segment.writeDigitRaw(2, dots)
  segment.writeDigit(3, int(minute / 10))
  segment.writeDigit(4, minute % 10)
  time.sleep(0.25)

Exemplo n.º 7
0
segment = SevenSegment(address=0x70)

# Ecouter sur le port 2947 (gpsd) de localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

while True:
    try:
        report = session.next()
        if report['class'] == 'TPV':
            if hasattr(report, 'speed'):
                print report.speed
                vitesse = report.speed * 3.6
                segment.writeDigit(1, int(vitesse / 10))
                if int(vitesse % 10) == 0: segment.writeDigitRaw(3, 63 + 128)
                if int(vitesse % 10) == 1: segment.writeDigitRaw(3, 6 + 128)
                if int(vitesse % 10) == 2: segment.writeDigitRaw(3, 91 + 128)
                if int(vitesse % 10) == 3: segment.writeDigitRaw(3, 79 + 128)
                if int(vitesse % 10) == 4: segment.writeDigitRaw(3, 102 + 128)
                if int(vitesse % 10) == 5: segment.writeDigitRaw(3, 109 + 128)
                if int(vitesse % 10) == 6: segment.writeDigitRaw(3, 125 + 128)
                if int(vitesse % 10) == 7: segment.writeDigitRaw(3, 7 + 128)
                if int(vitesse % 10) == 8: segment.writeDigitRaw(3, 127 + 128)
                if int(vitesse % 10) == 9: segment.writeDigitRaw(3, 111 + 128)
                segment.writeDigit(4, int((vitesse * 10) % 10))  # Ones
    except KeyError:
        pass
    except KeyboardInterrupt:
        quit()
    except StopIteration:
Exemplo n.º 8
0
		predictionString2 = 'null'				
		
	# load current time hours/minutes into variables
	currentTime = str(datetime.datetime.now().time())
	currentHours = currentTime[0:2]
	currentMins = currentTime[3:5]
	
	# split prediction strings out into useful chunks
	predictionHours = predictionString[0][9:11]	
	predictionMins = predictionString[0][12:14]	
	predictionHours2 = predictionString2[0][9:11]	
	predictionMins2 = predictionString2[0][12:14]	
	
	if predictionString == "null":
		print("no bus 1")
		segment.writeDigitRaw(0, 0x08)		# underscore means no busses but I'm still working
		segment.writeDigitRaw(1, 0x08)
	if predictionString2 == "null":
		print("no bus 2")		
		segment.writeDigitRaw(3, 0x08)
		segment.writeDigitRaw(4, 0x08)				

	# if predictionString contains anything but null
	if (predictionString != "null"):
		# if closest bus will arrive within current hour
		if (currentHours == predictionHours):
			minEstimate = int(predictionMins) - int(currentMins)
			print("first arrival in " + str(minEstimate))
			# if less than ten minutes, set first digit to zero
			if int(minEstimate) <= 9:
				segment.writeDigit(0, 0)			
Exemplo n.º 9
0
# Copyright (c) 2015-2016 Sid Gadkari. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Last Revision Date: 02/15/2016

#!/usr/bin/python

# This script draws '----' and then clears the display of all data.

import time
import datetime
from Adafruit_7Segment import SevenSegment

display = SevenSegment(address=0x70)

# Clear display
display.disp.clear()
display.writeDigitRaw(0, 64)
display.writeDigitRaw(1, 64)
display.writeDigitRaw(3, 64)
display.writeDigitRaw(4, 64)
time.sleep(1)
display.disp.clear()