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

// 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

// 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

short GetCardHandle(long* CardHandle, short CardIndex);
short GetRevisionID(long CardHandle, short* RevisionID);
short SetLed (long CardHandle, short LedNumber, short OnOffMode);
short GetLed (long CardHandle, short LedNumber, short* OnOffMode);

// 2. CHIP LEVEL FUNCTIONS

// 2.1 ACTIVE CHIP

short SetActiveChip (long CardHandle, short ChipNumber);
short GetActiveChip (long CardHandle, short* ChipNumber);
short TestActiveChip (long CardHandle);

// 2.2 I/O

short ReadInputs (long CardHandle, short* Inputs, short* EncoderEventFlags);
short WriteOutputs (long CardHandle, short Outputs);

// 3. ENCODER LEVEL FUNCTIONS

// 3.1 RESOLUTION

short SetEncoderResolution (long CardHandle, short EncoderNumber, short ClocksPerCycle);
short GetEncoderResolution (long CardHandle, short EncoderNumber, short* ClocksPerCycle);

// 3.2 INDEX

short SetIndexPulsePolarity (long CardHandle, short EncoderNumber, short Polarity);
short GetIndexPulsePolarity (long CardHandle, short EncoderNumber, short* Polarity);
short SetIndexResetsPositionCounter (long CardHandle, short EncoderNumber, short EnabledDisabledMode);
short GetIndexResetsPositionCounter (long CardHandle, short EncoderNumber, short* EnabledDisabledMode);

// 3.3 SETPOINT

short SetSetPoint (long CardHandle, short EncoderNumber, long SetPoint);
short GetSetPoint (long CardHandle, short EncoderNumber, long* SetPoint);

// 3.4 EVENT SIGNAL

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

// 3.5 POSITION COUNTER

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