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

Minor changes to avoid compilation errors in MSVC

This commit is contained in:
Gerry Stellenberg
2010-12-29 17:21:34 -06:00
parent bd90c25148
commit e08e4cde52
7 changed files with 65 additions and 42 deletions

View File

@@ -64,14 +64,14 @@ void UpdateDots( unsigned char * dots, unsigned int dotOffset )
const int rate_reduction_divisor = 1;
loopCtr = dotOffset/rate_reduction_divisor;
color = pow(2,kDMDSubFrames) - 1;
color = (1 << kDMDSubFrames) - 1;
byte_shifter = 0x80;
// Slow it down just a tad
if (dotOffset%rate_reduction_divisor == 0)
{
// Set up byte_shifter to rotate pattern to the right.
byte_shifter = pow(2,(loopCtr%8));
byte_shifter = 1 << (loopCtr%8);
// Clear the DMD dots every time the rotation occurs
memset(dots,0,((kDMDColumns*kDMDRows)/8)*kDMDSubFrames);
@@ -91,13 +91,13 @@ void UpdateDots( unsigned char * dots, unsigned int dotOffset )
{
// Turn on the byte in each sub-frame that's enabled
// active for the color code.
if ((mappedColor >> subFrame) & 1 == 1)
if (((mappedColor >> subFrame) & 1) == 1)
dots[subFrame*(kDMDColumns*kDMDRows/8)+((row%kDMDRows)*(kDMDColumns / 8))+col] = byte_shifter;
}
}
// Determine where to change the color in order to progress from row 0 = color 0
// to the last row being the last color.
if (row % (int)((kDMDRows/pow(2,kDMDSubFrames))) == 0) color--;
if (row % (int)((kDMDRows/(1 << kDMDSubFrames))) == 0) color--;
if (byte_shifter == 1) byte_shifter = 0x80;
else byte_shifter = byte_shifter >> 1;
}

View File

@@ -89,8 +89,6 @@ void RunLoop(PRHandle proc)
// Retrieve and store initial switch states.
LoadSwitchStates(proc);
uint32_t rdBuffer[1];
if (machineType != kPRMachineWPCAlphanumeric) {
// Send 3 frames
for (i=0; i<3; i++)
@@ -105,9 +103,6 @@ void RunLoop(PRHandle proc)
{
PRDriverWatchdogTickle(proc);
//PRReadData(proc, 5, 0, 1, rdBuffer);
//printf("dmd config: %x\n",rdBuffer[0]);
int numEvents = PRGetEvents(proc, events, maxEvents);
for (int i = 0; i < numEvents; i++)
{
@@ -120,8 +115,13 @@ void RunLoop(PRHandle proc)
case kPREventTypeSwitchOpenNondebounced: stateText = "open(ndb)"; break;
case kPREventTypeSwitchClosedNondebounced: stateText = "closed(ndb)"; break;
}
#ifdef _VC_
struct _timeb tv;
_ftime(&tv);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
#endif
switch (event->type)
{
@@ -130,7 +130,11 @@ void RunLoop(PRHandle proc)
case kPREventTypeSwitchOpenNondebounced:
case kPREventTypeSwitchClosedNondebounced:
{
printf("%d.%03d switch % 3d: %s\n", tv.tv_sec-startTime, tv.tv_usec/1000, event->value, stateText);
#ifdef _VC_
printf("%d.%03d switch % 3d: %s\n", tv.time-startTime, tv.millitm, event->value, stateText);
#else
printf("%d.%03d switch % 3d: %s\n", (int)(tv.tv_sec-startTime), (int)tv.tv_usec/1000, event->value, stateText);
#endif
UpdateSwitchState( event );
break;
}
@@ -148,7 +152,11 @@ void RunLoop(PRHandle proc)
}
}
PRFlushWriteData(proc);
#ifdef _VC_
Sleep(10);
#else
usleep(10*1000); // Sleep for 10ms so we aren't pegging the CPU.
#endif
}
}

View File

@@ -30,12 +30,23 @@
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#ifndef _VC_
#include <unistd.h>
#endif
#include <cmath>
#include "../../include/pinproc.h" // Include libpinproc's header.
#include <fstream>
#include <yaml-cpp/yaml.h>
#include <sys/time.h>
#ifdef _VC_
#include <time.h>
#include <sys/timeb.h>
#include <windows.h>
#else
#include <sys/time.h>
#endif
#define kFlippersSection "PRFlippers"
#define kBumpersSection "PRBumpers"

View File

