Esempio n. 1
0
def test_command():
    cmds = [3, 1, 4, 2]
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.command(*cmds)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.LOW)])
    spidev.writebytes.assert_called_once_with(cmds)
Esempio n. 2
0
def test_data():
    data = list(fib(100))
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.data(data)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.HIGH)])
    spidev.writebytes.assert_called_once_with(data)
Esempio n. 3
0
def test_init_84x48():
    pcd8544(serial, gpio=Mock())
    serial.command.assert_has_calls(
        [call(33, 20, 176, 32),
         call(32, 128, 64), call(12)])

    # Next 1024 are all data: zero's to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_called_once_with([0] * (84 * 48 // 8))
Esempio n. 4
0
def test_init_84x48():
    pcd8544(serial)
    serial.command.assert_has_calls([
        call(33, 20, 176, 32),
        call(32, 128, 64),
        call(12)
    ])

    # Next 1024 are all data: zero's to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_called_once_with([0] * (84 * 48 // 8))
Esempio n. 5
0
def verify_gpio_cs_spi_init(port,
                            device,
                            bus_speed_hz=8000000,
                            dc=24,
                            rst=25,
                            cs=23):
    spidev.open.assert_called_once_with(port, device)
    assert spidev.max_speed_hz == bus_speed_hz
    gpio.setmode.assert_not_called()
    gpio.setup.assert_has_calls([
        call(dc, gpio.OUT),
        call(rst, gpio.OUT),
        call(cs, gpio.OUT, initial=gpio.HIGH)
    ])
Esempio n. 6
0
def test_init():
    port = 5
    device = 2
    bus_speed = 16000000
    dc = 17
    rst = 11

    spi(gpio=gpio, spi=spidev, port=port, device=device, bus_speed_hz=16000000,
        gpio_DC=dc, gpio_RST=rst)
    verify_spi_init(port, device, bus_speed, dc, rst)
    gpio.output.assert_has_calls([
        call(rst, gpio.LOW),
        call(rst, gpio.HIGH)
    ])
