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

int pip_reset( void )
{
	int rc;
	IGS_SMSG smsg;
	IGS_RMSG rmsg;

	I2C_Byte Ph02[] = { 0xC3, 3, 0xFF, 0xFF, 0xE8, 0xE7, 0x80, 0x44, 0x80, 0x43, 0x10, 0, 0 },
			 Ph10[] = { 0x80, 0x2C, 0 };

	I2C_Byte Si00[21] = {	0x00,			// frozen, on
							0x00,			// x hi
							0x00,			// x lo
							0x00,			// y
							0x02,			// mode
							0,
							0x1F,
							0,
							0,
							1,
							0,
							0xB,			// frame control
							1,
							0,
							0,
							0x80,
							0,
							0x00,			// wipe on, wipe timer
							0,
							0,
							0 };

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

	switch( pip_type ) {

	case PIP_TYPE_SIEMENS:
		rc = elan_i2c_write( I2C_DEV_SAA7111, 0x02, sizeof(Ph02), Ph02 );
		if( rc < 0 )
			return rc;

		rc = elan_i2c_write( I2C_DEV_SAA7111, 0x10, sizeof(Ph10), Ph10 );
		if( rc < 0 )
			return rc;

		rc = elan_i2c_write( I2C_DEV_SDA9189, 0x00, sizeof(Si00), Si00 );
		if( rc < 0 )
			return rc;

		return 0;
		break;

	case PIP_TYPE_CPRO:
		smsg.type = SET_ABS_PIP;
		smsg.param.pip.x1 = 50;
		smsg.param.pip.y1 = 50;
		smsg.param.pip.x2 = 320;
		smsg.param.pip.y2 = 288;
		smsg.param.pip.source = MUX0;
		smsg.param.pip.colorkey = WINDOWKEY;
		smsg.param.pip.scale = 1;
		smsg.param.pip.standard = PAL;
		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;
}
