Using belay in a class
See original GitHub issueI’m now trying to create a class that takes a port as input, creates the Belay.device
in __init__
and has belay-decorated methods. However, I can’t do that currently as the decorator depends on device
. I also tried initiating the device outside the class and using it as an argument, but that doesn’t help either. Any ideas on how to go about this?
import belay
class BelayDevice():
def __init__(self, port, **kwargs):
device = belay.Device(port, 115200) #'/dev/cu.usbmodem141201'
@device.task
def led_loop(self, period):
from neopixel import NeoPixel
np = NeoPixel(Pin(17), 8)
x = 0
state = False
light = (0,0,0)
while x < 6:
# np.value(state)
if state is False:
light = (255, 255, 255)
else:
light = (0,0,0)
np.fill(light)
state = not state
sleep(period)
x += 1
bel = BelayDevice('/dev/tty.SLAB_USBtoUART')
bel.led_loop(1)
# Traceback (most recent call last):
# File "/Users/roaldarbol/Filen/git-projects/belay/mikkel-test.py", line 3, in <module>
# class BelayDevice():
# File "/Users/roaldarbol/Filen/git-projects/belay/mikkel-test.py", line 7, in BelayDevice
# @device.task
# NameError: name 'device' is not defined
For background, I’d like to be able to connect to multiple controllers and run code separately. I’ll use multiprocessing
for that, but I’ve already got that side of things down - I just need a way that I can easily instantiate a class multiple times.
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
How to Belay: Rock Climbing Basics | REI Co-op
Belaying is a foundational skill that climbing classes teach early on and instruction from a qualified teacher is essential. This article covers the...
Read more >Intro to Belay Class - Manhattan - Central Rock Gym
This class typically takes an hour and teaches knots, the belay process, and safety procedures at the gym. This course is required to...
Read more >BASICS OF BELAY CLASS TOP ROPE BELAY SKILLS ... - SMU
This 2-hour class is designed to teach fundamental top rope belay technique to beginners. It includes all skills and knowledge required for the...
Read more >Belay Class - RockSport
Learn to belay so that you and your climbing partner(s) can top-rope climb in our facility without the need of our staff. Once...
Read more >Belay Classes - Outdoor Action - Princeton University
You must take a Belay Class and pass the Belay Test in order to belay at the OA Climbing Wall. Monday from 3:30...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Between #52 and #54 , I’m going to close this issue. #54 will be merged in shortly. If you think something isn’t addressed in these PRs, we can either re-open this issue or create a new one. Thanks!
@roaldarbol See #52, I got it working. See if you like the interface or if you would change anything; please leave feedback in the PR. I still need to write more documentation for it, but see example ~11~ 08.
EDIT: In this PR, the previous method for multiple devices (multiple decorating) has been removed. I think the class approach is much more elegant for the user, and significantly simplifies Belay’s code.