Skip to content

Commit

Permalink
cleanup setup.py once again
Browse files Browse the repository at this point in the history
fix windows/mac handling in setup.py
fix try.py example
  • Loading branch information
prusnak committed Sep 10, 2013
1 parent 4f6531e commit 1520ee2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
hid.c
hid-raw.c
hidraw.c
115 changes: 0 additions & 115 deletions hid-raw.pyx

This file was deleted.

2 changes: 1 addition & 1 deletion hidapi
Submodule hidapi updated 5 files
+1 −6 .gitignore
+1 −1 README.txt
+1 −1 configure.ac
+8 −4 libusb/hid.c
+1 −0 mac/hid.c
1 change: 1 addition & 0 deletions hidraw.pyx
51 changes: 32 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
#!/usr/bin/python

# dependencies: libusb-1.0-0-dev, libudev-dev

# python setup.py sdist upload

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import os
import sys

sources = ["hid.pyx", os.path.join(os.getcwd(), "hidapi", "libusb", "hid.c")]
hidapi_topdir = os.path.join(os.getcwd(), 'hidapi')
hidapi_include = os.path.join(hidapi_topdir, 'hidapi')
def hidapi_src(platform):
return os.path.join(hidapi_topdir, platform, 'hid.c')

if sys.platform.startswith('linux'):
sources_raw = ["hid-raw.pyx",]
libs = ["usb-1.0", "udev", "rt"]
libs_raw = ["udev", "rt"]
modules = [Extension("hid", sources, libraries = libs, include_dirs=["/usr/include/libusb-1.0", os.path.join(os.getcwd(), "hidapi", "hidapi")]),
Extension("hidraw", sources_raw, libraries=libs_raw, include_dirs=[os.path.join(os.getcwd(), "hidapi", "hidapi")])]
modules = [
Extension('hid',
sources = ['hid.pyx', hidapi_src('libusb')],
include_dirs = [hidapi_include, '/usr/include/libusb-1.0'],
libraries = ['usb-1.0', 'udev', 'rt'],
),
Extension('hidraw',
sources = ['hidraw.pyx', hidapi_src('linux')],
include_dirs = [hidapi_include],
libraries = ['udev', 'rt'],
)
]

if sys.platform.startswith('darwin'):
os.environ['CFLAGS'] = "-framework IOKit -framework CoreFoundation"
os.environ['LDFLAGS'] = ""
sources.append("hid-mac.c")
libs = []
modules = [Extension("hid", sources, libraries = libs)]
os.environ['CFLAGS'] = '-framework IOKit -framework CoreFoundation'
os.environ['LDFLAGS'] = ''
modules = [
Extension('hid',
sources = ['hid.pyx', hidapi_src('mac')],
include_dirs = [hidapi_include],
libraries = [],
)
]

if sys.platform.startswith('win'):
sources.append("hid-windows.c")
libs = ["setupapi"]
modules = [Extension("hid", sources, libraries = libs)]
modules = [
Extension('hid',
sources = ['hid.pyx', hidapi_src('windows')],
include_dirs = [hidapi_include],
libraries = ['setupapi'],
)
]

setup(
name = 'hidapi',
Expand Down
5 changes: 3 additions & 2 deletions try.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

try:
print "Opening device"
h = hid.device(0x461, 0x20)
#h = hid.device(0x1941, 0x8021) # Fine Offset USB Weather Station
h = hid.device()
h.open(0x461, 0x20)
#h.open(0x1941, 0x8021) # Fine Offset USB Weather Station

print "Manufacturer: %s" % h.get_manufacturer_string()
print "Product: %s" % h.get_product_string()
Expand Down

0 comments on commit 1520ee2

Please sign in to comment.