Esempio n. 1
0
 def __init__(self):
     # create seven segment device
     self.serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219(self.serial, cascaded=1)
     self.device.contrast(200)
     self.seg = sevensegment(self.device)
     self.scroll_thread = None
Esempio n. 2
0
def test_overflow():
    device = dummy(width=24, height=8, mode="1")
    seg = sevensegment(device, segment_mapper=dot_muncher)
    with pytest.raises(OverflowError) as ex:
        seg.text = "This is too big to fit in 3x8 seven-segment displays"
    assert str(
        ex.value
    ) == "Device's capabilities insufficient for value 'This is too big to fit in 3x8 seven-segment displays'"
Esempio n. 3
0
 def __init__(self):
     serial = spi(port=0, device=0, gpio=noop())
     device = max7219(serial, cascaded=1)
     device.contrast(15)
     self.seg = sevensegment(device)
     self.update_clock()
     self.messages = []
     self.t0 = time.time()
Esempio n. 4
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)
    #orig_demo(serial, device, seg)
    #clock(seg, seconds=10)
    show_message_vp(device, "you are the best Mr. Shivakumar", 0.5)
Esempio n. 5
0
def init_device(port=0, device_id=0, cascaded=1, contrast=127):
    '''Initialize both the raw matrix device and sevensegment abstraction.
       Each is used by the different effects generated below.
    '''
    serial = spi(port=port, device=device_id, gpio=noop())
    device = led(serial)
    seg = sevensegment(device)
    device.contrast(contrast)
    return device, seg
Esempio n. 6
0
def main():
    global CAMERA
    global logging
    global client
    global SENSOR_CONFIG
    global SETTINGS
    global SEG

    signal.signal(signal.SIGINT, signal_handler)
    try:
        # create seven segment device
        serial = spi(port=0, device=0, gpio=noop())
        device = max7219(serial, cascaded=1)
        SEG = sevensegment(device)

        SETTINGS.read("settings.ini")

        args = example_utils.ExampleArgumentParser(num_sens=1).parse_args()
        example_utils.config_logging(args)
        logging.info("radarCat starting with args " + str(args))

        if args.socket_addr:
            client = SocketClient(args.socket_addr)
        elif args.spi:
            client = SPIClient()
        else:
            port = args.serial_port or example_utils.autodetect_serial_port()
            client = UARTClient(port)

        # setup Camera date and time
        if os.name != 'nt':
            logging.info("set Camera date and time")
            callback_obj = gp.check_result(gp.use_python_logging())
            # open camera connection
            CAMERA = gp.check_result(gp.gp_camera_new())
            gp.check_result(gp.gp_camera_init(CAMERA))
            # get camera details
            abilities = gp.check_result(gp.gp_camera_get_abilities(CAMERA))
            # get configuration tree
            camConfig = gp.check_result(gp.gp_camera_get_config(CAMERA))

            # find the date/time setting config item and set it
            if set_datetime(camConfig, abilities.model):
                # apply the changed config
                gp.check_result(gp.gp_camera_set_config(CAMERA, camConfig))
            else:
                logging.error("Could not set date & time")

        SENSOR_CONFIG = get_sensor_config()
        SENSOR_CONFIG.sensor = args.sensors
    except:
        print("Unexpected error:", sys.exc_info()[0])

    while True:
        detection()
        time.sleep(3)
Esempio n. 7
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)
    now = datetime.now()
    seg.text = now.strftime("%Y.%m.%d")
    time.sleep(5)

    # Digit futzing
    clock(seg, seconds=20)
Esempio n. 8
0
def test_setter_getter():
    img_path = get_reference_image('golden_ratio.png')

    with open(img_path, 'rb') as img:
        reference = Image.open(img)
        device = dummy(width=24, height=8)
        seg = sevensegment(device, segment_mapper=dot_muncher)
        seg.text = "1.61803398875"
        assert str(seg.text) == "1.61803398875"

        assert_identical_image(reference, device.image)
Esempio n. 9
0
    def show_message_vp(self, msg, delay=0.1):
        # Implemented with virtual viewport
        width = self.device.width
        padding = " " * width
        msg = padding + msg + padding
        n = len(msg)

        virtual = viewport(self.device, width=n, height=8)
        sevensegment(virtual).text = msg
        for i in reversed(list(range(n - width))):
            virtual.set_position((i, 0))
            time.sleep(delay)
Esempio n. 10
0
def test_display():
    device = ht1621(gpio)
    gpio.reset_mock()

    sevensegment(device).text = "HELLO"

    assert gpio.get_data() == [
        gpio.data(0), gpio.data(0), gpio.data(0),     # _ _ _
        gpio.data(0), gpio.data(0), gpio.data(0),     # _ _ _
        gpio.data(0), gpio.data(125), gpio.data(13),  # _ O L
        gpio.data(13), gpio.data(31), gpio.data(103)  # L E H
    ]
