From 9914cd52b152a8f583d1585ed23e32cd6ad04955 Mon Sep 17 00:00:00 2001 From: Alex Ward Date: Sat, 18 Aug 2018 16:52:33 +0100 Subject: [PATCH] make micropython friendly - collections is renamed ucollections in micropython - threading isn't available on all ports of micropython - __future__doesn't seem to be available, presumably because micropython code isn't meant to be ported between versions --- l293d/driver.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/l293d/driver.py b/l293d/driver.py index 73bf1b6..89c19d2 100644 --- a/l293d/driver.py +++ b/l293d/driver.py @@ -1,10 +1,16 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from __future__ import print_function -from collections import namedtuple -from threading import Thread +try: + from collections import namedtuple +except ImportError: + from ucollections import namedtuple + +try: + from threading import Thread +except ImportError: + threading = False from time import sleep from l293d.config import Config @@ -102,6 +108,9 @@ def drive_motor(self, direction=1, duration=None, wait=True, speed=100): self.pwm.start(speed.cycle) # If duration has been specified, sleep then stop if duration is not None and direction != 0: + if not threading: + self.stop(duration) + return stop_thread = Thread(target=self.stop, args=(duration,)) # Sleep in thread stop_thread.start() @@ -189,7 +198,7 @@ def __init__(self): 'for more info') -def pins_are_valid(pins, force_selection=False): +def pins_are_valid(pins, force_selection=True): """ Check the pins specified are valid for pin numbering in use """