// ARGUMENTS
// =========

// CardNumber:
// 0-15, according to jumper setting.

// ChipNumber:
#define Chip1 1 // Standard chip (always should be present).
#define Chip2 2 // Optional chip.

// EncoderNumber:
// The codes of EncoderNumber are of three types:
// Type 1 codes (one encoder):
//    Available for all the functions using EncoderNumber.
// Type 2 codes (pair of encoders):
//    Available only for ResetPositionCounter and RequestPositionCounter.
// Type 3 code (all four encoders):
//    Available only for RequestPositionCounter.

// Type 1 EncoderNumber codes (one encoder):
#define Encoder1 1 // First  encoder in the selected chip (A or C).
#define Encoder2 2 // Second encoder in the selected chip (B or D).
// Type 2 EncoderNumber codes (pair of encoders):
#define Encoder3 3 // Both encoders in the selected chip (A+B or C+D).
// Type 3 EncoderNumber codes (all 4 encoders):
#define Encoder4 4 // All 4 encoders (A+B+C+D).

// LedNumber:
#define LedYellow 1
#define LedRed 2

// ClocksPerCycle:
#define Clock1 1 // One clock per cycle.
#define Clock2 2 // Two clocks per cycle.
#define Clock4 4 // Four clocks per cycle.

// EventFlagSource:
#define EventFlagSourceNone 1
#define EventFlagSourceSetPoint 2
#define EventFlagSourceOverflow 3
#define EventFlagSourceIndex 4

// InterruptSource:
#define InterruptSourceEncoder1Event 1
        // Event Signal in the first  encoder in the selected chip (A or C).
#define InterruptSourceEncoder2Event 2
        // Event Signal in the second encoder in the selected chip (B or D).
#define InterruptSourceChipInput0 3 // Input #0 in the selected chip.
#define InterruptSourceChipInput1 4 // Input #1 in the selected chip.
#define InterruptSourceChipInput2 5 // Input #2 in the selected chip.
#define InterruptSourceChipInput3 6 // Input #3 in the selected chip.
#define InterruptSourceChipInput4 7 // Input #4 in the selected chip.
#define InterruptSourceVoltageFailureOrChip2Input5 8
        // For Chip #1: Voltage Failure indication (1 = Failure).
        // For Chip #2: Input #5

// OnOffMode:
#define TurnOn 1
#define TurnOff 0

// EnabledDisabledMode:
#define SetEnabled 1
#define SetDisabled 0

// Polarity
#define ActiveOnHigh 1
#define ActiveOnLow 0

// HEADERS:

#define BOOLEAN int


// 1. CARD LEVEL FUNCTIONS

BOOLEAN SetLed (short CardNumber, short LedNumber, short OnOffMode);
BOOLEAN GetLed (short CardNumber, short LedNumber, short* OnOffMode);

// 2. CHIP LEVEL FUNCTIONS

// 2.1 ACTIVE CHIP

BOOLEAN SetActiveChip (short CardNumber, short ChipNumber);
BOOLEAN GetActiveChip (short CardNumber, short* ChipNumber);
BOOLEAN TestActiveChip (short CardNumber);

// 2.2 I/O

BOOLEAN ReadInputs (short CardNumber, short* Inputs, short* EncoderEventFlags);
BOOLEAN WriteOutputs (short CardNumber, short Outputs);

// 2.3 INTERRUPT

BOOLEAN SetInterruptMode (short CardNumber, short EnabledDisabledMode);
BOOLEAN GetInterruptMode (short CardNumber, short* EnabledDisabledMode);
BOOLEAN SetInterruptPolarity (short CardNumber, short Polarity);
BOOLEAN GetInterruptPolarity (short CardNumber, short* Polarity);
BOOLEAN SetInterruptSource (short CardNumber, short InterruptSource);
BOOLEAN GetInterruptSource (short CardNumber, short* InterruptSource);

// 3. ENCODER LEVEL FUNCTIONS

// 3.1 RESOLUTION

BOOLEAN SetEncoderResolution (short CardNumber, short EncoderNumber, short ClocksPerCycle);
BOOLEAN GetEncoderResolution (short CardNumber, short EncoderNumber, short* ClocksPerCycle);

// 3.2 INDEX

BOOLEAN SetIndexPulsePolarity (short CardNumber, short EncoderNumber, short Polarity);
BOOLEAN GetIndexPulsePolarity (short CardNumber, short EncoderNumber, short* Polarity);
BOOLEAN SetIndexResetsPositionCounter (short CardNumber, short EncoderNumber, short EnabledDisabledMode);
BOOLEAN GetIndexResetsPositionCounter (short CardNumber, short EncoderNumber, short* EnabledDisabledMode);

// 3.3 SETPOINT

BOOLEAN SetSetPoint (short CardNumber, short EncoderNumber, long SetPoint);
BOOLEAN GetSetPoint (short CardNumber, short EncoderNumber, long* SetPoint);

// 3.4 EVENT SIGNAL

BOOLEAN SetEncoderEventFlagSource (short CardNumber, short EncoderNumber, short EventFlagSource);
BOOLEAN GetEncoderEventFlagSource (short CardNumber, short EncoderNumber, short* EventFlagSource);
BOOLEAN SetEncoderEventFlagPolarity (short CardNumber, short EncoderNumber, short Polarity);
BOOLEAN GetEncoderEventFlagPolarity (short CardNumber, short EncoderNumber, short* Polarity);
BOOLEAN SetHoldEncoderEventFlag (short CardNumber, short EncoderNumber, short OnOffMode);
BOOLEAN GetHoldEncoderEventFlag (short CardNumber, short EncoderNumber, short* OnOffMode);
BOOLEAN ClearEncoderEventFlag (short CardNumber, short EncoderNumber);

// 3.5 POSITION COUNTER

BOOLEAN ResetPositionCounter (short CardNumber, short EncoderNumber, short OutputsMirror);
BOOLEAN RequestPositionCounter (short CardNumber, short EncoderNumber, short OutputsMirror);
BOOLEAN ReadPositionCounter (short CardNumber, short EncoderNumber, long* PositionCounter);