Esempio n. 7
0
def test_clear():
    device = neopixel(ws)
    ws.reset_mock()
    device.clear()
    ws.ws2811_led_set.assert_has_calls(
        [call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
Esempio n. 8
0
def test_init_256x64():
    """
    SSD1362 OLED with a 256 x 64 resolution works correctly.
    """
    ssd1362(serial)
    serial.command.assert_has_calls([
        call(171, 1, 173, 158, 21, 0, 127, 117, 0, 63, 160, 67, 161, 0, 162, 0,
             164, 168, 63, 177, 17, 179, 240, 185, 188, 4, 190, 5),
        call(129, 127),
        call(21, 0, 127, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (256 * 64 // 2))
Esempio n. 9
0
def test_clear():
    device = neopixel(ws)
    ws.reset_mock()
    device.clear()
    ws.ws2811_led_set.assert_has_calls([
        call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
Esempio n. 10
0
def test_init_128x64():
    st7567(serial)
    serial.command.assert_has_calls([
        call(0xA3),
        call(0xA1),
        call(0xC0),
        call(0xA6),
        call(0x40),
        call(0x2F),
        call(0x22),
        call(0xAF),
        call(0x81, 57)
    ])

    # Next 1024 are all data: zeros to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_has_calls([call([0] * 128)] * 8)
Esempio n. 11
0
def test_command(mock_controller):
    cmds = [3, 1, 4, 2]
    gpio = Mock()
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    instance.get_gpio = Mock(return_value=gpio)
    mock_controller.side_effect = [instance]

    serial = ftdi_spi(device='ftdi://dummy',
                      bus_speed_hz=16000000,
                      gpio_CS=3,
                      gpio_DC=5,
                      gpio_RST=6)
    serial.command(*cmds)
    gpio.write.assert_has_calls([call(0x00), call(0x40), call(0x40)])
    port.write.assert_called_once_with(cmds)
Esempio n. 12
0
def test_init_128x64():
    st7567(serial)
    serial.command.assert_has_calls([
        call(0xA3),
        call(0xA1),
        call(0xC0),
        call(0xA6),
        call(0x40),
        call(0x2F),
        call(0x22),
        call(0xAF),
        call(0x81, 57)
    ])

    # Next 1024 are all data: zeros to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_has_calls([call([0] * 128)] * 8)
Esempio n. 13
0
def test_init_128x64():
    """
    SSD1325 OLED with a 128 x 64 resolution works correctly.
    """
    ssd1325(serial)
    serial.command.assert_has_calls([
        call(174, 179, 242, 168, 63, 162, 76, 161, 0, 173, 2, 160, 80, 134, 184,
             1, 17, 34, 50, 67, 84, 101, 118, 178, 81, 177, 85, 180, 3, 176, 40,
             188, 1, 190, 0, 191, 2, 164),
        call(129, 127),
        call(21, 0, 63, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (128 * 64 // 2))
Esempio n. 14
0
def test_init_128x128():
    """
    SSD1327 OLED with a 128 x 128 resolution works correctly.
    """
    ssd1327(serial)
    serial.command.assert_has_calls([
        call(174, 160, 83, 161, 0, 162, 0, 164, 168, 127, 184, 1, 17, 34, 50,
             67, 84, 101, 118, 179, 0, 171, 1, 177, 241, 188, 8, 190, 7, 213,
             98, 182, 15),
        call(129, 127),
        call(21, 0, 127, 117, 0, 127),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 128 / 2)
    serial.data.assert_called_once_with([0] * (128 * 128 // 2))
Esempio n. 15
0
def test_data(mock_controller):
    data = list(fib(100))
    gpio = Mock()
    port = Mock()
    instance = Mock()
    instance.get_port = Mock(return_value=port)
    instance.get_gpio = Mock(return_value=gpio)
    mock_controller.side_effect = [instance]

    serial = ftdi_spi(device='ftdi://dummy',
                      bus_speed_hz=16000000,
                      gpio_CS=3,
                      gpio_DC=5,
                      gpio_RST=6)
    serial.data(data)
    gpio.write.assert_has_calls([call(0x00), call(0x40), call(0x60)])
    port.write.assert_called_once_with(data)
Esempio n. 16
0
def test_init_128x64():
    """
    SSD1325 OLED with a 128 x 64 resolution works correctly.
    """
    ssd1325(serial)
    serial.command.assert_has_calls([
        call(174, 179, 242, 168, 63, 162, 76, 161, 0, 173, 2, 160, 80, 134,
             184, 1, 17, 34, 50, 67, 84, 101, 118, 178, 81, 177, 85, 180, 3,
             176, 40, 188, 1, 190, 0, 191, 2, 164),
        call(129, 127),
        call(21, 0, 63, 117, 0, 63),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 64 / 2)
    serial.data.assert_called_once_with([0] * (128 * 64 // 2))
Esempio n. 17
0
def test_cleanup():
    device = neopixel(ws)
    device.cleanup()
    ws.ws2811_led_set.assert_has_calls([
        call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
    assert ws.ws2811_fini.called
    assert ws.delete_ws2811_t.called
    assert device._leds is None
    assert device._channel is None
Esempio n. 18
0
def test_cleanup():
    device = neopixel(ws)
    device.cleanup()
    ws.ws2811_led_set.assert_has_calls(
        [call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
    assert ws.ws2811_fini.called
    assert ws.delete_ws2811_t.called
    assert device._leds is None
    assert device._channel is None
Esempio n. 19
0
def test_init_64x32():
    """
    SSD1306 OLED with a 64 x 32 resolution works correctly.
    """
    ssd1306(serial, width=64, height=32)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 213, 128, 168, 31, 211, 0, 64, 141, 20, 32, 0, 161, 200, 218,
             18, 217, 241, 219, 64, 164, 166),
        # set contrast
        call(129, 207),
        # reset the display
        call(33, 32, 95, 34, 0, 3),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next bytes are all data: zero's to clear the RAM
    serial.data.assert_called_once_with([0] * (64 * 32 // 8))
Esempio n. 20
0
def test_init_128x64():
    """
    SSD1309 OLED with a 128 x 64 resolution works correctly.
    """
    ssd1309(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 213, 128, 168, 63, 211, 0, 64, 141, 20, 32, 0,
             161, 200, 218, 18, 217, 241, 219, 64, 164, 166),
        # set contrast
        call(129, 207),
        # reset the display
        call(33, 0, 127, 34, 0, 7),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next are all data: zero's to clear the RAM
    serial.data.assert_called_once_with([0] * (128 * 64 // 8))
Esempio n. 21
0
def test_init_params_deprecated():
    port = 5
    device = 2
    bus_speed = 16000000
    dc = 80
    rst = 90
    msg1 = 'bcm_DC argument is deprecated in favor of gpio_DC and will be removed in 1.0.0'
    msg2 = 'bcm_RST argument is deprecated in favor of gpio_RST and will be removed in 1.0.0'

    with pytest.deprecated_call() as c:
        spi(gpio=gpio, spi=spidev, port=port, device=device,
            bus_speed_hz=bus_speed, bcm_DC=dc, bcm_RST=rst)
        verify_spi_init(port, device, bus_speed, dc, rst)
        gpio.output.assert_has_calls([
            call(rst, gpio.LOW),
            call(rst, gpio.HIGH)
        ])
        assert str(c.list[0].message) == msg1
        assert str(c.list[1].message) == msg2
Esempio n. 22
0
def main():
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--kill-dir', metavar='DIR', help='kill all scripts in the directory')
    args = parser.parse_args()

    # kill mahimahi shells and iperf
    pkill = 'pkill -f '
    pkill_cmds = [pkill + 'mm-delay', pkill + 'mm-link', pkill + 'mm-loss',
                  pkill + 'mm-tunnelclient', pkill + 'mm-tunnelserver',
                  pkill + '-SIGKILL iperf']

    if args.kill_dir:
        pkill_cmds.append(pkill + args.kill_dir)

    for cmd in pkill_cmds:
        call(cmd, shell=True)
Esempio n. 23
0
def test_init_96x16():
    """
    SSD1306 OLED with a 96 x 16 resolution works correctly.
    """
    ssd1306(serial, width=96, height=16)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 213, 96, 168, 15, 211, 0, 64, 141, 20, 32, 0, 161, 200, 218,
             2, 217, 241, 219, 64, 164, 166),
        # set contrast
        call(129, 207),
        # reset the display
        call(33, 16, 111, 34, 0, 1),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next 192 are all data: zero's to clear the RAM
    # (192 = 96 * 16 / 8)
    serial.data.assert_called_once_with([0] * (96 * 16 // 8))
Esempio n. 24
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('yaml_settings')
    args = parser.parse_args()

    with open(args.yaml_settings, 'r') as fh:
        yaml_settings = yaml.safe_load(fh)

    # the script is preferred to be run after 'backup_hour' AM (UTC)
    ts = datetime.utcnow()
    end_ts = datetime(ts.year, ts.month, ts.day, backup_hour, 0)

    # in case this script is executed before 'backup_hour' AM (UTC)
    if ts.hour < backup_hour:
        sys.stderr.write(
            'Warning: sleeping until {} AM (UTC) is passed\n'.format(
                backup_hour))
        time.sleep(math.ceil((end_ts - ts).total_seconds()))

    # back up the data collected in the last 24 hours
    start_ts = end_ts - timedelta(days=1)

    # convert datetime to time strings
    time_str = '%Y-%m-%dT%H:%M:%SZ'
    short_time_str = '%Y-%m-%dT%H'

    end_ts_str = end_ts.strftime(time_str)
    start_ts_str = start_ts.strftime(time_str)

    dst_dir = start_ts.strftime(short_time_str) + '_' + end_ts.strftime(
        short_time_str)

    # back up InfluxDB
    influx = yaml_settings['influxdb_connection']
    cmd = ('influxd backup -portable -database {} -start {} -end {} {}'.format(
        influx['dbname'], start_ts_str, end_ts_str, dst_dir))
    check_call(cmd, shell=True)

    # compress dst_dir
    cmd = 'tar czvf {0}.tar.gz {0}'.format(dst_dir)
    check_call(cmd, shell=True)

    # upload to Google cloud
    cmd = 'gsutil cp {}.tar.gz gs://puffer-influxdb-analytics'.format(dst_dir)
    check_call(cmd, shell=True)

    # remove files
    cmd = 'rm -rf {0} {0}.tar.gz'.format(dst_dir)
    check_call(cmd, shell=True)

    # read from YAML the path to Emily's program and run it
    retcode = call(yaml_settings['data_release_script'], shell=True)
    post_to_zulip(retcode, dst_dir)
Esempio n. 25
0
def test_init_96x64():
    """
    SSD1331 OLED with a 96 x 64 resolution works correctly.
    """
    ssd1331(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 160, 114, 161, 0, 162, 0, 164, 168, 63, 173, 142, 176, 11,
             177, 116, 179, 208, 138, 128, 139, 128, 140, 128, 187, 62, 190,
             62, 135, 15),
        # set contrast
        call(129, 255, 130, 255, 131, 255),
        # reset the display
        call(21, 0, 95, 117, 0, 63),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next 12288 are all data: zero's to clear the RAM
    # (12288 = 96 * 64 * 2)
    serial.data.assert_called_once_with([0] * 96 * 64 * 2)
Esempio n. 26
0
def test_init_96x64():
    """
    SSD1331 OLED with a 96 x 64 resolution works correctly.
    """
    ssd1331(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 160, 114, 161, 0, 162, 0, 164, 168, 63, 173,
             142, 176, 11, 177, 116, 179, 208, 138, 128, 139,
             128, 140, 128, 187, 62, 190, 62, 135, 15),
        # set contrast
        call(129, 255, 130, 255, 131, 255),
        # reset the display
        call(21, 0, 95, 117, 0, 63),
        # called last, is a command to show the screen
        call(175)
    ])

    # Next 12288 are all data: zero's to clear the RAM
    # (12288 = 96 * 64 * 2)
    serial.data.assert_called_once_with([0] * 96 * 64 * 2)
Esempio n. 27
0
def test_mapping():
    num_pixels = 16
    device = neopixel(ws, cascaded=num_pixels, mapping=reversed(list(range(num_pixels))))
    ws.reset_mock()

    with canvas(device) as draw:
        for i in range(device.cascaded):
            draw.point((i, 0), (i, 0, 0))

    expected = [call(chan, num_pixels - i - 1, i << 16) for i in range(num_pixels)]
    ws.ws2811_led_set.assert_has_calls(expected)

    assert ws.ws2811_render.called
Esempio n. 28
0
def test_init_4x8():
    device = neopixel(ws)
    assert device.cascaded == 32
    assert ws.ws2811_channel_t_count_set.called
    assert ws.ws2811_channel_t_gpionum_set.called
    assert ws.ws2811_channel_t_invert_set.called
    assert ws.ws2811_channel_t_brightness_set.called
    assert ws.ws2811_channel_t_strip_type_set.called
    assert ws.ws2811_t_freq_set.called
    assert ws.ws2811_t_dmanum_set.called
    assert ws.ws2811_init.called
    ws.ws2811_led_set.assert_has_calls(
        [call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
Esempio n. 29
0
def main():
    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    parser = argparse.ArgumentParser()
    parser.add_argument('--kill-dir',
                        metavar='DIR',
                        help='kill all scripts in the directory')
    args = parser.parse_args()

    # kill mahimahi shells and iperf
    pkill = 'pkill -f '
    pkill_cmds = [
        pkill + 'mm-delay', pkill + 'mm-link', pkill + 'mm-loss',
        pkill + 'mm-tunnelclient', pkill + 'mm-tunnelserver',
        pkill + '-SIGKILL iperf'
    ]

    if args.kill_dir:
        pkill_cmds.append(pkill + args.kill_dir)

    for cmd in pkill_cmds:
        call(cmd, shell=True)
Esempio n. 30
0
def test_init_4x8():
    device = neopixel(ws)
    assert device.cascaded == 32
    assert ws.ws2811_channel_t_count_set.called
    assert ws.ws2811_channel_t_gpionum_set.called
    assert ws.ws2811_channel_t_invert_set.called
    assert ws.ws2811_channel_t_brightness_set.called
    assert ws.ws2811_channel_t_strip_type_set.called
    assert ws.ws2811_t_freq_set.called
    assert ws.ws2811_t_dmanum_set.called
    assert ws.ws2811_init.called
    ws.ws2811_led_set.assert_has_calls([
        call(chan, i, 0x000000) for i in range(32)])
    assert ws.ws2811_render.called
Esempio n. 31
0
def test_display_16x8():
    device = max7219(serial, cascaded=2)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x81, 1, 0xFF]),
        call([2, 0x81, 2, 0x81]),
        call([3, 0x81, 3, 0x81]),
        call([4, 0x81, 4, 0x81]),
        call([5, 0x81, 5, 0x81]),
        call([6, 0x81, 6, 0x81]),
        call([7, 0x81, 7, 0x81]),
        call([8, 0xFF, 8, 0x81])
    ])
Esempio n. 32
0
def test_block_realignment_plus180():
    device = max7219(serial, cascaded=2, block_orientation=180)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0xF0, 1, 0x90]),
        call([2, 0x90, 2, 0x90]),
        call([3, 0x90, 3, 0x90]),
        call([4, 0x90, 4, 0x90]),
        call([5, 0x90, 5, 0x90]),
        call([6, 0x90, 6, 0x90]),
        call([7, 0x90, 7, 0x90]),
        call([8, 0x90, 8, 0xF0])
    ])
Esempio n. 33
0
def test_normal_alignment():
    device = max7219(serial, cascaded=2, block_orientation=0)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0x09, 1, 0x0F]),
        call([2, 0x09, 2, 0x09]),
        call([3, 0x09, 3, 0x09]),
        call([4, 0x09, 4, 0x09]),
        call([5, 0x09, 5, 0x09]),
        call([6, 0x09, 6, 0x09]),
        call([7, 0x09, 7, 0x09]),
        call([8, 0x0F, 8, 0x09])
    ])
Esempio n. 34
0
def test_display_16x16():
    device = max7219(serial, width=16, height=16)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]),
        call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]),
        call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]),
        call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]),
        call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]),
        call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]),
        call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]),
        call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01])
    ])
