#include <stdio.h>
#include "pip_lib.h"
#include "pipclient.h"
#include "imports/elan_lib.h"


int pip_setpos( int x, int y )
{
	I2C_Byte data[3];
	int rc;
	IGS_SMSG smsg;
	IGS_RMSG rmsg;

	rc = FindPip();
	if( rc ) return rc;

	switch( pip_type ) {

	case PIP_TYPE_SIEMENS:
		// correct for upper left corner and lores pixels
		x = x + 82;
		y = (y+72)>>1;

		data[0] = (x>>8)&0x03;
		data[1] = x&0xFF;
		data[2] = y&0xFF;
		rc = elan_i2c_write( I2C_DEV_SDA9189, 0x01, 3, data );
		if( rc < 0 )
			return rc;
		else
			return 0;
		break;

	case PIP_TYPE_CPRO:
		smsg.type = SET_PIP_POS;
		smsg.param.pip_pos.x = x;
		smsg.param.pip_pos.y = y;
		rc = Send( CPro_Server, &smsg, &rmsg, sizeof(smsg), sizeof(rmsg) );
		if( rc == -1 || rmsg.status ) return PIP_ERROR;
		return 0;
		break;
	}

	return PIP_ERROR_WRONG_TYPE;
}
