本文整理汇总了Python中driver.Driver.write_led方法的典型用法代码示例。如果您正苦于以下问题:Python Driver.write_led方法的具体用法?Python Driver.write_led怎么用?Python Driver.write_led使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类driver.Driver
的用法示例。
在下文中一共展示了Driver.write_led方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RemoteDriver
# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import write_led [as 别名]
class RemoteDriver(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(RemoteDriver, cls).__new__(
cls, *args, **kwargs)
return cls._instance
lock = None
def __init__(self, name=None, addr="141.212.110.237", port=4908):
#Driver().
# TOOD: call Driver().gimme_lock_info(self) (and implement it)
pass
def go(self):
pass
# Not called from the user's program, but rather the background process
def set_lock(self, lock, cur_running, my_priority, run_time, off_time):
# Thanks!
self.lock = lock
self.cur_running = cur_running
self.my_priority = my_priority
self.run_time = run_time
self.off_time = off_time
self.next_acquire_time = time.time()
self.have_lock = False
self.driver = Driver()
def write_led(self, led_id, brightness, red, green, blue):
# every once in a while, we should release the lock
if time.time() > self.next_acquire_time:
#if self.have_lock:
# self.lock.release()
acquire_lock_priority(self.lock, self.cur_running, self.my_priority, self.run_time, self.off_time)
self.lock.release() # can't hold lock in case user calls sleep
#self.have_lock = True # just true after the first time
self.next_acquire_time = time.time() + 0.01
self.driver.write_led(led_id, brightness, blue, green, red)
def busy_wait(self, duration=None):
if duration is None:
duration = 100
while duration > 0:
try:
#self.write_led(100, 0, 0, 0, 0)
acquire_lock_priority(self.lock, self.cur_running, self.my_priority, self.run_time, self.off_time)
self.lock.release()
time.sleep(min(duration, 0.5))
duration -= 0.5
except:
return
wait = busy_wait
def stop_signal(self):
"""
Returns True if client's turn is over
(use for future compatibility)
"""
return False
def done(self):
# We should probably do something like...
# release the lock and sleep?
pass