def update_times():
    global off_t, on_t, off_str, on_str
    schedule.clear(
        'relays')  #Clear schedules tagged with 'relays' to prevent doubles
    p = Popen("php times_output_071.php", shell=True,
              stdout=PIPE)  #Run PHP script needs shell=True to run.
    logging.info('update_times() Script activated')
    getOutput = p.stdout.read().decode(
        'ascii')  #outputs in bytes, needs to be decoded.

    #Extract twilight flavours
    nautical = getOutput[4:14]
    astronomical = getOutput[18:28]
    civil = getOutput[32:42]

    theTimes = astronomical  #Select which flavour
    #Chop up data as integers
    off_H = int(theTimes[0:1])
    off_M = int(theTimes[3:4])
    on_H = int(theTimes[5:6])
    on_M = int(theTimes[8:9])
    disp_times = theTimes[0:1] + "." + theTimes[3:4] + theTimes[
        5:6] + "." + theTimes[8:9]

    print(off_H)
    print(off_M)
    print(on_H)
    print(on_M)
    print(disp_times)
    exit()

    #combine extracted integers as time for init check
    off_t = datetime.time(hour=off_H, minute=off_M)
    on_t = datetime.time(hour=on_H, minute=on_M)
    #extract also as string for schedules and logging
    off_str = theTimes[0:5]
    on_str = theTimes[5:10]

    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)

    seg.device.contrast(0x00)
    #seg.text = str(off_H) + "." + str(off_M) + str(on_H) + "." + str(on_M)
    seg.text = disp_times

    #Set relay schedules
    schedule.every().day.at(off_str).do(switch_off,
                                        off_at=off_str).tag('relays')
    schedule.every().day.at(on_str).do(switch_on, on_at=on_str).tag('relays')
    theLog = 'Times updated. Switch on at: ' + on_str + ' Switch off at: ' + off_str
    logging.info(theLog)
Esempio n. 12
0
def show_message_vp(device, msg, delay=0.1):
    # Implemented with virtual viewport
    width = device.width
    padding = " " * width
    msg = padding + msg + padding
    n = len(msg)

    virtual = viewport(device, width=n, height=8)
    sevensegment(virtual).text = msg
    for i in reversed(list(range(n - width))):
        virtual.set_position((i, 0))
        time.sleep(delay)
Esempio n. 13
0
def test_display():
    device = ht1621(gpio)
    gpio.reset_mock()

    sevensegment(device).text = "HELLO"

    assert gpio.get_data() == [
        gpio.data(0), gpio.data(0), gpio.data(0),     # _ _ _
        gpio.data(0), gpio.data(0), gpio.data(0),     # _ _ _
        gpio.data(0), gpio.data(125), gpio.data(13),  # _ O L
        gpio.data(13), gpio.data(31), gpio.data(103)  # L E H
    ]
Esempio n. 14
0
    def __init__(self, c=1, p=0, d=0):
        """
        Constructor de la clase para crear un nuevo objeto display de 7
        segmentos con métodos fácilmente accesibles y opcionales.
        :param c: Cantidad de dispositivos en cascada.
        :param p: Puerto del dispositivo.
        :param d: Dispositivo.
        """
        self.cascaded = c  # Cantidad de dispositivos en cascada

        self.serial = spi(port=p, device=d, gpio=noop())
        self.device = max7219(self.serial, cascaded=c)
        self.seg = sevensegment(self.device)
Esempio n. 15
0
    def __init__(self, mvg_pars, port=0, device=0, cascaded=1, screen_timeout=None, update_interval=30):

        if screen_timeout > 0:
            self.screen_timeout = screen_timeout
        else:
            screen_timeout = None

        # create seven segment device
        self.serial = spi(port=port, device=device, gpio=noop())
        self.device = max7219(self.serial, cascaded=cascaded)
        self.seg = sevensegment(self.device)

        super(EightDigSevSeg, self).__init__(mvg_pars=mvg_pars, update_interval=update_interval)
Esempio n. 16
0
def show_message_vp(request, msg):
    device = request.app['device']
    delay = request.app['delay']
    # Implemented with virtual viewport
    width = device.width
    padding = " " * width
    msg = padding + msg + padding
    n = len(msg)

    virtual = viewport(device, width=n, height=8)
    sevensegment(virtual).text = msg
    for i in reversed(list(range(n - width))):
        virtual.set_position((i, 0))
        time.sleep(delay)
