Skip to content

Commit

Permalink
make micropython friendly
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
alxwrd committed Aug 18, 2018
1 parent 304625e commit 9914cd5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions l293d/driver.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
"""
Expand Down

0 comments on commit 9914cd5

Please sign in to comment.