/********************************
	i8093 Error Code definition	
*******************************/

#define OK 		 				       0	
#define ID_ERROR 				    -1
#define SLOT_OUT_RANGE			-2
#define CHANNEL_OUT_RANGE		-3
#define MODE_ERROR				  -4
#define FIRMWARENOTSUPPORT  -5

	
#ifdef	__cplusplus  // for C++ compile use
extern "C" {
#endif	/*	__cplusplus	*/


#define i9093_GetFirmwareVersion    i8093W_GetFirmwareVersion
#define i9093_GetLibVersion         i8093W_GetLibVersion
#define i9093_Init                  i8093W_Init
#define i9093_SetMode               i8093W_SetMode
#define i9093_GetMode               i8093W_GetMode
#define i9093_GetLineStatus         i8093W_GetLineStatus
#define i9093_GetIndex              i8093W_GetIndex
#define i9093_SetXOR                i8093W_SetXOR
#define i9093_GetXOR                i8093W_GetXOR
#define i9093_Read32BitEncoder      i8093W_Read32BitEncoder
#define i9093_ResetEncoder          i8093W_ResetEncoder   
#define i9093_SetPresetValue        i8093W_SetPresetValue
#define i9093_GetPresetValue        i8093W_GetPresetValue
#define i9093_SetLowPassFilter      i8093W_SetLowPassFilter
#define i9093_GetLowPassFilter      i8093W_GetLowPassFilter
#define i9093_ClearLatchedIndex     i8093W_ClearLatchedIndex

#define i9093_SetLowPassFilter           i8093W_SetLowPassFilter     //LP-9k only
#define i9093_GetLowPassFilter           i8093W_GetLowPassFilter     //LP-9k only
#define i9093_ReadIndexLatchedPosition   i8093W_ReadIndexLatchedPosition  //LP-9k only
#define i9093_ReadExTrigLatchedPosition  i8093W_ReadExTrigLatchedPosition //LP-9k only
#define i9093_ReadNextPosition           i8093W_ReadNextPosition     //LP-9k only
#define i9093_ClearNextPosition          i8093W_ClearNextPosition    //LP-9k only
#define i9093_SetExTrigMode              i8093W_SetExTrigMode        //LP-9k only
#define i9093_GetExTrigMode              i8093W_GetExTrigMode        //LP-9k only
#define i9093_SetExSignal                i8093W_SetExSignal          //LP-9k only
#define i9093_GetExSignal                i8093W_GetExSignal          //LP-9k only
#define i9093_SetFirstTrigPosition       i8093W_SetFirstTrigPosition //LP-9k only
#define i9093_GetFirstTrigPosition       i8093W_GetFirstTrigPosition //LP-9k only
#define i9093_SetTrigDistance            i8093W_SetTrigDistance      //LP-9k only
#define i9093_GetTrigDistance            i8093W_GetTrigDistance      //LP-9k only
#define i9093_ConfigTriggerOut           i8093W_ConfigTriggerOut     //LP-9k only
#define i9093_GetTriggerOutConfig        i8093W_GetTriggerOutConfig  //LP-9k only



/********************************
	return Lattice version	
*******************************/
short i8093W_GetFirmwareVersion(int slot);


/********************************
	i8093W_GetLibVersion can get the version i8093W Lib
	return Lib version	
*******************************/
short i8093W_GetLibVersion(void);
          
          
/********************************
	i8093W_GetLibDate can get the builded date of i8093W Lib
	1.*LibDate: library date	
*******************************/  
//void i8093W_GetLibDate(char *LibDate);


/********************************
	i8093W_Init can initialize i-8093W
	return value: please refer to i8093W Error Code definition		
*******************************/
int i8093W_Init(int slot);


/********************************
	i8093W_SetMode can set encoder counting mode
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. Mode value:
	   1 ==> CW/CCW counting mode
	   2 ==> Pulse/Direction counting mode
	   3 ==> Quadrant counting mode
	return value: please refer to i8093W Error Code definition
*******************************/
int i8093W_SetMode(int slot, int ch, int Mode);


/********************************
	i8093W_GetMode can get encoder counting mode
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. *Mode value:
	   *Mode=1 ==> CW/CCW counting mode
	   *Mode=2 ==> Pulse/Direction counting mode
	   *Mode=3 ==> Quadrant counting mode

	return value: please refer to i8093W Error Code definition
*******************************/ 
int i8093W_GetMode(int slot, int ch, int* Mode);


/********************************
	i8093W_GetLineStatus can read A/B/Z status
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. *A_Status: 0/1
	4. *B_Status: 0/1
  5. *C_Status: 0/1 
  	
	return value: please refer to i8093W Error Code definition
*******************************/
int i8093W_GetLineStatus(int slot, int ch, int* A_Status,int* B_Status,int* C_Status);


/********************************
	i8093W_GetIndex can read Index(Z) value
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. *index: 0/1

	return value: please refer to i8093W Error Code definition	
*******************************/
int i8093W_GetIndex(int slot, int ch,int* index);


/********************************
	i8093W_SetXOR can set XOR value 
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. Xor: 0/1
	
	return value: please refer to i8093W Error Code definition
*******************************/
int i8093W_SetXOR(int slot, int ch, int Xor);


/********************************
	i8093W_GetXOR can get XOR value
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. *Xor: 0/1
	
	return value: please refer to i8093W Error Code definition
*******************************/
int i8093W_GetXOR(int slot, int ch, int* Xor);


/********************************
	i8093W_Read32BitEncoder can read 32-bit counter value
	1. slot: 1 ~ 8
	2. ch: 0 ~ 2
	3. *EnCode32: 32-bit counter value
	
	return value: return Index enable/disable and Index latched status
	0: Disable Index Latch (0), Index Not Latched (0)
	1: Enable Index Latch  (1), Index Not Latched (0)
	2: Disable Index Latch (0), Index Latched (1)
	3: Enable Index Latch  (1), Index Latched (1)
*******************************/
int i8093W_Read32BitEncoder(int slot,int ch, long* EnCode32);


/********************************
	i8093W_ResetEncoder can clear A/B/Z and 32 bit counter
	1. slot 1 ~ 8
	2. ch 0 ~ 2
*******************************/ 
int i8093W_ResetEncoder(int slot, int ch);


/********************************
 i8093W_SetPresetValue can set the preset value of i-8093W
 1. slot 1 ~ 8 
 2. ch 0 ~ 2 
 3. PresetVal 0 ~ 0xffffffff
 return value: please refer to i8093WW Error Code definition 
 Note1: preset value is supported at lib version 0x1007 or above 
*******************************/ 
int i8093W_SetPresetValue(int slot, int ch, long presetVal);


/********************************
 i8093W_GetPresetValue can get the preset value of i-8093W
 1. slot 1 ~ 8 
 2. ch 0 ~ 2 
 3. PresetVal 0 ~ 0xffffffff
 return value: please refer to i8093WW Error Code definition 
 Note1: preset value is supported at lib version 0x1007 or above 
*******************************/ 
int i8093W_GetPresetValue(int slot, int ch, long* presetVal);




/********************************
 8093W firmware must be 4 or above to support i8093W_SetIndexLatchStatus function
 i8093W_ClearLatchedIndex clear Index Latch status of i-8093
 1. slot 1 ~ 8 
 2. ch 0 ~ 2  

 Note1: normally we can use pac_i8093W_GetIndex to read the index (z ) status, but sometimes it is not easy 
 to let the encoder to match the right position, so 8093W add this function to latch the z index status 
 Note2: if enable the latch index function and the z index latched, the encoder value will also be latched 
 at the position where z index latched point, so we can adjust the encoder position to the latched point.
 Note3: disable the index latch function, pac_i8093W_Read32BitEncoder can read the normal encoder value as usual.
 
 return value: please refer to i8093W Error Code definition  
*******************************/
int i8093W_ClearLatchedIndex(int slot, int ch);



// vvvvvvvvvvvvvvvvvv  for 8093W only  vvvvvvvvvvvvvvvvvvvvvv// 
/********************************
 8093W firmware must be 3 or above to support i8093W_ReadFreq function
 i8093W_ReadFreq read the frequency value of i-8093
 1. slot 1 ~ 8 
 2. ch 0 ~ 2  
 3. Freq  readback frequency of i-8093,
 Note1: if there is no encoder input, the frequency will be 0.093 not 0
 
 return value: please refer to i8093W Error Code definition  
*******************************/ 
int i8093W_ReadFreq(int slot,int ch,float* freq);



/********************************
 8093W firmware must be 4 or above to support i8093W_SetIndexLatchStatus function
 pac_i8093W_SetIndexLatchStatus to disable/enable the index latch function of i-8093
 1. slot 1 ~ 8 
 2. ch 0 ~ 2  
 3. ifEnableLatch  to enable or disable the index latch function of i-8093,
 Note1: normally we can use pac_i8093W_GetIndex to read the index (z ) status, but sometimes it is not easy 
 to let the encoder to match the right position, so 8093W add this function to latch the z index status 
 Note2: if enable the latch index function and the z index latched, the encoder value will also be latched 
 at the position where z index latched point, so we can adjust the encoder position to the latched point.
 Note3: disable the index latch function, pac_i8093W_Read32BitEncoder can read the normal encoder value as usual.
 
 return value: please refer to i8093W Error Code definition  
*******************************/
int i8093W_SetIndexLatchStatus(int slot, int ch, int ifEnableLatch);



/********************************
 8093W firmware must be 4 or above to support i8093W_SetIndexLatchStatus function
 i8093W_GetIndexLatchStatus read the index latched status and enable latch configuration of i-8093
 1. slot 1 ~ 8 
 2. ch 0 ~ 2  
 3. *latchedStatus  check z index latched or not
 4. *ifEnableLatch  readback enable latched  of i-8093,
 Note1: normally we can use pac_i8093W_GetIndex to read the index (z ) status, but sometimes it is not easy 
 to let the encoder to match the right position, so 8093W add this function to latch the z index status 
 Note2: if enable the latch index function and the z index latched, the encoder value will also be latched 
 at the position where z index latched point, so we can adjust the encoder position to the latched point.
 Note3: disable the index latch function, pac_i8093W_Read32BitEncoder can read the normal encoder value as usual.
 
 return value: please refer to i8093W Error Code definition  
*******************************/
int i8093W_GetIndexLatchStatus(int slot, int ch, int* latchedStatus, int* ifEnableLatch);




// vvvvvvvvvvvvvvvvvv   for 9093 only  vvvvvvvvvvvvvvvvvvvvv// 
/********************************
 i8093W_SetPresetValue can set the preset value of i-8093W
 1. slot 1 ~ 8 
 2. ch 0 ~ 2 
 3. PresetVal 0 ~ 0xffffffff
 return value: please refer to i8093WW Error Code definition 
 Note1: preset value is supported at lib version 0x1007 or above 
*******************************/ 
int i8093W_SetLowPassFilter(int slot, int ch, int filter);


/********************************
 i8093W_GetPresetValue can get the preset value of i-8093W
 1. slot 1 ~ 8 
 2. ch 0 ~ 2 
 3. PresetVal 0 ~ 0xffffffff
 return value: please refer to i8093WW Error Code definition 
 Note1: preset value is supported at lib version 0x1007 or above 
*******************************/ 
int i8093W_GetLowPassFilter(int slot, int ch, int* filter);
int i8093W_ReadIndexLatchedPosition(int slot,int ch,long* Data32);
int i8093W_ReadExTrigLatchedPosition(int slot,int ch,long* Data32);
int i8093W_ReadNextPosition(int slot,int ch,long* Data32);
int i8093W_ClearNextPosition(int slot,int ch);

int i8093W_SetExTrigMode(int slot, int ch, unsigned char Mode);
int i8093W_GetExTrigMode(int slot, int ch, unsigned char *Mode);

int i8093W_SetExSignal(int slot, unsigned char Edge);
int i8093W_GetExSignal(int slot, unsigned char *Edge);
int i8093W_SetFirstTrigPosition(int slot, int ch, long Position);
int i8093W_GetFirstTrigPosition(int slot, int ch, long* Position);
int i8093W_SetTrigDistance(int slot, int ch,int dir, long distance);//dir:??  ?I-9093?Àe  ??  ? 
int i8093W_GetTrigDistance(int slot, int ch,int* dir, long* distance);
int i8093W_ConfigTriggerOut(int slot,int ch, unsigned char enStatus);
int i8093W_GetTriggerOutConfig(int slot, int ch, unsigned char *enStatus);

#ifdef	__cplusplus
}
#endif	/*	__cplusplus	*/