Esempio n. 17
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)
    #orig_demo(serial, device, seg)
    #clock(seg, seconds=10)
    #show_message_vp(device, "you are the best Mr. Shivakumar", 0.5)
    while (True):
        try:
            ip(device)
        except:
            show_message_vp(device, "No IP found yet")
        time.sleep(2)
Esempio n. 18
0
def main():
    # create seven segment device
    device = get_device()

    if not hasattr(device, 'segment_mapper'):
        sys.exit('sevensegment is not supported on a {} device'.format(
            device.__class__.__name__))

    seg = sevensegment(device)

    print('Simple text...')
    for _ in range(8):
        seg.text = "HELLO"
        time.sleep(0.6)
        seg.text = " GOODBYE"
        time.sleep(0.6)

    # Digit slicing
    print("Digit slicing")
    seg.text = "_" * seg.device.width
    time.sleep(1.0)

    for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]):
        seg.text[i] = str(ch)
        time.sleep(0.6)

    for i in range(len(seg.text)):
        del seg.text[0]
        time.sleep(0.6)

    # Scrolling Alphabet Text
    print('Scrolling alphabet text...')
    show_message_vp(device, "HELLO EVERYONE!")
    show_message_vp(device, "PI is 3.14159 ... ")
    show_message_vp(device, "IP is 127.0.0.1 ... ")
    show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ")

    # Digit futzing
    date(seg)
    time.sleep(5)
    clock(seg, seconds=10)

    # Brightness
    print('Brightness...')
    for x in range(5):
        for intensity in range(16):
            seg.device.contrast(intensity * 16)
            time.sleep(0.1)
    device.contrast(0x7F)
Esempio n. 19
0
def initialize_game():

    print("Starting game initialization...")

    #GPIO Setwarning/Setmode
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)  #BCM = GPIO-Nummern

    # init seven segment displays
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=8)  #cascaded entspricht der Anzahl der Anzeigen
    seg = sevensegment(device)
    seg.text = "                                                                "
    device.contrast(255)

    players = []

    for player in PLAYERS:
        players.append(
            Player(
                player['number'],
                ArcadeButton(player['arcade']['led'],
                             player['arcade']['button']),
                Display(seg, player['display']['start'],
                        player['display']['end']), Score(0, 0)))

    big_button = ArcadeButton(BIG_BUTTON['led'], BIG_BUTTON['button'])

    global game_table
    game_table = GameTable(players, big_button, seg)

    GPIO.add_event_detect(big_button.button,
                          GPIO.FALLING,
                          callback=big_button_callback,
                          bouncetime=400)

    for player in players:
        GPIO.add_event_detect(
            player.arcade_button.button,
            GPIO.FALLING,
            callback=lambda x: player_button_callback(
                x,
                game_table.get_player_by_gpio(x).get_number()),
            bouncetime=200)

    print("Finished game initialization. \nReady to play!")
    print("Game state:", GAME_STATE.PLAYER_SELECTION.name)
Esempio n. 20
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)

    print('Simple text...')
    for _ in range(8):
        seg.text = "HELLO"
        time.sleep(0.6)
        seg.text = " GOODBYE"
        time.sleep(0.6)

    # Digit slicing
    print("Digit slicing")
    seg.text = "_" * seg.device.width
    time.sleep(1.0)

    for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]):
        seg.text[i] = str(ch)
        time.sleep(0.6)

    for i in range(len(seg.text)):
        del seg.text[0]
        time.sleep(0.6)

    # Scrolling Alphabet Text
    print('Scrolling alphabet text...')
    show_message_vp(device, "HELLO EVERYONE!")
    show_message_vp(device, "PI is 3.14159 ... ")
    show_message_vp(device, "IP is 127.0.0.1 ... ")
    show_message_alt(
        seg,
        "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ")

    # Digit futzing
    date(seg)
    time.sleep(5)
    clock(seg, seconds=10)

    # Brightness
    print('Brightness...')
    for x in range(5):
        for intensity in range(16):
            seg.device.contrast(intensity * 16)
            time.sleep(0.1)
    device.contrast(0x7F)
Esempio n. 21
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)

    print('Simple text...')
    for _ in range(8):
        seg.text = "HELLO"
        time.sleep(0.6)
        seg.text = " GOODBYE"
        time.sleep(0.6)

    # Digit slicing
    print("Digit slicing")
    seg.text = "_" * seg.device.width
    time.sleep(1.0)

    for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]):
        seg.text[i] = str(ch)
        time.sleep(0.6)

    for i in range(len(seg.text)):
        del seg.text[0]
        time.sleep(0.6)

    # Scrolling Alphabet Text
    print('Scrolling alphabet text...')
    show_message_vp(device, "HELLO EVERYONE!")
    show_message_vp(device, "PI is 3.14159 ... ")
    show_message_vp(device, "IP is 127.0.0.1 ... ")
    show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ")

    # Digit futzing
    date(seg)
    time.sleep(5)
    clock(seg, seconds=10)

    # Brightness
    print('Brightness...')
    for x in range(5):
        for intensity in range(16):
            seg.device.contrast(intensity * 16)
            time.sleep(0.1)
    device.contrast(0x7F)
