Exemplo n.º 1
0
#! /usr/bin/env python3
 
# PFx Brick example script to demonstrate multiple scripted actions

import hid
import time
import random
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

audiofile = 2
max_speed = 100

# start looped audio playback and set volume
brick.test_action(PFxAction().repeat_audio_file(audiofile))
brick.test_action(PFxAction().set_volume(75))

# ramp up the motor speed gradually to max_speed
for x in range(max_speed):
    brick.test_action(PFxAction().set_motor_speed([1], x))
    # show a random light pattern
    y = random.randint(1,8)
    brick.test_action(PFxAction().light_toggle([y]))
    time.sleep(0.1)

# ramp down the motor speed gradually to 0%

for x in range(max_speed):
Exemplo n.º 2
0
#! /usr/bin/env python3

# PFx Brick example script to show copying a file from the PFx Brick

from sys import argv

import hid

from pfxbrick import PFxBrick

brick = PFxBrick()
brick.open()

if len(argv) < 2:
    print("Usage: ./filecopyfrom.py <id> [filename]")
    print("  where <id> is file ID to copy or a string filename")
    print("  where [filename] optional override filename when copied")
else:
    fn = ""
    fid = int(argv[1])
    brick.refresh_file_dir()
    fid = brick.file_id_from_str_or_int()
    f = brick.filedir.get_file_dir_entry(fid)
    if len(argv) == 3:
        fn = argv[2]
    else:
        fn = f.name
    print("Copying file id %d as %s from brick..." % (fid, fn))
    brick.get_file(fid, fn)

    brick.close()
Exemplo n.º 3
0
#! /usr/bin/env python3

# PFx Brick example script to show PFx Brick file directory

import hid
from pfxbrick import PFxBrick

brick = PFxBrick()
brick.open()
brick.refresh_file_dir()
print(brick.filedir)
brick.close()
Exemplo n.º 4
0
from sys import argv

import hid

from pfxbrick import PFxBrick

if len(argv) < 3:
    print("Usage: ./filecopy.py <filename> [id]")
    print("  where <filename> is the local file to copy")
    print(
        "        <id> is an optional unique file ID to assign the file on the PFx Brick"
    )
    print("             if not specified, it is automatically determined")
else:
    brick = PFxBrick()
    brick.open()

    fn = argv[1]
    if len(argv) > 2:
        fid = int(argv[2])
    else:
        brick.refresh_file_dir()
        fid = brick.filedir.find_available_file_id()
    print("Copying %s to brick with id %d..." % (fn, fid))
    brick.put_file(fid, fn)
    brick.refresh_file_dir()
    print(brick.filedir)

    brick.close()
Exemplo n.º 5
0
#! /usr/bin/env python3

# PFx Brick example script to retrieve basic information about the
# brick including its identity and configuration settings.

import hid

from pfxbrick import PFxBrick, find_bricks

bricks = find_bricks(True)
print("%d PFx Bricks found" % (len(bricks)))

if bricks:
    for b in bricks:
        brick = PFxBrick()
        res = brick.open(b)
        if not res:
            print("Unable to open session to PFx Brick")
        else:
            print("PFx Brick Status / Identity")
            print("===========================")
            print("PFx Brick ICD version : %s" % (brick.get_icd_rev()))
            brick.get_name()
            print("PFx Brick name        : %s" % (brick.name))
            brick.get_status()
            brick.print_status()
            print("PFx Brick Configuration")
            print("=======================")
            brick.get_config()
            brick.print_config()
            brick.close()
Exemplo n.º 6
0
#! /usr/bin/env python3

# PFx Brick example script to showing modification to the
# brick configuration settings.

import hid
from pfxbrick import PFxBrick, find_bricks
from pfxbrick.pfx import *

bricks = find_bricks()
print('%d PFx Bricks found' % (len(bricks)))