Esempio n. 35
0
def test_display_16x16():
    device = max7219(serial, width=16, height=16)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x80, 1, 0xFF, 1, 0x01, 1, 0xFF]),
        call([2, 0x80, 2, 0x80, 2, 0x01, 2, 0x01]),
        call([3, 0x80, 3, 0x80, 3, 0x01, 3, 0x01]),
        call([4, 0x80, 4, 0x80, 4, 0x01, 4, 0x01]),
        call([5, 0x80, 5, 0x80, 5, 0x01, 5, 0x01]),
        call([6, 0x80, 6, 0x80, 6, 0x01, 6, 0x01]),
        call([7, 0x80, 7, 0x80, 7, 0x01, 7, 0x01]),
        call([8, 0xFF, 8, 0x80, 8, 0xFF, 8, 0x01])
    ])
Esempio n. 36
0
def test_normal_alignment():
    device = max7219(serial, cascaded=2, block_orientation=0)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0x09, 1, 0x0F]),
        call([2, 0x09, 2, 0x09]),
        call([3, 0x09, 3, 0x09]),
        call([4, 0x09, 4, 0x09]),
        call([5, 0x09, 5, 0x09]),
        call([6, 0x09, 6, 0x09]),
        call([7, 0x09, 7, 0x09]),
        call([8, 0x0F, 8, 0x09])
    ])
