From dcd9c560d32997e8e8ec41873636abac81b1428e Mon Sep 17 00:00:00 2001 From: Adam Preble Date: Mon, 25 May 2009 01:40:08 -0400 Subject: [PATCH] Added CMake building and instructions to README.markdown. Removed YAML loading code from libpinproc. --- CMakeLists.txt | 18 +++++ Makefile | 11 ++- README.markdown | 18 ++++- examples/pinproctest/Makefile | 10 ++- examples/pinproctest/pinproctest.cpp | 10 +-- include/pinproc.h | 2 - libpinproc.xcodeproj/project.pbxproj | 16 +--- src/PRConfig.cpp | 108 --------------------------- src/PRDevice.h | 1 - src/pinproc.cpp | 5 -- 10 files changed, 52 insertions(+), 147 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 src/PRConfig.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..69639dd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 2.6) + +#set( CMAKE_OSX_ARCHITECTURES ppc;i386 ) #Comment out if not universal binary + +#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../bin) +#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ../bin) +#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ../bin) + +include_directories(/usr/local/include ./include) + +link_directories(/usr/local/lib) + +set(FILES src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp) +add_library(pinproc ${FILES}) + +add_executable(pinproctest examples/pinproctest/pinproctest.cpp) +target_link_libraries(pinproctest pinproc usb ftdi) + diff --git a/Makefile b/Makefile index f995236..a1f8b48 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,21 @@ # CC=g++ LIB=libpinproc.a -LIBDEST=./ +LIBDEST=./bin/ -LIBSRC=src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp src/PRConfig.cpp +LIBSRC=src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp LIBOBJ=$(LIBSRC:.cpp=.o) -#CXXFLAGS=-I/usr/local/lib -lusb -lftdi -CXXFLAGS=-I../../yaml-cpp/include +CXXFLAGS= $(LIB): $(LIBOBJ) @echo lib Makefile - archiving $(LIB) - $(AR) r $(LIB) $(LIBOBJ) + $(AR) r $(LIBDEST)$(LIB) $(LIBOBJ) .cpp.o: @echo lib Makefile - compiling $< $(CC) $(CXXFLAGS) -c $< -o $@ clean: - rm -f $(LIBOBJ) $(LIB) + rm -f $(LIBOBJ) $(LIBDEST)$(LIB) diff --git a/README.markdown b/README.markdown index 7e5b248..e92e344 100644 --- a/README.markdown +++ b/README.markdown @@ -4,15 +4,29 @@ Library for Gerry Stellenberg's [P-ROC](http://pinballcontrollers.com/) (Pinball ### Compiling +#### Prerequisites + libpinproc requires: - [libusb-0.1.12](http://libusb.wiki.sourceforge.net/): Install with the default /usr/local prefix. - [libftdi-0.16](http://www.intra2net.com/en/developer/libftdi/): Install with the default /usr/local prefix. + +Once required but not right now: + - [yaml-cpp](http://code.google.com/p/yaml-cpp/): Should be checked out in the directory two levels below libpinproc in the full source tree (at the same level as ./P-ROC) in a directory named yaml-cpp. Follow the build instructions, creating the build subdirectory. The Makefiles and other project files expect to find libyaml-cpp.a in the yaml-cpp/build/bin directory. -### License +We are presently experimenting with different build mechanisms. As such there are three ways to build libpinproc at this time: CMake, GNU Make, and the Xcode project (for Mac). As the preferred method is presently CMake, here's how. Before you get started, you will need CMake if you don't already have it. -#### The MIT License +#### Building with CMake + + cd libpinproc + mkdir build; cd build + cmake .. + make + +The CMakeLists.txt file is presently designed to be run from a directory inside the libpinproc directory. This will build both libpinproc and pinproctest. Binaries will be placed in the directory that make was run from. + +### License Copyright (c) 2009 Gerry Stellenberg, Adam Preble diff --git a/examples/pinproctest/Makefile b/examples/pinproctest/Makefile index 99244bc..8b5ddf4 100644 --- a/examples/pinproctest/Makefile +++ b/examples/pinproctest/Makefile @@ -1,13 +1,15 @@ # # File: Makefile for application # +PINPROC_PATH=../.. + CC=g++ -LDFLAGS=-L../.. -L/usr/local/lib -L../../../../yaml-cpp/build/bin -LIBS=-lpinproc -lusb -lftdi -lyaml-cpp +LDFLAGS=-L$(PINPROC_PATH)/bin -L/usr/local/lib +LIBS=-lpinproc -lusb -lftdi SRC=pinproctest.cpp -CXXFLAGS=-I../../include +CXXFLAGS=-I$(PINPROC_PATH)/include OBJS=$(SRC:.cpp=.o) @@ -16,7 +18,7 @@ EXE=pinproctest all: $(EXE) # FIXME: This makes the exe require libpinproc but not in a very graceful way. -$(EXE): $(OBJS) ../../libpinproc.a +$(EXE): $(OBJS) $(PINPROC_PATH)/bin/libpinproc.a @echo application Makefile - linking $< $(CC) $^ $(LDFLAGS) $(LIBS) -o $@ diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index db632bd..5a2854d 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -219,15 +219,15 @@ void ConfigureDMD(PRHandle proc) // Display a simple pattern to verify DMD functionality. // 16 consecutive rows will turn on with incrementing brightness and rotate vertically -void UpdateDots( unsigned char * dots, unsigned int dotPointer ) +void UpdateDots( unsigned char * dots, unsigned int dotOffset ) { int i,j,k,color,mappedColor,loopCtr; - loopCtr = dotPointer/2; + loopCtr = dotOffset/2; color = 0xf; // Slow it down just a tad - if (dotPointer%2 == 0) + if (dotOffset%2 == 0) { // Clear the DMD dots every time the rotation occurs memset(dots,0,((128*32)/8)*4); @@ -266,14 +266,14 @@ void RunLoop(PRHandle proc) // Create dot array using an array of bytes. Each byte holds 8 dots. Need // space for 4 sub-frames of 128/32 dots. unsigned char dots[4*((128*32)/8)]; - unsigned int dotPointer = 0; + unsigned int dotOffset = 0; while (runLoopRun) { PRDriverWatchdogTickle(proc); // Create a dot pattern to test the DMD - UpdateDots(dots,dotPointer++); + UpdateDots(dots,dotOffset++); PRDMDDraw(proc,dots); int numEvents = PRGetEvents(proc, events, maxEvents); diff --git a/include/pinproc.h b/include/pinproc.h index 5856d93..c0aacac 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -91,8 +91,6 @@ typedef enum PRMachineType { PR_EXPORT PRHandle PRCreate(PRMachineType machineType); /**< Create a new P-ROC device handle. Only one handle per device may be created. This handle must be destroyed with PRDelete() when it is no longer needed. Returns #kPRHandleInvalid if an error occurred. */ PR_EXPORT void PRDelete(PRHandle handle); /**< Destroys an existing P-ROC device handle. */ -PR_EXPORT PRResult PRLoadDefaultsFromYAML(PRHandle handle, const char *yamlFilePath); - /** @} */ // End of Device Creation & Deletion // Drivers diff --git a/libpinproc.xcodeproj/project.pbxproj b/libpinproc.xcodeproj/project.pbxproj index 252f07f..aea7949 100644 --- a/libpinproc.xcodeproj/project.pbxproj +++ b/libpinproc.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 668249E30FC0A3960051560E /* pinproctest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 668249E20FC0A3960051560E /* pinproctest.cpp */; }; 668249EA0FC0A4280051560E /* libpinproc.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2AAC046055464E500DB518D /* libpinproc.a */; }; 668249ED0FC0A4CD0051560E /* PRHardware.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 668249EC0FC0A4CD0051560E /* PRHardware.cpp */; }; - 66824DAE0FC6FC690051560E /* PRConfig.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 66824DAD0FC6FC690051560E /* PRConfig.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -37,7 +36,6 @@ 668249D90FC0A30A0051560E /* pinproctest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = pinproctest; sourceTree = BUILT_PRODUCTS_DIR; }; 668249E20FC0A3960051560E /* pinproctest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = pinproctest.cpp; path = examples/pinproctest/pinproctest.cpp; sourceTree = ""; }; 668249EC0FC0A4CD0051560E /* PRHardware.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PRHardware.cpp; path = src/PRHardware.cpp; sourceTree = ""; }; - 66824DAD0FC6FC690051560E /* PRConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PRConfig.cpp; path = src/PRConfig.cpp; sourceTree = ""; }; D2AAC046055464E500DB518D /* libpinproc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpinproc.a; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -95,7 +93,6 @@ 668249390FC07B2A0051560E /* pinproc.cpp */, 668249400FC07D900051560E /* PRDevice.h */, 668249410FC07D900051560E /* PRDevice.cpp */, - 66824DAD0FC6FC690051560E /* PRConfig.cpp */, 6682494A0FC0870B0051560E /* PRHardware.h */, 668249EC0FC0A4CD0051560E /* PRHardware.cpp */, ); @@ -201,7 +198,6 @@ 6682493A0FC07B2A0051560E /* pinproc.cpp in Sources */, 668249430FC07D900051560E /* PRDevice.cpp in Sources */, 668249ED0FC0A4CD0051560E /* PRHardware.cpp in Sources */, - 66824DAE0FC6FC690051560E /* PRConfig.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -285,11 +281,7 @@ GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; INSTALL_PATH = /usr/local/bin; - OTHER_LDFLAGS = ( - "-L../../yaml-cpp/build/bin", - "-lyaml-cpp", - "-lftdi", - ); + OTHER_LDFLAGS = "-lftdi"; PREBINDING = NO; PRODUCT_NAME = pinproctest; }; @@ -304,11 +296,7 @@ GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_MODEL_TUNING = G5; INSTALL_PATH = /usr/local/bin; - OTHER_LDFLAGS = ( - "-L../../yaml-cpp/build/bin", - "-lyaml-cpp", - "-lftdi", - ); + OTHER_LDFLAGS = "-lftdi"; PREBINDING = NO; PRODUCT_NAME = pinproctest; ZERO_LINK = NO; diff --git a/src/PRConfig.cpp b/src/PRConfig.cpp deleted file mode 100644 index ac0a0e5..0000000 --- a/src/PRConfig.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The MIT License - * Copyright (c) 2009 Gerry Stellenberg, Adam Preble - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ -/* - * PRConfig.cpp - * libpinproc - * - */ - - -#include "PRDevice.h" - -#include -#include "yaml.h" - -PRResult PRDevice::LoadDefaultsFromYAML(const char *yamlFilePath) -{ - try - { - std::ifstream fin(yamlFilePath); - if (fin.is_open() == false) - { - DEBUG(PRLog("YAML file not found: %s\n", yamlFilePath)); - return kPRFailure; - } - YAML::Parser parser(fin); - - while(parser) { - YAML::Node doc; - parser.GetNextDocument(doc); - - try - { - const YAML::Node& node = doc["PRGameName"]; - std::string name; node >> name; - DEBUG(PRLog(" Game Name: %s\n", name.c_str())); - } - catch (YAML::KeyNotFound& ex) {} - - try - { - const YAML::Node& dict = doc["PRSwitches"]; - for(YAML::Iterator dictIt = dict.begin(); dictIt != dict.end(); ++dictIt) - { - std::string key; - std::string name; - dictIt.first() >> key; - dictIt.second() >> name; - DEBUG(PRLog(" Switch: %s -> %s\n", key.c_str(), name.c_str())); - } - } - catch (YAML::KeyNotFound& ex) {} - - try - { - const YAML::Node& dict = doc["PRDrivers"]; - for(YAML::Iterator dictIt = dict.begin(); dictIt != dict.end(); ++dictIt) - { - std::string key; - std::string name; - dictIt.first() >> key; - dictIt.second() >> name; - DEBUG(PRLog(" Driver: %s -> %s\n", key.c_str(), name.c_str())); - } - } - catch (YAML::KeyNotFound& ex) {} - - } - } - catch (YAML::ParserException& ex) - { - DEBUG(PRLog("YAML parse error at line=%d col=%d: %s\n", ex.line, ex.column, ex.msg.c_str())); - return kPRFailure; - } - catch (YAML::RepresentationException& ex) - { - DEBUG(PRLog("YAML representation error at line=%d col=%d: %s\n", ex.line, ex.column, ex.msg.c_str())); - return kPRFailure; - } - catch (...) - { - DEBUG(PRLog("Unexpected exception while parsing YAML config.\n")); - return kPRFailure; - } - return kPRSuccess; -} diff --git a/src/PRDevice.h b/src/PRDevice.h index 06ce090..b4117b2 100644 --- a/src/PRDevice.h +++ b/src/PRDevice.h @@ -56,7 +56,6 @@ protected: public: // public libpinproc API: - PRResult LoadDefaultsFromYAML(const char *yamlFilePath); int GetEvents(PREvent *events, int maxEvents); PRResult DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig); diff --git a/src/pinproc.cpp b/src/pinproc.cpp index 58b1a54..9dddd1e 100644 --- a/src/pinproc.cpp +++ b/src/pinproc.cpp @@ -72,11 +72,6 @@ PR_EXPORT void PRDelete(PRHandle handle) delete (PRDevice*)handle; } -PR_EXPORT PRResult PRLoadDefaultsFromYAML(PRHandle handle, const char *yamlFilePath) -{ - return handleAsDevice->LoadDefaultsFromYAML(yamlFilePath); -} - // Events /** Get all of the available events that have been received. */