@@ -238,32 +238,32 @@ PR_EXPORT PRResult PRDriverGroupDisable(PRHandle handle, uint8_t groupNum);
* 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);
PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint8_t driverNum);
/**
* 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, uint8_t milliseconds);
PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds);
/**
* 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);
PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint8_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now);
/**
* 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);
PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint8_t driverNum, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime);
/**
* Assigns a pitter-patter schedule (repeating on/off) to the given driver on for the given duration.
* This function is provided for convenience. See PRDriverStatePulsedPatter() for a full description.
*/
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime);
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint8_t driverNum, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime);
/**
* Assigns a pitter-patter schedule (repeating on/off) to the given driver for the given duration.
* This function is provided for convenience. See PRDriverStatePatter() for a full description.
*/
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime);
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint8_t driverNum, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime);
/**
* Prepares an Aux Command to drive the Aux bus.
* This function is provided for convenience.
@@ -317,14 +317,14 @@ PR_EXPORT void PRDriverStateSchedule(PRDriverState *driverState, uint32_t schedu
*
* 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);
PR_EXPORT void PRDriverStatePatter(PRDriverState *driverState, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime);
/**
* @brief Changes the given #PRDriverState to reflect a pitter-patter schedule state.
* Just like the regular Patter above, but PulsePatter only drives the patter
* scheduled for the given number of milliseconds before disabling the driver.
*/
PR_EXPORT void PRDriverStatePulsedPatter(PRDriverState *driverState, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t patterTime);
PR_EXPORT void PRDriverStatePulsedPatter(PRDriverState *driverState, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t patterTime);
/**
* Write Aux Port commands into the Aux Port command memory.

View File

@@ -32,7 +32,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#ifndef __WIND32__
#include <stdio.h>
#endif
PRDevice::PRDevice(PRMachineType machineType) : machineType(machineType)
{
@@ -264,9 +266,9 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *driverState)
// Note, the driver numbers depend on the driver group settings from DriverLoadMachineTypeDefaults.
// TODO: Create some constants that are used both here and in DriverLoadMachineTypeDefaults.
switch (readMachineType) {
kPRMachineWPC:
kPRMachineWPC95:
kPRMachineWPCAlphanumeric:{
case kPRMachineWPC:
case kPRMachineWPC95:
case kPRMachineWPCAlphanumeric:{
if ((driverState->driverNum >= 40 && driverState->driverNum <= 47) ||
(driverState->driverNum == 32) ||
(driverState->driverNum == 34) ||
@@ -276,8 +278,8 @@ PRResult PRDevice::DriverUpdateState(PRDriverState *driverState)
}
break;
}
kPRMachineSternWhitestar:
kPRMachineSternSAM: {
case kPRMachineSternWhitestar:
case kPRMachineSternSAM: {
if (driverState->driverNum >= 32 && driverState->driverNum <= 47) {
if (driverState->timeslots == 0 && driverState->outputDriveTime == 0) return kPRFailure;
}
@@ -589,7 +591,7 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR
// If more the base rule will link to others, ensure free indexes exists for
// the links.
if (numDrivers > 0 && freeSwitchRuleIndexes.size() < numDrivers-1) // -1 because the first switch rule holds the first driver.
if (numDrivers > 0 && freeSwitchRuleIndexes.size() < (uint32_t)(numDrivers-1)) // -1 because the first switch rule holds the first driver.
{
PRSetLastErrorText("Not enough free switch rule indexes: %d available, need %d", freeSwitchRuleIndexes.size(), numDrivers);
return kPRFailure;
@@ -882,7 +884,7 @@ PRResult PRDevice::PRJTAGGetStatus(PRJTAGStatus * status)
PRResult PRDevice::Open()
{
uint32_t temp_word,i;
uint32_t temp_word;
PRResult res = PRHardwareOpen();
if (res == kPRSuccess)
{
@@ -962,7 +964,7 @@ PRResult PRDevice::VerifyChipID()
{
PRResult rc;
const int bufferWords = 5;
uint32_t buffer[bufferWords];
uint32_t buffer[bufferWords] = {0};
//uint32_t temp_word;
uint32_t max_count, i;
const uint32_t max_count_limit = 10;
@@ -1120,7 +1122,7 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int
// Wait for data to return. Give it 10 loops before giving up.
// Expect numReadWords + 1 word with the address.
while (requestedDataQueue.size() < (numReadWords + 1) && i++ < 10)
while (requestedDataQueue.size() < (uint32_t)((numReadWords + 1)) && i++ < 10)
{
PRSleep (10); // 10 milliseconds should be plenty of time.
if (SortReturningData() != kPRSuccess)
@@ -1130,7 +1132,7 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int
// Make sure all of the requested words are available before processing them.
// Too many words is just as bad as not enough words.
// If too many come back, can they be trusted?
if (requestedDataQueue.size() == numReadWords + 1)
if (requestedDataQueue.size() == (uint32_t)(numReadWords + 1))
{
requestedDataQueue.pop(); // Ignore address word. TODO: Verify the address.
for (i = 0; i < numReadWords; i++)
@@ -1177,7 +1179,7 @@ int32_t PRDevice::ReadData(uint32_t *buffer, int32_t num_words)
PRResult PRDevice::FlushReadBuffer()
{
int32_t numBytes,rc,k;
int32_t numBytes,rc=0,k;
//uint32_t rd_buffer[3];
numBytes = CollectReadData();
k = 0;
@@ -1261,6 +1263,7 @@ PRResult PRDevice::SortReturningData()
int PRDevice::CalcCombinedVerRevision()
{
combinedVersionRevision = (version * 0x10000) + revision;
return 0;
}
int PRDevice::GetVersionInfo(uint16_t *verPtr, uint16_t *revPtr, uint16_t *combinedPtr)
@@ -1268,4 +1271,5 @@ int PRDevice::GetVersionInfo(uint16_t *verPtr, uint16_t *revPtr, uint16_t *combi
*verPtr = version;
*revPtr = revision;
*combinedPtr = combinedVersionRevision;
return 0;
}

View File

@@ -553,11 +553,11 @@ int PRHardwareRead(uint8_t *buffer, int maxBytes)
ftStatus = FT_GetQueueStatus(ftHandle,&bytesToRead);
if (ftStatus != FT_OK) return 0;
if (maxBytes < bytesToRead) bytesToRead = maxBytes;
if ((DWORD)maxBytes < bytesToRead) bytesToRead = maxBytes;
ftStatus = FT_Read(ftHandle, buffer, bytesToRead, &bytesRead);
if (ftStatus == FT_OK) {
DEBUG(PRLog(kPRLogVerbose,"Read %d bytes:\n",bytesRead));
for (i=0; i<bytesRead; i++) {
for (i=0; (DWORD)i<bytesRead; i++) {
DEBUG(PRLog(kPRLogVerbose,"Read byte: %x\n",buffer[i]));
}
return (int)bytesRead;
@@ -578,7 +578,7 @@ int PRHardwareWrite(uint8_t *buffer, int bytes)
DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes:\n",bytesWritten));
if (bytesWritten != bytes) DEBUG(PRLog(kPRLogVerbose,"Wrote %d bytes, should have written %d bytes",bytesWritten,bytes));
else {
for (i=0; i<bytesWritten; i++) {
for (i=0; (DWORD)i<bytesWritten; i++) {
DEBUG(PRLog(kPRLogVerbose,"Wrote byte: %x\n",buffer[i]));
}
}

View File

@@ -175,35 +175,35 @@ PR_EXPORT PRResult PRDriverGroupDisable(PRHandle handle, uint8_t groupNum)
return handleAsDevice->DriverUpdateGroupConfig(&driverGroup);
}
// Driver Helper functions:
PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint16_t driverNum)
PR_EXPORT PRResult PRDriverDisable(PRHandle handle, uint8_t driverNum)
{
PRDriverState driver;
handleAsDevice->DriverGetState(driverNum, &driver);
PRDriverStateDisable(&driver);
return handleAsDevice->DriverUpdateState(&driver);
}
PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint16_t driverNum, uint8_t milliseconds)
PR_EXPORT PRResult PRDriverPulse(PRHandle handle, uint8_t driverNum, uint8_t milliseconds)
{
PRDriverState driver;
handleAsDevice->DriverGetState(driverNum, &driver);
PRDriverStatePulse(&driver, milliseconds);
return handleAsDevice->DriverUpdateState(&driver);
}
PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint16_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now)
PR_EXPORT PRResult PRDriverSchedule(PRHandle handle, uint8_t driverNum, uint32_t schedule, uint8_t cycleSeconds, bool_t now)
{
PRDriverState driver;
handleAsDevice->DriverGetState(driverNum, &driver);
PRDriverStateSchedule(&driver, schedule, cycleSeconds, now);
return handleAsDevice->DriverUpdateState(&driver);
}
PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime)
PR_EXPORT PRResult PRDriverPatter(PRHandle handle, uint8_t driverNum, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime)
{
PRDriverState driver;
handleAsDevice->DriverGetState(driverNum, &driver);
PRDriverStatePatter(&driver, millisecondsOn, millisecondsOff, originalOnTime);
return handleAsDevice->DriverUpdateState(&driver);
}
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint16_t driverNum, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t duration)
PR_EXPORT PRResult PRDriverPulsedPatter(PRHandle handle, uint8_t driverNum, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t duration)
{
PRDriverState driver;
handleAsDevice->DriverGetState(driverNum, &driver);
@@ -296,7 +296,7 @@ PR_EXPORT void PRDriverStateSchedule(PRDriverState *driver, uint32_t schedule, u
driver->patterOffTime = 0;
driver->patterEnable = false;
}
PR_EXPORT void PRDriverStatePatter(PRDriverState *driver, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t originalOnTime)
PR_EXPORT void PRDriverStatePatter(PRDriverState *driver, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t originalOnTime)
{
driver->state = true;
driver->timeslots = 0;
@@ -307,7 +307,7 @@ PR_EXPORT void PRDriverStatePatter(PRDriverState *driver, uint16_t millisecondsO
driver->patterEnable = true;
}
PR_EXPORT void PRDriverStatePulsedPatter(PRDriverState *driver, uint16_t millisecondsOn, uint16_t millisecondsOff, uint16_t patterTime)
PR_EXPORT void PRDriverStatePulsedPatter(PRDriverState *driver, uint8_t millisecondsOn, uint8_t millisecondsOff, uint8_t patterTime)
{
driver->state = false;
driver->timeslots = 0;