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

// HUGE   = 1/4 size  (288x252)
// BIG    = 1/9 size  (192x168)
// MEDIUM = 1/16 size (144x126)
// SMALL  = 1/36 size (96x84)


int pip_setsize( int sx, int sy )
{
	I2C_Byte data[2];
	int rc;
	IGS_SMSG smsg;
	IGS_RMSG rmsg;

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

	switch( pip_type ) {

	case PIP_TYPE_SIEMENS:
		if( sx <= 96 )              data[0] = SDA9189_MODE_1X1_SMALL;
		if( sx > 96 && sx <= 144 )  data[0] = SDA9189_MODE_1X1_MEDIUM;
		if( sx > 144 && sx <= 192 ) data[0] = SDA9189_MODE_1X1_BIG;
		if( sx > 192 )              data[0] = SDA9189_MODE_1X1_HUGE;

		data[1] = 0x00;

		rc = elan_i2c_write( I2C_DEV_SDA9189, 0x04, 2, &data );
		if( rc < 0 )
			return rc;
		else
			return 0;
		break;

	case PIP_TYPE_CPRO:
		smsg.type = SET_PIP_SIZE;
		smsg.param.pip_size.x = sx;
		smsg.param.pip_size.y = sy;
		smsg.param.pip_size.scale = 1;
		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;
}
