def _audio_command(self, command, play_type): if is_micropython(): if play_type == Sound.PLAY_WAIT_FOR_COMPLETE: os.system(command) elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE: os.system('{} &'.format(command)) elif play_type == Sound.PLAY_LOOP: while True: os.system(command) else: raise Exception("invalid play_type " % play_type) return None else: with open(os.devnull, 'w') as n: if play_type == Sound.PLAY_WAIT_FOR_COMPLETE: processes = get_command_processes(command) processes[-1].communicate() processes[-1].wait() return None elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE: processes = get_command_processes(command) return processes[-1] elif play_type == Sound.PLAY_LOOP: while True: processes = get_command_processes(command) processes[-1].communicate() processes[-1].wait() else: raise Exception("invalid play_type " % play_type)
def get_ticks_ms(): if is_micropython(): return utime.ticks_ms() else: return int(dt.datetime.timestamp(dt.datetime.now()) * 1000)
""" A StopWatch class for tracking the amount of time between events """ from ev3dev2 import is_micropython if is_micropython(): import utime else: import datetime as dt def get_ticks_ms(): if is_micropython(): return utime.ticks_ms() else: return int(dt.datetime.timestamp(dt.datetime.now()) * 1000) class StopWatch(object): def __init__(self, desc=None): self.desc = desc self._value = 0 self.start_time = None self.prev_update_time = None def __str__(self): if self.desc is not None: return self.desc else: return self.__class__.__name__
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ----------------------------------------------------------------------------- import sys if sys.version_info < (3, 4): raise SystemError('Must be using Python 3.4 or higher') from ev3dev2 import is_micropython import os import re from time import sleep if not is_micropython(): import shlex from subprocess import Popen, PIPE def _make_scales(notes): """ Utility function used by Sound class for building the note frequencies table """ res = dict() for note, freq in notes: freq = round(freq) for n in note.split('/'): res[n.upper()] = freq return res def get_command_processes(command):
Check if ``enter`` button is pressed. """ pass @property def backspace(self): """ Check if ``backspace`` button is pressed. """ pass # micropython implementation if is_micropython(): # noqa: C901 try: # This is a linux-specific module. # It is required by the Button class, but failure to import it may be # safely ignored if one just needs to run API tests on Windows. import fcntl except ImportError: log.warning(library_load_warning_message("fcntl", "Button")) def _test_bit(buf, index): pass class ButtonBase(ButtonCommon): pass