Esempio n. 22
0
File: tfl.py Progetto: cp2423/tfl
def main():
    try:
        logging.basicConfig(
            filename="log_tfl.txt",
            format="%(asctime)s %(levelname)s %(name)s: %(message)s",
            level=logging.DEBUG)
        serial = spi(port=0, device=0, gpio=noop())
        device = max7219(serial, cascaded=1)
        seg = sevensegment(device)
        pir = MotionSensor(PIR_GPIO)
        daemon_thread = threading.Thread(target=daemon, args=(
            seg,
            pir,
        ))
        #daemon_thread.setDaemon(True)
        logging.debug("Starting daemon")
        daemon_thread.start()
        download(0)
    except Exception as ex:
        logging.exception(ex)
        raise
Esempio n. 23
0
    def mostrarMensajeFlotante(self, txt, delay=1):
        """
        Muestra un mensaje como animación recorriendo la pantalla de forma que
        entra por la derecha y sale por la izquierda, útil cuando no cabe al
        completo el texto por ser un mensaje largo conviertiéndolo previamente
        a mayúsculas.
        :param txt: Texto a mostrar por la pantalla
        :param delay: Tiempo entre carácteres para desplazar el mensaje
        """
        width = self.device.width
        padding = " " * width
        txt = padding + txt.upper() + padding
        n = len(txt)

        print("Mostrando mensaje:\n"+txt)

        virtual = viewport(self.device, width=n, height=8)
        sevensegment(virtual).text = txt
        for i in reversed(list(range(n - width))):
            virtual.set_position((i, 0))
            sleep(delay)
Esempio n. 24
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)

    text = ""
    tries = 0

    while True:
        #f = open("text.txt","r")
        #contents = f.read()

        try:
            text = urllib2.urlopen('http://localhost:3000/api/segments').read()
        except urllib2.URLError as e:
            tries = tries + 1
            if tries > 2:
                print("Python exiting")
                sys.exit()

        seg.text = text
        time.sleep(0.5)
Esempio n. 25
0
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.core.virtual import sevensegment
from luma.led_matrix.device import max7219

serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=2)
seg = sevensegment(device)
seg.text = "Hello world"

 def __init__(self):
     # create seven segment device
     serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219(serial, cascaded=1)
     self.seg = sevensegment(self.device)
Esempio n. 27
0
def setup(app):  # create the display device and store it
    app['serial'] = spi(port=0, device=0, gpio=noop())
    app['device'] = max7219(app['serial'], cascaded=1)
    app['seg'] = sevensegment(app['device'])
    app['delay'] = 0.15
Esempio n. 28
0
import time
import datetime
import logging

from luma.core.interface.serial import spi, noop
from luma.core.virtual import sevensegment
from luma.led_matrix.device import max7219

from utils import prepare_time_for_display, prepare_date_for_display

logging.basicConfig(filename='smartwatch.log', filemode='w+')

serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial, cascaded=1)
display = sevensegment(device)
logging.info('Started app')

while True:
    try:
        for cycle in range(10):
            for second in range(30):
                current_time = datetime.datetime.now()
                statement = prepare_time_for_display(current_time.hour, current_time.minute, current_time.second)
                display.text = statement
                time.sleep(1)
            current_date = datetime.datetime.now()
            statement = prepare_date_for_display(current_date.day, current_date.month, current_date.year)
            display.text = str(statement)
            time.sleep(10)
    except Exception as e:
        logging.critical('Critical exception: {}'.format(e.message))
Esempio n. 29
0
def main(temp, hum):
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)
    seg.text = numbers_to_string(temp, hum)
Esempio n. 30
0
 def __init__ (self, port=0, device=0 ): 
     self.serial = spi(port=port, device=device, gpio=noop())
     self.device = max7219(self.serial, cascaded=1)
     self.seg = sevensegment(self.device)
Esempio n. 31
0
 def __init__(self):
     serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219_backend(serial, cascaded=1)
     self.seg = sevensegment(self.device)
Esempio n. 32
0
def test_init():
    device = dummy(width=24, height=8, mode="1")
    sevensegment(device, segment_mapper=dot_muncher)
    assert device.image == Image.new("1", (24, 8))