1
0
mirror of https://github.com/preble/libpinproc synced 2026-02-24 18:25:23 +01:00

Added excruciatingly rough implementation of PRLoadDefaultsFromYAML() and related items.

This commit is contained in:
Adam Preble
2009-05-22 01:51:52 -04:00
parent b96905f5ca
commit cd1b0462c5
11 changed files with 133 additions and 7 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
build/ build/
*/*.pbxuser */*.pbxuser
*/*.perspectivev3 */*.perspectivev3
*.o

View File

@@ -9,7 +9,8 @@ LIBSRC=src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp
LIBOBJ=$(LIBSRC:.cpp=.o) LIBOBJ=$(LIBSRC:.cpp=.o)
#CXXFLAGS=-I/usr/local/lib -lusb -lftdi #CXXFLAGS=-I/usr/local/lib -lusb -lftdi
CXXFLAGS=-I../../yaml-cpp/include
$(LIB): $(LIBOBJ) $(LIB): $(LIBOBJ)
@echo lib Makefile - archiving $(LIB) @echo lib Makefile - archiving $(LIB)

View File

@@ -2,6 +2,14 @@
Library for Gerry Stellenberg's [P-ROC](http://pinballcontrollers.com/) (Pinball Remote Operations Controller). Library for Gerry Stellenberg's [P-ROC](http://pinballcontrollers.com/) (Pinball Remote Operations Controller).
### Compiling
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.
- [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 ### License
#### The MIT License #### The MIT License

View File

@@ -0,0 +1,7 @@
PRGameName: My Great Pin
PRDrivers:
1: driver one
2: driver two
PRSwitches:
1: switch one
2: switch two

View File

@@ -2,8 +2,8 @@
# File: Makefile for application # File: Makefile for application
# #
CC=g++ CC=g++
LDFLAGS=-L../.. -L/usr/local/lib LDFLAGS=-L../.. -L/usr/local/lib -L../../../../yaml-cpp/build/bin
LIBS=-lpinproc -lusb -lftdi LIBS=-lpinproc -lusb -lftdi -lyaml-cpp
SRC=pinproctest.cpp SRC=pinproctest.cpp

View File

@@ -162,6 +162,7 @@ int main(const char **argv, int argc)
return 1; return 1;
printf("Configuring P-ROC...\n"); printf("Configuring P-ROC...\n");
PRLoadDefaultsFromYAML(proc, "../../examples/pinproctest/Example.yaml");
ConfigureSwitches(proc); ConfigureSwitches(proc);
// Make Drivers the last thing to configure so watchdog doesn't expire // Make Drivers the last thing to configure so watchdog doesn't expire

View File

@@ -91,6 +91,8 @@ 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 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 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 /** @} */ // End of Device Creation & Deletion
// Drivers // Drivers

View File

@@ -221,7 +221,10 @@
GCC_ENABLE_FIX_AND_CONTINUE = YES; GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
HEADER_SEARCH_PATHS = /usr/local/include; HEADER_SEARCH_PATHS = (
/usr/local/include,
"../../yaml-cpp/include",
);
INSTALL_PATH = /usr/local/lib; INSTALL_PATH = /usr/local/lib;
PRODUCT_NAME = pinproc; PRODUCT_NAME = pinproc;
}; };
@@ -233,7 +236,10 @@
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
HEADER_SEARCH_PATHS = /usr/local/include; HEADER_SEARCH_PATHS = (
/usr/local/include,
"../../yaml-cpp/include",
);
INSTALL_PATH = /usr/local/lib; INSTALL_PATH = /usr/local/lib;
PRODUCT_NAME = pinproc; PRODUCT_NAME = pinproc;
}; };
@@ -275,7 +281,11 @@
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = /usr/local/bin; INSTALL_PATH = /usr/local/bin;
OTHER_LDFLAGS = "-lftdi"; OTHER_LDFLAGS = (
"-L../../yaml-cpp/build/bin",
"-lyaml-cpp",
"-lftdi",
);
PREBINDING = NO; PREBINDING = NO;
PRODUCT_NAME = pinproctest; PRODUCT_NAME = pinproctest;
}; };
@@ -290,7 +300,11 @@
GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_MODEL_TUNING = G5; GCC_MODEL_TUNING = G5;
INSTALL_PATH = /usr/local/bin; INSTALL_PATH = /usr/local/bin;
OTHER_LDFLAGS = "-lftdi"; OTHER_LDFLAGS = (
"-L../../yaml-cpp/build/bin",
"-lyaml-cpp",
"-lftdi",
);
PREBINDING = NO; PREBINDING = NO;
PRODUCT_NAME = pinproctest; PRODUCT_NAME = pinproctest;
ZERO_LINK = NO; ZERO_LINK = NO;

View File

@@ -99,6 +99,93 @@ void PRDevice::Reset()
// TODO: Assign defaults based on machineType. Some may have already been done above. // TODO: Assign defaults based on machineType. Some may have already been done above.
} }
#include <fstream>
#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);
for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
std::string key;
it.first() >> key;
DEBUG(PRLog("Parsing key %s...\n", key.c_str()));
if (key.compare("PRGameName") == 0)
{
std::string name;
it.second() >> name;
DEBUG(PRLog(" Machine name: %s\n", name.c_str()));
}
else if (key.compare("PRDriverGlobalConfig") == 0)
{
//const YAML::Node& dict = it.second();
}
else if (key.compare("PRDriverGroupConfigs") == 0)
{
const YAML::Node& groups = it.second();
for(YAML::Iterator it=groups.begin();it!=groups.end();++it)
{
std::string key;
it.first() >> key;
}
}
else if (key.compare("PRDrivers") == 0)
{
const YAML::Node& dict = it.second();
for(YAML::Iterator dictIt=dict.begin(); dictIt != dict.end(); ++dictIt)
{
std::string driverKey;
std::string driverName;
dictIt.first() >> driverKey;
dictIt.second() >> driverName;
DEBUG(PRLog(" Driver: %s -> %s\n", driverKey.c_str(), driverName.c_str()));
}
}
else if (key.compare("PRSwitches") == 0)
{
const YAML::Node& dict = it.second();
for(YAML::Iterator dictIt=dict.begin(); dictIt != dict.end(); ++dictIt)
{
std::string driverKey;
std::string driverName;
dictIt.first() >> driverKey;
dictIt.second() >> driverName;
DEBUG(PRLog(" Switch: %s -> %s\n", driverKey.c_str(), driverName.c_str()));
}
}
}
}
}
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;
}
int PRDevice::GetEvents(PREvent *events, int maxEvents) int PRDevice::GetEvents(PREvent *events, int maxEvents)
{ {

View File

@@ -56,6 +56,7 @@ protected:
public: public:
// public libpinproc API: // public libpinproc API:
PRResult LoadDefaultsFromYAML(const char *yamlFilePath);
int GetEvents(PREvent *events, int maxEvents); int GetEvents(PREvent *events, int maxEvents);
PRResult DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig); PRResult DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig);

View File

@@ -72,6 +72,10 @@ PR_EXPORT void PRDelete(PRHandle handle)
delete (PRDevice*)handle; delete (PRDevice*)handle;
} }
PR_EXPORT PRResult PRLoadDefaultsFromYAML(PRHandle handle, const char *yamlFilePath)
{
return handleAsDevice->LoadDefaultsFromYAML(yamlFilePath);
}
// Events // Events