Esempio n. 37
0
def test_block_realignment_plus180():
    device = max7219(serial, cascaded=2, block_orientation=180)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 0xF0, 1, 0x90]),
        call([2, 0x90, 2, 0x90]),
        call([3, 0x90, 3, 0x90]),
        call([4, 0x90, 4, 0x90]),
        call([5, 0x90, 5, 0x90]),
        call([6, 0x90, 6, 0x90]),
        call([7, 0x90, 7, 0x90]),
        call([8, 0x90, 8, 0xF0])
    ])
def test_reversed_max7219():
    device = max7219(serial, cascaded=4, blocks_arranged_in_reverse_order=True)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle((0, 0, 15, 3), outline="white")

    serial.data.assert_has_calls([
        call([1, 15, 1, 9, 1, 0, 1, 0]),
        call([2, 9, 2, 9, 2, 0, 2, 0]),
        call([3, 9, 3, 9, 3, 0, 3, 0]),
        call([4, 9, 4, 9, 4, 0, 4, 0]),
        call([5, 9, 5, 9, 5, 0, 5, 0]),
        call([6, 9, 6, 9, 6, 0, 6, 0]),
        call([7, 9, 7, 9, 7, 0, 7, 0]),
        call([8, 9, 8, 15, 8, 0, 8, 0])
    ])
