openbci-archive / OpenBCI_Python

The Python software library designed to work with OpenBCI hardware.
MIT License
510 stars 207 forks source link

Clean up BluePy import #105

Closed ikmckenz closed 5 years ago

ikmckenz commented 6 years ago

This should resolve #87 and #103 by cleaning up the BluePy import.

Previously trying to instantiate the driver with port as "TEST" would result in this error:

Traceback (most recent call last):
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/test.py", line 3, in <module>
    driver = OpenBCIGanglion(port="AUTO")
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 94, in __init__
    self.connect()
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 121, in connect
    self.gang = Peripheral(self.port, 'random') # ADDR_TYPE_RANDOM
NameError: global name 'Peripheral' is not defined

While after this patch it errors on "TEST" not being a MAC address as expected.

Traceback (most recent call last):
Looking for Ganglion board
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/test.py", line 3, in <module>
Init BLE connection with MAC: TEST
    driver = OpenBCIGanglion(port="TEST")
NB: if it fails, try with root privileges.
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 82, in __init__
    self.connect()
  File "/home/ian/PycharmProjects/OpenBCI_Python/openbci/ganglion.py", line 109, in connect
    self.gang = Peripheral(self.port, 'random') # ADDR_TYPE_RANDOM
  File "/home/ian/PycharmProjects/OpenBCI_Python/venv/local/lib/python2.7/site-packages/bluepy/btle.py", line 318, in __init__
    self.connect(deviceAddr, addrType, iface)
  File "/home/ian/PycharmProjects/OpenBCI_Python/venv/local/lib/python2.7/site-packages/bluepy/btle.py", line 350, in connect
    raise ValueError("Expected MAC address, got %s" % repr(addr))
ValueError: Expected MAC address, got 'TEST'

Ganglion has a bunch of other small bugs in it, but I was kinda hoping that my style pull request would be merged in before working on them.

codecov-io commented 6 years ago

Codecov Report

Merging #105 into master will decrease coverage by 0.29%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #105     +/-   ##
=========================================
- Coverage   29.11%   28.82%   -0.3%     
=========================================
  Files           9        9             
  Lines        1590     1582      -8     
=========================================
- Hits          463      456      -7     
+ Misses       1127     1126      -1
Impacted Files Coverage Δ
openbci/ganglion.py 13.66% <100%> (-1.33%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update dc990b6...f4093b0. Read the comment docs.

aliraza19 commented 6 years ago

This Patch is really is help-full for sorting out the error "NameError: global name 'Peripheral' is not defined" .

ikmckenz commented 5 years ago

Is there anything else you'd like to see here before you merge this @andrewjaykeller ?

andrewjaykeller commented 5 years ago

I can merge it!

andrewjaykeller commented 5 years ago

Thanks!!!

jzingh98 commented 5 years ago

I'm getting the same output "Expected MAC address, got %s" repr(addr))

with

sudo python user.py -p /dev/TEST (same as OP)

as well as when I specify a port

sudo python user.py -p /dev/ttyACM0

This is with Ganglion on Ubuntu 18.04. Wondering if a solution has been found?