Skip to content

Commit 103f4c3

Browse files
author
Thomas Preston
committed
Added magic default serial port for pi2, pi3 and macos
1 parent 41dc30f commit 103f4c3

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
v0.8.1
5+
------
6+
- Figures out default serial port for Raspberry Pi 2 and below,
7+
Raspberry Pi 3 and above and MacOS.
8+
49
v0.8.0
510
------
611
- Added servo support.

codebug_tether/core.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,27 @@
66
from codebug_tether.serial_channel_device import SerialChannelDevice
77

88

9-
DEFAULT_SERIAL_PORT = '/dev/ttyACM0'
9+
# setup default serial port (different on MacOS and >=Raspberry Pi 3)
10+
if os.uname().sysname == 'Darwin':
11+
# OSX
12+
DEFAULT_SERIAL_PORT = '/dev/tty.USBmodem'
13+
else:
14+
# assume we're on Raspberry Pi/Linux
15+
def get_rpi_revision():
16+
"""Returns the version number from the revision line."""
17+
for line in open("/proc/cpuinfo"):
18+
if "Revision" in line:
19+
import re
20+
return re.sub('Revision\t: ([a-z0-9]+)\n', r'\1', line)
21+
22+
rpi_revision = get_rpi_revision()
23+
if rpi_revision and rpi_revision != 'Beta' and int('0x'+rpi_revision, 16) >= 0xa02082:
24+
# RPi 3 and above
25+
DEFAULT_SERIAL_PORT = '/dev/ttyS0'
26+
else:
27+
# RPi 2 and below
28+
DEFAULT_SERIAL_PORT = '/dev/ttyACM0'
29+
1030

1131
IO_DIGITAL_OUTPUT = 0
1232
IO_DIGITAL_INPUT = 1

codebug_tether/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.8.0'
1+
__version__ = '0.8.1'

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
#
5151
# The short X.Y version.
5252
# The short X.Y version.
53-
version = '0.8.0'
53+
version = '0.8.1'
5454
# The full version, including alpha/beta/rc tags.
55-
release = '0.8.0'
55+
release = '0.8.1'
5656

5757
# The language for content autogenerated by Sphinx. Refer to documentation
5858
# for a list of supported languages.

docs/example.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Basics
3838

3939

4040
.. note:: You can specify a different serial device for CodeBug by passing
41-
the class a string. For example, OSX users might use:
42-
``codebug = codebug_tether.CodeBug('/dev/tty.USBmodem')``.
41+
the class a string. For example:
42+
``codebug = codebug_tether.CodeBug(serial_port='/dev/tty.USBmodem')``.
4343

4444

4545
Sprites

0 commit comments

Comments
 (0)