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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
build/
|
||||
*/*.pbxuser
|
||||
*/*.perspectivev3
|
||||
*.o
|
||||
|
||||
3
Makefile
3
Makefile
@@ -9,7 +9,8 @@ LIBSRC=src/pinproc.cpp src/PRDevice.cpp src/PRHardware.cpp
|
||||
|
||||
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)
|
||||
@echo lib Makefile - archiving $(LIB)
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
|
||||
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
|
||||
|
||||
#### The MIT License
|
||||
|
||||
7
examples/pinproctest/Example.yaml
Normal file
7
examples/pinproctest/Example.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
PRGameName: My Great Pin
|
||||
PRDrivers:
|
||||
1: driver one
|
||||
2: driver two
|
||||
PRSwitches:
|
||||
1: switch one
|
||||
2: switch two
|
||||
@@ -2,8 +2,8 @@
|
||||
# File: Makefile for application
|
||||
#
|
||||
CC=g++
|
||||
LDFLAGS=-L../.. -L/usr/local/lib
|
||||
LIBS=-lpinproc -lusb -lftdi
|
||||
LDFLAGS=-L../.. -L/usr/local/lib -L../../../../yaml-cpp/build/bin
|
||||
LIBS=-lpinproc -lusb -lftdi -lyaml-cpp
|
||||
|
||||
SRC=pinproctest.cpp
|
||||
|
||||
|
||||
@@ -162,6 +162,7 @@ int main(const char **argv, int argc)
|
||||
return 1;
|
||||
|
||||
printf("Configuring P-ROC...\n");
|
||||
PRLoadDefaultsFromYAML(proc, "../../examples/pinproctest/Example.yaml");
|
||||
|
||||
ConfigureSwitches(proc);
|
||||
// Make Drivers the last thing to configure so watchdog doesn't expire
|
||||
|
||||
@@ -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 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
|
||||
|
||||
@@ -221,7 +221,10 @@
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
HEADER_SEARCH_PATHS = /usr/local/include;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
/usr/local/include,
|
||||
"../../yaml-cpp/include",
|
||||
);
|
||||
INSTALL_PATH = /usr/local/lib;
|
||||
PRODUCT_NAME = pinproc;
|
||||
};
|
||||
@@ -233,7 +236,10 @@
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
GCC_MODEL_TUNING = G5;
|
||||
HEADER_SEARCH_PATHS = /usr/local/include;
|
||||
HEADER_SEARCH_PATHS = (
|
||||
/usr/local/include,
|
||||
"../../yaml-cpp/include",
|
||||
);
|
||||
INSTALL_PATH = /usr/local/lib;
|
||||
PRODUCT_NAME = pinproc;
|
||||
};
|
||||
@@ -275,7 +281,11 @@
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
INSTALL_PATH = /usr/local/bin;
|
||||
OTHER_LDFLAGS = "-lftdi";
|
||||
OTHER_LDFLAGS = (
|
||||
"-L../../yaml-cpp/build/bin",
|
||||
"-lyaml-cpp",
|
||||
"-lftdi",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
PRODUCT_NAME = pinproctest;
|
||||
};
|
||||
@@ -290,7 +300,11 @@
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = NO;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
INSTALL_PATH = /usr/local/bin;
|
||||
OTHER_LDFLAGS = "-lftdi";
|
||||
OTHER_LDFLAGS = (
|
||||
"-L../../yaml-cpp/build/bin",
|
||||
"-lyaml-cpp",
|
||||
"-lftdi",
|
||||
);
|
||||
PREBINDING = NO;
|
||||
PRODUCT_NAME = pinproctest;
|
||||
ZERO_LINK = NO;
|
||||
|
||||
@@ -99,6 +99,93 @@ void PRDevice::Reset()
|
||||
// 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)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,7 @@ protected:
|
||||
|
||||
public:
|
||||
// public libpinproc API:
|
||||
PRResult LoadDefaultsFromYAML(const char *yamlFilePath);
|
||||
int GetEvents(PREvent *events, int maxEvents);
|
||||
|
||||
PRResult DriverUpdateGlobalConfig(PRDriverGlobalConfig *driverGlobalConfig);
|
||||
|
||||
@@ -72,6 +72,10 @@ PR_EXPORT void PRDelete(PRHandle handle)
|
||||
delete (PRDevice*)handle;
|
||||
}
|
||||
|
||||
PR_EXPORT PRResult PRLoadDefaultsFromYAML(PRHandle handle, const char *yamlFilePath)
|
||||
{
|
||||
return handleAsDevice->LoadDefaultsFromYAML(yamlFilePath);
|
||||
}
|
||||
|
||||
// Events
|
||||
|
||||
|
||||
Reference in New Issue
Block a user