Esempio n. 39
0
def test_display_16x8():
    device = max7219(serial, cascaded=2)
    serial.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")

    serial.data.assert_has_calls([
        call([1, 0x81, 1, 0xFF]),
        call([2, 0x81, 2, 0x81]),
        call([3, 0x81, 3, 0x81]),
        call([4, 0x81, 4, 0x81]),
        call([5, 0x81, 5, 0x81]),
        call([6, 0x81, 6, 0x81]),
        call([7, 0x81, 7, 0x81]),
        call([8, 0xFF, 8, 0x81])
    ])
Esempio n. 40
0
def test_init_cascaded():
    device = neopixel(ws, cascaded=7)
    assert device.width == 7
    assert device.height == 1
    assert ws.ws2811_channel_t_count_set.called
    assert ws.ws2811_channel_t_gpionum_set.called
    assert ws.ws2811_channel_t_invert_set.called
    assert ws.ws2811_channel_t_brightness_set.called
    assert ws.ws2811_channel_t_strip_type_set.called
    assert ws.ws2811_t_freq_set.called
    assert ws.ws2811_t_dmanum_set.called
    assert ws.ws2811_init.called
    ws.ws2811_led_set.assert_has_calls([
        call(chan, i, 0x000000) for i in range(7)])
    assert ws.ws2811_render.called
