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

Initial commit.

This commit is contained in:
Adam Preble
2009-05-19 21:08:38 -04:00
commit 0a0756c2b5
13 changed files with 3633 additions and 0 deletions

142
src/pinproc.cpp Normal file
View File

@@ -0,0 +1,142 @@
/*
* 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.
*/
/*
* pinproc.cpp
* libpinproc
*/
#include "../include/pinproc.h"
#include "PRDevice.h"
typedef void (*PRLogCallback)(const char *text);
PRLogCallback logCallback = NULL;
void PRLog(const char *format, ...)
{
const int maxLogLineLength = 1024;
char line[maxLogLineLength];
va_list ap;
va_start(ap, format);
vsnprintf(line, maxLogLineLength, format, ap);
if (logCallback)
logCallback(line);
else
fprintf(stderr, line);
}
void PRLogSetCallback(PRLogCallback callback)
{
logCallback = callback;
}
#define handleAsDevice ((PRDevice*)handle)
/** 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. */
PR_EXPORT PRHandle PRCreate(PRMachineType machineType)
{
PRDevice *device = PRDevice::Create(machineType);
if (device == NULL)
return kPRHandleInvalid;
else
return device;
}
/** Destroys an existing P-ROC device handle. */
PR_EXPORT void PRDelete(PRHandle handle)
{
if (handle != kPRHandleInvalid)
delete (PRDevice*)handle;
}
// Events
/** Get all of the available events that have been received. */
PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents)
{
return handleAsDevice->GetEvents(eventsOut, maxEvents);
}
// Drivers
PR_EXPORT PRResult PRDriverUpdateGlobalConfig(PRHandle handle, PRDriverGlobalConfig *driverGlobalConfig)
{
return handleAsDevice->DriverUpdateGlobalConfig(driverGlobalConfig);
}
PR_EXPORT PRResult PRDriverGetGroupConfig(PRHandle handle, uint8_t groupNum, PRDriverGroupConfig *driverGroupConfig)
{
return handleAsDevice->DriverGetGroupConfig(groupNum, driverGroupConfig);
}
PR_EXPORT PRResult PRDriverUpdateGroupConfig(PRHandle handle, PRDriverGroupConfig *driverGroupConfig)
{
return handleAsDevice->DriverUpdateGroupConfig(driverGroupConfig);
}
PR_EXPORT PRResult PRDriverGetState(PRHandle handle, uint8_t driverNum, PRDriverState *driverState)
{
return handleAsDevice->DriverGetState(driverNum, driverState);
}
PR_EXPORT PRResult PRDriverUpdateState(PRHandle handle, PRDriverState *driverState)
{
return handleAsDevice->DriverUpdateState(driverState);
}
// Driver Helper functions:
PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint16_t driverNum)
{
return handleAsDevice->DriverDisable(driverNum);
}
PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint16_t driverNum, int milliseconds)
{
return handleAsDevice->DriverPulse(driverNum, milliseconds);
}
PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint16_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now)
{
return handleAsDevice->DriverSchedule(driverNum, schedule, cycleSeconds, now);
}
PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime)
{
return handleAsDevice->DriverPatter(driverNum, millisecondsOn, millisecondsOff, originalOnTime);
}
// Switches
PR_EXPORT PRResult PRSwitchesUpdateRules(PRHandle handle, PRSwitchRule *rules, int numRules)
{
return handleAsDevice->SwitchesUpdateRules(rules, numRules);
}
PR_EXPORT int32_t PRDMDUpdateGlobalConfig(PRHandle handle, PRDMDGlobalConfig *dmdGlobalConfig)
{
return handleAsDevice->DMDUpdateGlobalConfig(dmdGlobalConfig);
}
PR_EXPORT PRResult PRDMDDraw(PRHandle handle, uint8_t * dots, uint16_t columns, uint8_t rows, uint8_t numSubFrames)
{
return handleAsDevice->DMDDraw(dots, columns, rows, numSubFrames);
}