if bricks:
    brick = PFxBrick()
    res = brick.open()
    if not res:
        print("Unable to open session to PFx Brick")
    else:
        print('PFx Brick Configuration')
        print('=======================')
        brick.get_config()
        brick.print_config()

        print("Change the volume beep setting...")
        if brick.config.settings.volumeBeep == PFX_CFG_VOLBEEP_ON:
            brick.config.settings.volumeBeep = PFX_CFG_VOLBEEP_OFF
        else:
            brick.config.settings.volumeBeep = PFX_CFG_VOLBEEP_ON
        brick.set_config()

        print('PFx Brick Updated Configuration')
Exemplo n.º 7
0
#! /usr/bin/env python3

# PFx Brick example script to show access to the event/action LUT

import hid
import time
import copy
from pfxbrick import PFxBrick, PFxAction, find_bricks
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

left_button_ch1 = brick.get_action(EVT_ID_8879_LEFT_BUTTON, 0)
print("Get action for Left Button Ch 1 on Speed Remote...")
print(left_button_ch1)

print("Add a light effect to this action...")
new_left_action = copy.copy(left_button_ch1)
new_left_action.light_on([1, 2, 3, 4])
print(new_left_action)

print("Save new action back to brick...")
brick.set_action(EVT_ID_8879_LEFT_BUTTON, 0, new_left_action)
print(brick.get_action(EVT_ID_8879_LEFT_BUTTON, 0))
time.sleep(1)

print("Restore the original action without the change...")
brick.set_action(EVT_ID_8879_LEFT_BUTTON, 0, left_button_ch1)
print(brick.get_action(EVT_ID_8879_LEFT_BUTTON, 0))
Exemplo n.º 8
0
#! /usr/bin/env python3

# PFx Brick example script to retrieve basic information about the
# brick including its identidy and configuration settings.

import hid
import time
from math import sin
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()
print("Set lights 1, 2, 3, 4 ON")
a = PFxAction().light_on([1, 2, 3, 4])
brick.test_action(a)
time.sleep(2)

for x in range(100):
    b = int(sin(6.28 * x * 0.1) * 127 + 128)
    brick.test_action(PFxAction().set_brightness([1, 2, 3, 4], b))
    time.sleep(0.050)

print("Set lights 1, 2, 3, 4 OFF")
a = PFxAction().light_off([1, 2, 3, 4])
brick.test_action(a)
time.sleep(2)

print("Set strobe lights 1, 4 ON")
a = PFxAction().light_fx(
    [1, 4], EVT_LIGHTFX_STROBE_P,
Exemplo n.º 9
0
#! /usr/bin/env python3

# PFx Brick example script to show access to the event/action LUT
# by showing startup events

import hid
import time
import copy
from pfxbrick import PFxBrick, PFxAction, find_bricks
from pfxbrick.pfxhelpers import address_to_evtch
from pfxbrick.pfxdict import evtid_dict
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

events = [
    EVT_STARTUP_EVENT1, EVT_STARTUP_EVENT2, EVT_STARTUP_EVENT3,
    EVT_STARTUP_EVENT4
]
for event in events:
    evt, ch = address_to_evtch(event)
    print("%s %d at LUT address %02X" % (evtid_dict[evt], ch + 1, event))
    print(brick.get_action_by_address(event))
brick.close()
Exemplo n.º 10
0
#! /usr/bin/env python3

# PFx Brick example script to demonstrate motor control

import hid
import time
from pfxbrick import PFxBrick, PFxAction
from pfxbrick.pfx import *

brick = PFxBrick()
brick.open()

print("Motor channel A forward 50% speed")
a = PFxAction().set_motor_speed([1], 50)
brick.test_action(a)
print("Waiting 3 seconds...")
time.sleep(3)

print("Stop motor A")
a = PFxAction().stop_motor([1])
brick.test_action(a)
time.sleep(1)

print("Motor channel A reverse 33% speed for 2 sec self-timed")
a = PFxAction().set_motor_speed([1], -33, 2)
brick.test_action(a)

brick.close()