Esempio n. 41
0
def test_mapping():
    num_pixels = 16
    device = neopixel(ws2812,
                      cascaded=num_pixels,
                      mapping=reversed(list(range(num_pixels))))
    ws2812.reset_mock()

    with canvas(device) as draw:
        for i in range(device.cascaded):
            draw.point((i, 0), (i, 0, 0))

    expected = [call(num_pixels - i - 1, i, 0, 0) for i in range(num_pixels)]
    ws2812.setPixelColor.assert_has_calls(expected)

    assert ws2812.show.called
Esempio n. 42
0
def test_init_cascaded():
    device = neopixel(ws, cascaded=7)
    assert device.width == 7
    assert device.height == 1
    assert ws.ws2811_channel_t_count_set.called
    assert ws.ws2811_channel_t_gpionum_set.called
    assert ws.ws2811_channel_t_invert_set.called
    assert ws.ws2811_channel_t_brightness_set.called
    assert ws.ws2811_channel_t_strip_type_set.called
    assert ws.ws2811_t_freq_set.called
    assert ws.ws2811_t_dmanum_set.called
    assert ws.ws2811_init.called
    ws.ws2811_led_set.assert_has_calls(
        [call(chan, i, 0x000000) for i in range(7)])
    assert ws.ws2811_render.called
