Skip to content
Browse files

Cleanup

  • Loading branch information...
1 parent 3931856 commit 2d986aafff085a9168bdfbd4dfd0903ec3d631cc @ejholmes committed Jul 11, 2011
Showing with 59 additions and 37 deletions.
  1. +3 −0 .gitignore
  2. +10 −1 Makefile.am
  3. +1 −7 bootloader.cpp
  4. +0 −2 commandline/.gitignore
  5. +0 −6 commandline/Makefile
  6. +4 −0 commandline/bootloader.cpp
  7. +4 −0 commandline/openfocus.cpp
  8. +27 −5 configure.ac
  9. +1 −7 device.cpp
  10. +9 −9 util.h → openfocus_priv.h
View
3 .gitignore
@@ -13,6 +13,9 @@ build/*
*.tar
*.xcodeproj
+openfocus
+bootloader
+
# Autotools
Makefile
Makefile.in
View
11 Makefile.am
@@ -3,4 +3,13 @@ libopenfocus_la_CPPFLAGS = $(LIBUSB_CFLAGS)
libopenfocus_la_LIBADD = $(LIBUSB_LIBS)
libopenfocus_la_SOURCES = device.cpp bootloader.cpp cdevice.cpp intelhex.cpp helper.cpp
libopenfocus_la_LDFLAGS = -no-undefined -version-info 0:0:0
-include_HEADERS = openfocus.h intelhex.h util.h
+noinst_HEADERS = intelhex.h openfocus_priv.h
+include_HEADERS = openfocus.h
+
+noinst_PROGRAMS = openfocus bootloader
+
+openfocus_LDADD = libopenfocus.la
+openfocus_SOURCES = commandline/openfocus.cpp
+
+bootloader_LDADD = libopenfocus.la
+bootloader_SOURCES = commandline/bootloader.cpp
View
8 bootloader.cpp
@@ -4,13 +4,7 @@
#include <usb.h>
#include "openfocus.h"
-#include "util.h"
-
-#ifdef DEBUG
-#define DBG(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DBG(...)
-#endif
+#include "openfocus_priv.h"
enum USB_REQUEST {
USB_RQ_REBOOT = 0x01,
View
2 commandline/.gitignore
@@ -1,2 +0,0 @@
-bootloader
-openfocus
View
6 commandline/Makefile
@@ -1,6 +0,0 @@
-all:
- g++ -o openfocus openfocus.cpp -lusb -lopenfocus
- g++ -I.. -o bootloader bootloader.cpp -lusb -lopenfocus
-
-clean:
- rm -f bootloader openfocus
View
4 commandline/bootloader.cpp
@@ -18,6 +18,10 @@ void usage()
int main(int argc, char **argv)
{
+ if (argc <= 1) {
+ usage();
+ return 0;
+ }
Bootloader *bootloader = new Bootloader();
int c;
opterr = 0;
View
4 commandline/openfocus.cpp
@@ -22,6 +22,10 @@ void usage()
int main(int argc, char **argv)
{
+ if (argc <= 1) {
+ usage();
+ return 0;
+ }
Device *device = new Device();
/* Try to connect to the device */
if (!device->Connect()) {
View
32 configure.ac
@@ -14,12 +14,34 @@ AC_PROG_LN_S
AC_PROG_CPP
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
+PKG_PROG_PKG_CONFIG
-# Check for libusb
-PKG_CHECK_MODULES([LIBUSB], [libusb],,[
- AC_CHECK_LIB([usb], [usb_init],,[AC_MSG_ERROR[libusb not found]])
- AC_CHECK_HEADERS([usb.h],,[AC_MSG_ERROR[usb.h not found]])
- ])
+AC_ARG_ENABLE(debug,
+ [ --enable-debug Enable debugging (disabled by default)],
+ [if test x$enableval = xyes; then
+ AC_DEFINE(DEBUG, 1, [Define this to enable debug messages and assert warnings.]) debug_support=yes
+ fi])
+
+AC_PATH_PROG([LIBUSB_CONFIG], [libusb-config], [], [$PATH$PATH_SEPARATOR/usr/local/Crosspack-AVR/bin])
+
+if test ! -z $PKG_CONFIG; then
+ PKG_CHECK_MODULES([LIBUSB], [libusb],,)
+else
+ if test ! -z $LIBUSB_CONFIG; then
+ LIBUSB_CFLAGS=`$LIBUSB_CONFIG --cflags`
+ LIBUSB_LIBS=`$LIBUSB_CONFIG --libs`
+ AC_SUBST([LIBUSB_CFLAGS])
+ AC_SUBST([LIBUSB_LIBS])
+ else
+ AC_MSG_ERROR([
+* No suitable version of libusb-0.1 was found.
+* If you know where libusb is located, specify it
+* with the LIBUSB_CFLAGS and LIBUSB_LIBS variables.
+*
+* If you do not have libusb installed, you can
+* download it from http://www.libusb.org/])
+ fi
+fi
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h])
View
8 device.cpp
@@ -6,13 +6,7 @@
#include <usb.h>
#include "openfocus.h"
-#include "util.h"
-
-#ifdef DEBUG
-#define DBG(...) fprintf(stderr, __VA_ARGS__)
-#else
-#define DBG(...)
-#endif
+#include "openfocus_priv.h"
enum USB_REQUEST {
USB_RQ_MOVE_TO = 0x00,
View
18 util.h → openfocus_priv.h
@@ -1,6 +1,10 @@
#ifndef UTIL_H
#define UTIL_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <usb.h>
@@ -51,14 +55,10 @@ static inline bool usb_open_device(usb_dev_handle **device, int vendorID, int pr
return true;
}
-/* Copies bytes from source to dest and swapping between big and little endian
- * in the process */
-static inline void endian_swap(void *dest, const void *source, int length)
-{
- int i;
- for (i = 0; i < length; i++) {
- ((char *)dest)[i] = (((char *)source)[length - i]);
- }
-}
+#ifdef DEBUG
+#define DBG(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define DBG(...)
+#endif
#endif // UTIL_H

0 comments on commit 2d986aa

Please sign in to comment.
Something went wrong with that request. Please try again.