diff --git a/CMakeLists.txt b/CMakeLists.txt index 81661fe..ed39e89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,9 +86,6 @@ include_directories(${PINPROC_SOURCE_DIR}/include ${EXTRA_INC} /usr/local/includ link_directories(${EXTRA_LINK} /usr/local/lib) endif() -set(YAML_CPP_LIB "yaml-cpp") -set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}") - ### ### General compilation settings @@ -169,15 +166,7 @@ if(MSVC) if(NOT BUILD_SHARED_LIBS) ### General stuff set(LIB_TARGET_SUFFIX "${LIB_SUFFIX}${LIB_RT_SUFFIX}") - - ### Project stuff - # correct external library names - set(YAML_CPP_LIB "${CMAKE_STATIC_LIBRARY_PREFIX}${YAML_CPP_LIB}${LIB_RT_SUFFIX}") - set(YAML_CPP_LIB_DBG "${YAML_CPP_LIB}d") endif() -else() - # make sure executable files are standalone - SET(CMAKE_EXE_LINKER_FLAGS "-static") endif() @@ -261,8 +250,6 @@ add_executable(pinproctest ) target_link_libraries(pinproctest pinproc - optimized ${YAML_CPP_LIB} - debug ${YAML_CPP_LIB_DBG} ) # Create a target for the firmware tool diff --git a/README.markdown b/README.markdown index ff796b8..425c44d 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ ## libpinproc -Library for Gerry Stellenberg's [P-ROC](http://pinballcontrollers.com/) (Pinball Remote Operations Controller). +Library for [Multimorphic, Inc.'s](https://www.multimorphic.com/) P-ROC and P3-ROC pinball controller boards. ### Compiling @@ -12,12 +12,6 @@ libpinproc requires: - [libftdi-0.16](http://www.intra2net.com/en/developer/libftdi/): Install with the default /usr/local prefix. -The pinproctest example requires [yaml-cpp](https://github.com/jbeder/yaml-cpp). Follow the build instructions, creating the build subdirectory. After building, from the main source directory, run the following commands to manually install it: - - sudo cp lib/libyaml-cpp.a /usr/local/lib/ - sudo mkdir /usr/local/include/yaml-cpp - sudo cp include/*.h /usr/local/include/yaml-cpp/ - ##### libusb-1.0 and libusb-compat Version 1.0.2 does not work out of the box since libftdi is written against libusb-0.1. You can use the libusb-compat-0.1.2 project, however, which creates a library that provides the older libusb interface. Because Macs do not come with pkg-config, you may need to run configure for libusb-compat as follows: @@ -37,7 +31,7 @@ Download and install [CMake](http://www.cmake.org/cmake/resources/software.html) 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. We recommend 'bin', as it is the path expected by pypinproc. -Note: On some systems, it may be necessary to build libpinproc with the '-fPIC' option. To do this with cmake, instead of running 'cmake ..', run 'cmake .. -DCMAKE_CXX_FLAGS="-fPIC"'. Compiling without '-fPIC' may cause problems when building the python extensions on some 64-bit Linux machines. +Note: On some systems, it may be necessary to build libpinproc with the '-fPIC' option. To do this with cmake, instead of running 'cmake ..', run 'cmake .. -DCMAKE_CXX_FLAGS="-fPIC"'. Compiling without '-fPIC' may cause problems when building the Python extensions on some 64-bit Linux machines. #### Building in Windows with MinGW/CMake @@ -52,17 +46,31 @@ Follow directions above for building yaml-cpp with the following exception: To build libpinproc: -- add the paths for ftd2xx.h (from the unzipped driver package) and the yaml-cpp/include/*.h files to the "include_directories" line in libpinproc/CMakeLists.txt. - -- either create the directory c:\usr\local\lib and copy libyaml-cpp*.a from the yaml-cpp build directory and ftd2xx.sys to it or add the location of those files to the "link_directories" line in libpinproc/CMakeLists.txt. +- Use -DEXTRA_INC=";" and -DEXTRA_LINK=";" to add include/library paths for `ftd2xx.h` and `ftd2xx.sys`. Follow instructions above for building libpinproc with cmake with the following exceptions: add '-G "MinGW Makefiles' to the cmake command line, use mingw32-make instead of make - + +#### Building in Windows with Visual Studio 2019 + +Assumes you are already running an MSYS2/MinGW64 system. + +Make sure you have cmake installed for i686 (MinGW32) or x86_64 (MinGW64): `pacman -S cmake mingw-w64-i686-cmake mingw-w64-x86_64-cmake` + + cd libpinproc + mkdir build; cd build + cmake .. -A Win32 + # configure paths for td2xxx; use `cmake .. -L` to list configured options + cmake .. -D EXTRA_INC="../ftd2xx" + cmake .. -D EXTRA_LINK="../../ftd2xx/i386" + +Then open PINPROC.sln in Visual Studio, switch to the Debug or Release configuration and perform ALL_BUILD. It will place the libary and sample programs in `build/Debug` and `build/Release`. + ### License Copyright (c) 2009 Gerry Stellenberg, Adam Preble +Copyright (c) 2020 Multimorphic, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/examples/pinproctest/Makefile b/examples/pinproctest/Makefile index 97c9da0..18aa846 100644 --- a/examples/pinproctest/Makefile +++ b/examples/pinproctest/Makefile @@ -11,7 +11,7 @@ SRCS = pinproctest.cpp drivers.cpp dmd.cpp switches.cpp OBJS := $(SRCS:.cpp=.o) INCLUDES = ../../include/pinproc.h -LIBS = usb pinproc yaml-cpp +LIBS = usb pinproc ifneq ($(uname_s),Windows) # not Windows LIBS += ftdi endif diff --git a/examples/pinproctest/pinproctest.cpp b/examples/pinproctest/pinproctest.cpp index 7800930..10d2075 100644 --- a/examples/pinproctest/pinproctest.cpp +++ b/examples/pinproctest/pinproctest.cpp @@ -36,37 +36,6 @@ void TestLogger(PRLogLevel level, const char *text) fprintf(stderr, "TEST: %s", text); } -PRResult LoadConfiguration(YAML::Node& yamlDoc, const char *yamlFilePath) -{ - try - { - std::ifstream fin(yamlFilePath); - if (fin.is_open() == false) - { - fprintf(stderr, "YAML file not found: %s\n", yamlFilePath); - return kPRFailure; - } - - yamlDoc = YAML::Load(fin); - } -// catch (YAML::ParserException& ex) -// { -// fprintf(stderr, "YAML parse error at line=%d col=%d: %s\n", ex.line, ex.column, ex.msg.c_str()); - // return kPRFailure; -// } -// catch (YAML::RepresentationException& ex) -// { -// fprintf(stderr, "YAML representation error at line=%d col=%d: %s\n", ex.line, ex.column, ex.msg.c_str()); -// return kPRFailure; -// } - catch (...) - { - fprintf(stderr, "Unexpected exception while parsing YAML config.\n"); - return kPRFailure; - } - return kPRSuccess; -} - void ConfigureAccelerometerMotion(PRHandle proc) { uint32_t readData[5]; @@ -312,6 +281,20 @@ void sigint(int) printf("Exiting...\n"); } +const struct { + PRMachineType type; + const char *name; +} machine_types[] = { + { kPRMachineCustom, "custom" }, + { kPRMachineWPCAlphanumeric, "wpcAlphanumeric" }, + { kPRMachineWPC, "wpc" }, + { kPRMachineWPC95, "wpc95" }, + { kPRMachineSternWhitestar, "sternWhitestar" }, + { kPRMachineSternSAM, "sternSAM" }, + { kPRMachinePDB, "pdb" }, +}; +#define MACHINE_TYPES (sizeof(machine_types) / sizeof(machine_types[0])) + int main(int argc, const char **argv) { int i; @@ -320,39 +303,26 @@ int main(int argc, const char **argv) signal(SIGINT, sigint); startTime = time(NULL); - if (argc < 2) - { - fprintf(stderr, "Usage: %s \n", argv[0]); + if (argc < 2) { + printf("Usage: %s \n\nWhere machine_type is one of:\n ", argv[0]); + for (i = 0; i < MACHINE_TYPES; i++) { + printf("%s %s", i ? "," : "", machine_types[i].name); + } return 1; } - const char *yamlFilename = argv[1]; // Assign a custom logging callback to demonstrate capturing log information from P-ROC: PRLogSetCallback(TestLogger); - YAML::Node yamlDoc; - if (LoadConfiguration(yamlDoc, yamlFilename) != kPRSuccess) - { - fprintf(stderr, "Failed to load configuration file %s\n", yamlFilename); - return 1; + for (i = 0; i < MACHINE_TYPES; i++) { + if (_strcmpi(argv[1], machine_types[i].name) == 0) { + machineType = machine_types[i].type; + break; + } } - std::string machineTypeString = yamlDoc["PRGame"]["machineType"].as(); - if (machineTypeString == "wpc") - machineType = kPRMachineWPC; - else if (machineTypeString == "wpc95") - machineType = kPRMachineWPC95; - else if (machineTypeString == "wpcAlphanumeric") - machineType = kPRMachineWPCAlphanumeric; - else if(machineTypeString == "sternWhitestar") - machineType = kPRMachineSternWhitestar; - else if(machineTypeString == "sternSAM") - machineType = kPRMachineSternSAM; - else if(machineTypeString == "custom") - machineType = kPRMachineCustom; - else - { - fprintf(stderr, "Unknown machine type: %s\n", machineTypeString.c_str()); + if (machineType == kPRMachineInvalid) { + printf("Unknown machine type: %s\n", argv[1]); return 1; } @@ -371,8 +341,7 @@ int main(int argc, const char **argv) // timing purposes. ConfigureDMD(proc); if (machineType == kPRMachineCustom) ConfigureDrivers(proc); - ConfigureSwitches(proc, yamlDoc); // Notify host for all debounced switch events. - ConfigureSwitchRules(proc, yamlDoc); // Flippers, slingshots + ConfigureSwitches(proc); // Notify host for all debounced switch events. if (machineType == kPRMachineWPCAlphanumeric) UpdateAlphaDisplay(proc, 0); diff --git a/examples/pinproctest/pinproctest.h b/examples/pinproctest/pinproctest.h index 9a8f4f9..1557168 100644 --- a/examples/pinproctest/pinproctest.h +++ b/examples/pinproctest/pinproctest.h @@ -44,7 +44,6 @@ #include #include "pinproc.h" // Include libpinproc's header. #include -#include #ifdef _MSC_VER #include @@ -72,8 +71,7 @@ void ConfigureDrivers(PRHandle proc); -void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc); -void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc); +void ConfigureSwitches(PRHandle proc); void UpdateSwitchState (PREvent * event); void LoadSwitchStates (PRHandle proc); diff --git a/examples/pinproctest/switches.cpp b/examples/pinproctest/switches.cpp index 491def6..75a99d5 100644 --- a/examples/pinproctest/switches.cpp +++ b/examples/pinproctest/switches.cpp @@ -33,7 +33,7 @@ typedef struct SwitchStatus { static SwitchStatus switches[kPRSwitchPhysicalLast + 1]; -void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc) +void ConfigureSwitches(PRHandle proc) { // Configure switch controller registers (if the defaults aren't acceptable) PRSwitchConfig switchConfig; @@ -137,43 +137,6 @@ void ConfigureBumperRule (PRHandle proc, int swNum, int coilNum, int pulseTime) PRSwitchUpdateRule(proc, swNum, kPREventTypeSwitchClosedDebounced, &sw, NULL, 0, false); } -void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc) -{ - // WPC Flippers - std::string numStr; - const YAML::Node& flippers = yamlDoc[kFlippersSection]; - for (YAML::const_iterator flippersIt = flippers.begin(); flippersIt != flippers.end(); ++flippersIt) - { - int swNum, coilMain, coilHold; - std::string flipperName = flippersIt->as(); - if (machineType == kPRMachineWPC) - { - numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); - numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as(); coilMain = PRDecode(machineType, numStr.c_str()); - numStr = yamlDoc[kCoilsSection][flipperName + "Hold"][kNumberField].as(); coilHold = PRDecode(machineType, numStr.c_str()); - ConfigureWPCFlipperSwitchRule (proc, swNum, coilMain, coilHold, kFlipperPulseTime); - } - else if (machineType == kPRMachineSternWhitestar || machineType == kPRMachineSternSAM) - { - printf("hi\n"); - numStr = yamlDoc[kSwitchesSection][flipperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); - numStr = yamlDoc[kCoilsSection][flipperName + "Main"][kNumberField].as(); coilMain = PRDecode(machineType, numStr.c_str()); - ConfigureSternFlipperSwitchRule (proc, swNum, coilMain, kFlipperPulseTime, kFlipperPatterOnTime, kFlipperPatterOffTime); - } - } - - const YAML::Node& bumpers = yamlDoc[kBumpersSection]; - for (YAML::const_iterator bumpersIt = bumpers.begin(); bumpersIt != bumpers.end(); ++bumpersIt) - { - int swNum, coilNum; - // WPC Slingshots - std::string bumperName = bumpersIt->as(); - numStr = yamlDoc[kSwitchesSection][bumperName][kNumberField].as(); swNum = PRDecode(machineType, numStr.c_str()); - numStr = yamlDoc[kCoilsSection][bumperName][kNumberField].as(); coilNum = PRDecode(machineType, numStr.c_str()); - ConfigureBumperRule (proc, swNum, coilNum, kBumperPulseTime); - } -} - void UpdateSwitchState( PREvent * event ) { switches[event->value].state = event->type; diff --git a/libpinproc.xcodeproj/project.pbxproj b/libpinproc.xcodeproj/project.pbxproj index 1da2af3..8ef288f 100644 --- a/libpinproc.xcodeproj/project.pbxproj +++ b/libpinproc.xcodeproj/project.pbxproj @@ -369,7 +369,6 @@ INSTALL_PATH = /usr/local/bin; OTHER_LDFLAGS = ( "-Lbin", - "-lyaml-cpp", "-lftdi", ); PREBINDING = NO; @@ -388,7 +387,6 @@ HEADER_SEARCH_PATHS = /usr/local/include; INSTALL_PATH = /usr/local/bin; OTHER_LDFLAGS = ( - "-lyaml-cpp", "-lftdi", ); PREBINDING = NO;