Esempio n. 43
0
def test_mapping():
    num_pixels = 16
    device = neopixel(ws,
                      cascaded=num_pixels,
                      mapping=reversed(list(range(num_pixels))))
    ws.reset_mock()

    with canvas(device) as draw:
        for i in range(device.cascaded):
            draw.point((i, 0), (i, 0, 0))

    expected = [
        call(chan, num_pixels - i - 1, i << 16) for i in range(num_pixels)
    ]
    ws.ws2811_led_set.assert_has_calls(expected)

    assert ws.ws2811_render.called
Esempio n. 44
0
def test_init_128x128():
    """
    SSD1327 OLED with a 128 x 128 resolution works correctly.
    """
    ssd1327(serial)
    serial.command.assert_has_calls([
        call(174, 160, 83, 161, 0, 162, 0, 164, 168, 127),
        call(184, 1, 17, 34, 50, 67, 84, 101, 118),
        call(179, 0, 171, 1, 177, 241, 188, 8, 190, 7, 213, 98, 182, 15),
        call(129, 127),
        call(21, 0, 63, 117, 0, 127),
        call(175)
    ])

    # Next 4096 are all data: zero's to clear the RAM
    # (4096 = 128 * 128 / 2)
    serial.data.assert_called_once_with([0] * (128 * 128 // 2))
Esempio n. 45
0
def test_data():
    data = (0xFF, 0x0F, 0x00)
    serial = bitbang(gpio=gpio, SCLK=13, SDA=14, CE=15, DC=16, RST=17)
    serial.data(data)

    reset = [call(17, gpio.LOW), call(17, gpio.HIGH)]
    clock = [call(13, gpio.HIGH), call(13, gpio.LOW)]
    data = lambda x: call(14, 0x80 if x == gpio.HIGH else 0x00)
    ce = lambda x: [call(15, x)]
    dc = lambda x: [call(16, x)]

    calls = reset + \
        dc(gpio.HIGH) + \
        ce(gpio.LOW) + \
        (([data(gpio.HIGH)] + clock) * 8) + \
        (([data(gpio.LOW)] + clock) * 4) + \
        (([data(gpio.HIGH)] + clock) * 4) + \
        (([data(gpio.LOW)] + clock) * 8) + \
        ce(gpio.HIGH)

    gpio.output.assert_has_calls(calls)
Esempio n. 46
0
	log.addHandler(handler)

	log = logging.getLogger(__name__)
	#log.info('set log level to %s (%d)' % (options.loglevel, log.getEffectiveLevel()))

	if not options.file:
		parser.print_help()
		parser.error("Missing topology file")
		
	rpath = options.rpath
	
	try:
	
		if (not options.noupdate) and (not options.noinstall):  # double negative
				if isInstalled('yum'):
						call("yum update")
				elif isInstalled('apt-get'):
						call("apt-get -y update")
				else:
						msg = 'I do not know how to update this system. Platform not supported. Run with --noupdate or on a supported platform (yum or apt-get enabled).'
						log.critical(msg)
						sys.exit(msg)  # write msg and exit with status 1
								
		verifyPythonDevel()
	
		if not options.noinstall:				 
	
			try:
				installPython('PyYAML', 'yaml', 'install', rpath)
			except PBuildException:
				installPython('PyYAML', 'yaml', '--without-libyaml install', rpath)  # try without libyaml if build error
Esempio n. 47
0
def test_init_8x8():
    device = max7219(serial)
    assert device.cascaded == 1
    serial.data.assert_has_calls([
        call([11, 7]),
        call([9, 0]),
        call([15, 0]),
        call([10, 7]),
        call([1, 0]),
        call([2, 0]),
        call([3, 0]),
        call([4, 0]),
        call([5, 0]),
        call([6, 0]),
        call([7, 0]),
        call([8, 0]),
        call([12, 1])
    ])
Esempio n. 48
0
def test_init_16x8():
    device = max7219(serial, width=16, height=8)
    assert device.cascaded == 2
    serial.data.assert_has_calls([
        call([11, 7, 11, 7]),
        call([9, 0, 9, 0]),
        call([15, 0, 15, 0]),
        call([10, 7, 10, 7]),
        call([1, 0, 1, 0]),
        call([2, 0, 2, 0]),
        call([3, 0, 3, 0]),
        call([4, 0, 4, 0]),
        call([5, 0, 5, 0]),
        call([6, 0, 6, 0]),
        call([7, 0, 7, 0]),
        call([8, 0, 8, 0]),
        call([12, 1, 12, 1])
    ])
Esempio n. 49
0
        rpath = options.rpath 
        
        if sys.hexversion < 0x020700F0:
                log.critical("Only works with python 2.7 or greater. Current python version: %s" %(sys.version))
                sys.exit("Only works with python 2.7 or greater. Current python version: %s" %(sys.version))

        MAX_TRIES = 5
        trialItr = 1
        
        while True:
            try:
                
                if (not options.noupdate) and (not options.noinstall):  # double negative
                        if isInstalled('yum'):
                                call("yum update")
                        elif isInstalled('apt-get'):
                                call("apt-get -y update")
                        else:
                                msg = 'I do not know how to update this system. Platform not supported. Run with --noupdate or on a supported platform (yum or apt-get enabled).'
                                log.critical(msg)
                                sys.exit(msg)  # write msg and exit with status 1
                                        
                verifyPythonDevel()
        
                if not options.noinstall:                 
                        try:
                                installC('yaml', '/usr/lib/libyaml.so', rpath)
                                import yaml 
                        except:
                                log.info("unable to install libyaml, will using pure python version: %s", sys.exc_info()[1])
Esempio n. 50
0
def test_init_128x64():
    """
    SH1106 OLED with a 128 x 64 resolution works correctly.
    """
    sh1106(serial)
    serial.command.assert_has_calls([
        # Initial burst are initialization commands
        call(174, 32, 16, 176, 200, 0, 16, 64, 161, 166, 168, 63, 164,
             211, 0, 213, 240, 217, 34, 218, 18, 219, 32, 141, 20),
        # set contrast
        call(129, 127),
        # reset the display
        call(176, 2, 16),
        call(177, 2, 16),
        call(178, 2, 16),
        call(179, 2, 16),
        call(180, 2, 16),
        call(181, 2, 16),
        call(182, 2, 16),
        call(183, 2, 16)
    ])

    # Next 1024 are all data: zero's to clear the RAM
    # (1024 = 128 * 64 / 8)
    serial.data.assert_has_calls([call([0] * 128)] * 8)
Esempio n. 51
0
def test_display():
    device = neopixel(ws, width=4, height=4)
    ws.reset_mock()

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="red")

    ws.ws2811_led_set.assert_has_calls([
        call(chan, 0, 0xFF0000),
        call(chan, 1, 0xFF0000),
        call(chan, 2, 0xFF0000),
        call(chan, 3, 0xFF0000),
        call(chan, 4, 0xFF0000),
        call(chan, 5, 0x000000),
        call(chan, 6, 0x000000),
        call(chan, 7, 0xFF0000),
        call(chan, 8, 0xFF0000),
        call(chan, 9, 0x000000),
        call(chan, 10, 0x000000),
        call(chan, 11, 0xFF0000),
        call(chan, 12, 0xFF0000),
        call(chan, 13, 0xFF0000),
        call(chan, 14, 0xFF0000),
        call(chan, 15, 0xFF0000),
    ])
    assert ws.ws2811_render.called