mirror of
https://github.com/preble/libpinproc
synced 2026-02-22 18:15:25 +01:00
resolved merge conflicts
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
|
||||
|
||||
|
||||
@@ -306,6 +306,7 @@ int main(const char **argv, int argc)
|
||||
return 1;
|
||||
|
||||
printf("Configuring P-ROC...\n");
|
||||
PRLoadDefaultsFromYAML(proc, "../../examples/pinproctest/Example.yaml");
|
||||
|
||||
ConfigureDMD(proc);
|
||||
ConfigureSwitches(proc); // Notify host for all debounced switch events.
|
||||
|
||||
@@ -56,9 +56,7 @@
|
||||
#define PR_EXTERN_C_END
|
||||
#endif
|
||||
#endif
|
||||
/** @endcond */
|
||||
|
||||
/** @cond */
|
||||
PR_EXTERN_C_BEGIN
|
||||
/** @endcond */
|
||||
|
||||
@@ -76,6 +74,11 @@ typedef void * PRHandle; /**< Opaque type used to reference an individual P-
|
||||
typedef void (*PRLogCallback)(const char *text); /**< Function pointer type for a custom logging callback. See: PRLogSetCallback(). */
|
||||
PR_EXPORT void PRLogSetCallback(PRLogCallback callback); /**< Replaces the default logging handler with the given callback function. */
|
||||
|
||||
/**
|
||||
* @defgroup device Device Creation & Deletion
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef enum PRMachineType {
|
||||
kPRMachineInvalid = 0,
|
||||
kPRMachineCustom = 1,
|
||||
@@ -88,29 +91,14 @@ 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);
|
||||
|
||||
// Events
|
||||
// Closed == 0, Open == 1
|
||||
typedef enum PREventType {
|
||||
kPREventTypeInvalid = 0,
|
||||
kPREventTypeSwitchClosedDebounced = 1, /**< The switch has gone from open to closed and the signal has been debounced. */
|
||||
kPREventTypeSwitchOpenDebounced = 2, /**< The switch has gone from closed to open and the signal has been debounced. */
|
||||
kPREventTypeSwitchClosedNondebounced = 3, /**< The switch has gone from open to closed and the signal has not been debounced. */
|
||||
kPREventTypeSwitchOpenNondebounced = 4, /**< The switch has gone from closed to open and the signal has not been debounced. */
|
||||
kPREventTypetLast = kPREventTypeSwitchOpenNondebounced
|
||||
} PREventType;
|
||||
|
||||
typedef struct PREvent {
|
||||
PREventType type; /**< The type of event that has occurred. Usually a switch event at this point. */
|
||||
uint32_t value; /**< For switch events, the switch number that has changed. */
|
||||
uint32_t time; /**< Time (in milliseconds) that this event occurred. */
|
||||
} PREvent;
|
||||
|
||||
/** Get all of the available events that have been received. */
|
||||
PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents);
|
||||
|
||||
/** @} */ // End of Device Creation & Deletion
|
||||
|
||||
// Drivers
|
||||
/** @defgroup drivers Driver Manipulation
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct PRDriverGlobalConfig {
|
||||
bool_t enableOutputs; // Formerly enable_direct_outputs
|
||||
@@ -160,43 +148,95 @@ PR_EXPORT PRResult PRDriverGetGroupConfig(PRHandle handle, uint8_t groupNum, PRD
|
||||
PR_EXPORT PRResult PRDriverUpdateGroupConfig(PRHandle handle, PRDriverGroupConfig *driverGroupConfig);
|
||||
|
||||
PR_EXPORT PRResult PRDriverGetState(PRHandle handle, uint8_t driverNum, PRDriverState *driverState);
|
||||
/** Sets the state of the given driver (lamp, coil, etc.). */
|
||||
/**
|
||||
* @brief Sets the state of the given driver (lamp or coil).
|
||||
*/
|
||||
PR_EXPORT PRResult PRDriverUpdateState(PRHandle handle, PRDriverState *driverState);
|
||||
|
||||
// Driver Helper functions:
|
||||
|
||||
/** Disables (turns off) the given driver. */
|
||||
/**
|
||||
* Disables (turns off) the given driver.
|
||||
* This function is provided for convenience. See PRDriverStateDisable() for a full description.
|
||||
*/
|
||||
PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint16_t driverNum);
|
||||
/** Pulses the given driver for a number of milliseconds. */
|
||||
/**
|
||||
* Pulses the given driver for a number of milliseconds.
|
||||
* This function is provided for convenience. See PRDriverStatePulse() for a full description.
|
||||
*/
|
||||
PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint16_t driverNum, int milliseconds);
|
||||
/** Assigns a repeating schedule to the given driver. */
|
||||
/**
|
||||
* Assigns a repeating schedule to the given driver.
|
||||
* This function is provided for convenience. See PRDriverStateSchedule() for a full description.
|
||||
*/
|
||||
PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint16_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now);
|
||||
/** Assigns a pitter-patter schedule (repeating on/off) to the given driver. */
|
||||
/**
|
||||
* Assigns a pitter-patter schedule (repeating on/off) to the given driver.
|
||||
* This function is provided for convenience. See PRDriverStatePatter() for a full description.
|
||||
*/
|
||||
PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime);
|
||||
/** Tickle the watchdog timer. */
|
||||
PR_EXPORT PRResult PRDriverWatchdogTickle(PRHandle handle);
|
||||
|
||||
/** Disables (turns off) the given driver. */
|
||||
/**
|
||||
* Changes the given #PRDriverState to reflect a disabled state.
|
||||
* @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect.
|
||||
*/
|
||||
PR_EXPORT void PRDriverStateDisable(PRDriverState *driverState);
|
||||
/** Pulses the given driver for a number of milliseconds. */
|
||||
/**
|
||||
* Changes the given #PRDriverState to reflect a pulse state.
|
||||
* @param milliseconds Number of milliseconds to pulse the driver for.
|
||||
* @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect.
|
||||
*/
|
||||
PR_EXPORT void PRDriverStatePulse(PRDriverState *driverState, int milliseconds);
|
||||
/** Assigns a repeating schedule to the given driver. */
|
||||
/**
|
||||
* Changes the given #PRDriverState to reflect a scheduled state.
|
||||
* Assigns a repeating schedule to the given driver.
|
||||
* @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect.
|
||||
*/
|
||||
PR_EXPORT void PRDriverStateSchedule(PRDriverState *driverState, uint32_t schedule, uint8_t cycleSeconds, bool_t now);
|
||||
/** Assigns a pitter-patter schedule (repeating on/off) to the given driver. */
|
||||
/**
|
||||
* @brief Changes the given #PRDriverState to reflect a pitter-patter schedule state.
|
||||
* Assigns a pitter-patter schedule (repeating on/off) to the given driver.
|
||||
* @note The driver state structure must be applied using PRDriverUpdateState() or linked to a switch rule using PRSwitchesUpdateRule() to have any effect.
|
||||
*
|
||||
* Use originalOnTime to pulse the driver for a number of milliseconds before the pitter-patter schedule begins.
|
||||
*/
|
||||
PR_EXPORT void PRDriverStatePatter(PRDriverState *driverState, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime);
|
||||
|
||||
|
||||
/** @} */ // End of Drivers
|
||||
|
||||
// Switches
|
||||
|
||||
/** @defgroup switchconsts Switch Constants
|
||||
/** @defgroup switches Switches and Events
|
||||
* @{
|
||||
*/
|
||||
|
||||
// Events
|
||||
// Closed == 0, Open == 1
|
||||
typedef enum PREventType {
|
||||
kPREventTypeInvalid = 0,
|
||||
kPREventTypeSwitchClosedDebounced = 1, /**< The switch has gone from open to closed and the signal has been debounced. */
|
||||
kPREventTypeSwitchOpenDebounced = 2, /**< The switch has gone from closed to open and the signal has been debounced. */
|
||||
kPREventTypeSwitchClosedNondebounced = 3, /**< The switch has gone from open to closed and the signal has not been debounced. */
|
||||
kPREventTypeSwitchOpenNondebounced = 4, /**< The switch has gone from closed to open and the signal has not been debounced. */
|
||||
kPREventTypetLast = kPREventTypeSwitchOpenNondebounced
|
||||
} PREventType;
|
||||
|
||||
typedef struct PREvent {
|
||||
PREventType type; /**< The type of event that has occurred. Usually a switch event at this point. */
|
||||
uint32_t value; /**< For switch events, the switch number that has changed. */
|
||||
uint32_t time; /**< Time (in milliseconds) that this event occurred. */
|
||||
} PREvent;
|
||||
|
||||
/** Get all of the available events that have been received. */
|
||||
PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents);
|
||||
|
||||
|
||||
#define kPRSwitchPhysicalFirst (0) /**< Switch number of the first physical switch. */
|
||||
#define kPRSwitchPhysicalLast (223) /**< Switch number of the last physical switch. */
|
||||
#define kPRSwitchVirtualFirst (224) /**< Switch number of the first virtual switch. */
|
||||
#define kPRSwitchVirtualLast (255) /**< Switch number of the last virtual switch. */
|
||||
/** @} */
|
||||
|
||||
typedef struct PRSwitchRule {
|
||||
bool_t notifyHost; /**< If true this switch change event will provided to the user via PRGetEvents(). */
|
||||
@@ -205,9 +245,12 @@ typedef struct PRSwitchRule {
|
||||
/**
|
||||
* @brief Configures the handling of switch rules within P-ROC.
|
||||
*
|
||||
* P-ROC's switch event system allows the user to receive and act upon events specific to the individual switch's application.
|
||||
* For example, P-ROC can provide debounced switch events to software by means of the PRGetEvents() call (to create
|
||||
* a lane change behavior). The same switch can also be configured with a non-debounced rule to fire a flipper coil.
|
||||
* P-ROC's switch rule system allows the user to decide which switch events are returned to software,
|
||||
* as well as optionally linking one or more driver state changes to rules to create immediate feedback (such as in pop bumpers).
|
||||
*
|
||||
* For instance, P-ROC can provide debounced switch events for a flipper button so software can apply lange change behavior.
|
||||
* This is accomplished by configuring the P-ROC with a switch rule for the flipper button and then receiving the events via the PRGetEvents() call.
|
||||
* The same switch can also be configured with a non-debounced rule to fire a flipper coil.
|
||||
* Multiple driver changes can be tied to a single switch state transition to create more complicated effects: a slingshot
|
||||
* switch that fires the slingshot coil, a flash lamp, and a score event.
|
||||
*
|
||||
@@ -219,14 +262,14 @@ typedef struct PRSwitchRule {
|
||||
*
|
||||
* @section Examples
|
||||
*
|
||||
* Configuring a basic switch rule with no driver state changes that will appear in PRGetEvents():
|
||||
* Configuring a basic switch rule to simply notify software via PRGetEvents() without affecting any coil/lamp drivers:
|
||||
* @code
|
||||
* PRSwitchRule rule;
|
||||
* rule.notifyHost = true;
|
||||
* PRSwitchesUpdateRule(handle, switchNum, kPREventTypeSwitchOpenDebounced, &rule, NULL, 0);
|
||||
* @endcode
|
||||
*
|
||||
* Configuring a pop bumper switch to pulse the coil and a flash lamp:
|
||||
* Configuring a pop bumper switch to pulse the coil and a flash lamp for 50ms each:
|
||||
* @code
|
||||
* // Configure a switch rule to fire the coil and flash lamp:
|
||||
* PRSwitchRule rule;
|
||||
@@ -236,11 +279,11 @@ typedef struct PRSwitchRule {
|
||||
* PRDriverGetState(handle, drvFlashLamp1, &drivers[1]);
|
||||
* PRDriverStatePulse(&drivers[0], 50);
|
||||
* PRDriverStatePulse(&drivers[1], 50);
|
||||
* PRSwitchesUpdateRule(handle, drvSwPopBumper1, kPREventTypeSwitchClosedNondebounced,
|
||||
* PRSwitchesUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedNondebounced,
|
||||
* &rule, drivers, 2);
|
||||
* // Now configure a switch rule to process scoring in software:
|
||||
* rule.notifyHost = false;
|
||||
* PRSwitchesUpdateRule(handle, drvSwPopBumper1, kPREventTypeSwitchClosedDebounced,
|
||||
* rule.notifyHost = true;
|
||||
* PRSwitchesUpdateRule(handle, swPopBumper1, kPREventTypeSwitchClosedDebounced,
|
||||
* &rule, NULL, 0);
|
||||
* @endcode
|
||||
*
|
||||
@@ -253,10 +296,14 @@ typedef struct PRSwitchRule {
|
||||
*/
|
||||
PR_EXPORT PRResult PRSwitchesUpdateRule(PRHandle handle, uint8_t switchNum, PREventType eventType, PRSwitchRule *rule, PRDriverState *linkedDrivers, int numDrivers);
|
||||
|
||||
|
||||
/** @} */ // End of Switches & Events
|
||||
|
||||
// DMD
|
||||
|
||||
/**
|
||||
* @defgroup dmd DMD Control
|
||||
* @{
|
||||
*/
|
||||
typedef struct PRDMDConfig {
|
||||
uint8_t numRows;
|
||||
uint16_t numColumns;
|
||||
@@ -273,8 +320,16 @@ PR_EXPORT int32_t PRDMDUpdateConfig(PRHandle handle, PRDMDConfig *dmdConfig);
|
||||
/** Updates the DMD frame buffer with the given data. */
|
||||
PR_EXPORT PRResult PRDMDDraw(PRHandle handle, uint8_t * dots);
|
||||
|
||||
/** @} */ // End of DMD
|
||||
|
||||
/** @cond */
|
||||
PR_EXTERN_C_END
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @mainpage libpinproc API Documentation
|
||||
*
|
||||
* This is the documentation for libpinproc, the P-ROC Layer 1 API.
|
||||
*/
|
||||
|
||||
#endif // _PINPROC_H_
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
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 */
|
||||
@@ -36,6 +37,7 @@
|
||||
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 = "<group>"; };
|
||||
668249EC0FC0A4CD0051560E /* PRHardware.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PRHardware.cpp; path = src/PRHardware.cpp; sourceTree = "<group>"; };
|
||||
66824DAD0FC6FC690051560E /* PRConfig.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PRConfig.cpp; path = src/PRConfig.cpp; sourceTree = "<group>"; };
|
||||
D2AAC046055464E500DB518D /* libpinproc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpinproc.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -93,6 +95,7 @@
|
||||
668249390FC07B2A0051560E /* pinproc.cpp */,
|
||||
668249400FC07D900051560E /* PRDevice.h */,
|
||||
668249410FC07D900051560E /* PRDevice.cpp */,
|
||||
66824DAD0FC6FC690051560E /* PRConfig.cpp */,
|
||||
6682494A0FC0870B0051560E /* PRHardware.h */,
|
||||
668249EC0FC0A4CD0051560E /* PRHardware.cpp */,
|
||||
);
|
||||
@@ -198,6 +201,7 @@
|
||||
6682493A0FC07B2A0051560E /* pinproc.cpp in Sources */,
|
||||
668249430FC07D900051560E /* PRDevice.cpp in Sources */,
|
||||
668249ED0FC0A4CD0051560E /* PRHardware.cpp in Sources */,
|
||||
66824DAE0FC6FC690051560E /* PRConfig.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -221,7 +225,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 +240,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 +285,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 +304,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;
|
||||
|
||||
108
src/PRConfig.cpp
Normal file
108
src/PRConfig.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 <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);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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