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

Merge branch 'switch_dev'

This commit is contained in:
gstellenberg
2009-05-31 11:26:01 -05:00
9 changed files with 153 additions and 9 deletions

View File

@@ -99,4 +99,5 @@ void UpdateDots( unsigned char * dots, unsigned int dotOffset )
else byte_shifter = byte_shifter >> 1;
}
}
}
}

View File

@@ -84,6 +84,9 @@ void RunLoop(PRHandle proc)
unsigned char dots[4*((128*32)/8)];
unsigned int dotOffset = 0;
// Retrieve and store initial switch states.
LoadSwitchStates(proc);
while (runLoopRun)
{
PRDriverWatchdogTickle(proc);
@@ -107,6 +110,7 @@ void RunLoop(PRHandle proc)
struct timeval tv;
gettimeofday(&tv, NULL);
printf("%d.%03d switch % 3d: %s\n", tv.tv_sec-startTime, tv.tv_usec/1000, event->value, stateText);
UpdateSwitchState( event );
}
PRFlushWriteData(proc);
usleep(10*1000); // Sleep for 10ms so we aren't pegging the CPU.

View File

@@ -54,6 +54,8 @@ void ConfigureDrivers(PRHandle proc, PRMachineType machineType, YAML::Node& yaml
void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc);
void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc);
void UpdateSwitchState (PREvent * event);
void LoadSwitchStates (PRHandle proc);
void ConfigureDMD(PRHandle proc);
void UpdateDots(unsigned char * dots, unsigned int dotOffset);

View File

@@ -24,6 +24,12 @@
*/
#include "pinproctest.h"
typedef struct SwitchStatus {
PREventType state;
uint32_t lastEventTime;
} SwitchStatus;
static SwitchStatus switches[kPRSwitchPhysicalLast + 1];
void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc)
{
@@ -36,6 +42,13 @@ void ConfigureSwitches(PRHandle proc, YAML::Node& yamlDoc)
switchConfig.pulsesPerBurst = 6;
switchConfig.pulseHalfPeriodTime = 13; // milliseconds
PRSwitchUpdateConfig(proc, &switchConfig);
// Go through the switches array and reset the current status of each switch
for (int i = 0; i <= kPRSwitchPhysicalLast; i++)
{
switches[i].state = kPREventTypeInvalid;
switches[i].lastEventTime = 0;
}
}
void ConfigureWPCFlipperSwitchRule (PRHandle proc, int swNum, int mainCoilNum, int holdCoilNum, int pulseTime)
@@ -106,4 +119,43 @@ void ConfigureSwitchRules(PRHandle proc, YAML::Node& yamlDoc)
yamlDoc[kCoilsSection][bumperName][kNumberField] >> coilNum;
ConfigureBumperRule (proc, swNum, coilNum, kBumperPulseTime);
}
}
}
void UpdateSwitchState( PREvent * event )
{
switches[event->value].state = event->type;
switches[event->value].lastEventTime = event->time;
}
void LoadSwitchStates( PRHandle proc )
{
int i;
PREventType procSwitchStates[kPRSwitchPhysicalLast + 1];
// Get all of the switch states from the P-ROC.
if (PRSwitchGetStates( proc, procSwitchStates, kPRSwitchPhysicalLast + 1 ) == kPRFailure)
{
fprintf(stderr, "Error: Unable to retrieve switch states\n");
}
else
{
// Copy the returning states into the local switches array.
for (i = 0; i <= kPRSwitchPhysicalLast; i++)
{
switches[i].state = procSwitchStates[i];
}
fprintf(stderr, "\nCurrent Switch States: 0 : ");
for (i = 0; i < kPRSwitchPhysicalLast + 1; i++)
{
fprintf(stderr, "%d ", switches[i].state);
if ((i + 1) % 32 == 0)
{
printf("\n");
if (i != kPRSwitchPhysicalLast)
fprintf(stderr, "Current Switch States: %d : ", i);
}
}
fprintf(stderr, "\n");
}
}