Version 0.9.1

Datei 'www/global/av_scripts.js' Zurück zur Übersicht
/*
Yamaha RX-V779

How it works

POST a xml

//set vol to -55,5
<YAMAHA_AV cmd="PUT">
<Main_Zone>
<Volume>
<Lvl>
<Val>-555</Val>
<Exp>1</Exp>
<Unit>dB</Unit>
</Lvl>
</Volume>
</Main_Zone>
</YAMAHA_AV>
*/

function av(ip) {
	this.ip = (typeof ip == "undefined")? 'http://192.168.178.21' : 'http://'+ ip;

	this.postXML = function(xml) {
		var url = this.ip +'/YamahaRemoteControl/ctrl',
			data = {XML: xml},
			ajax = {url: url, data: xml, contentType: "text/xml", dataType: "text", type: 'POST', crossDomain: true, cache: false};
			
		$.ajax(ajax);
		console.log(ajax);
	}

	this.postXML = function(xml) {
			var invocation = new XMLHttpRequest(),
				url = this.ip +'/YamahaRemoteControl/ctrl';
			
		  if(invocation)
			{
			  invocation.open('POST', url, true);
			  invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
			  invocation.setRequestHeader('Content-Type', 'application/xml');
			  invocation.onreadystatechange = handler;
			  invocation.send(xml); 
			}
	}

	this.setInput = function(inp) {
		var xml = '<YAMAHA_AV cmd="PUT"><Main_Zone><Input><Input_Sel>'+ inp +'</Input_Sel></Input></Main_Zone></YAMAHA_AV>';
		this.postXML(xml);
	}

	this.setAudioType = function(type) {
		var xml = '<YAMAHA_AV cmd="PUT"><Main_Zone><Surround><Program_Sel><Current><Straight>Off</Straight><Sound_Program>'+ type +'</Sound_Program></Current></Program_Sel></Surround></Main_Zone></YAMAHA_AV>';
		this.postXML(xml);
	}

	this.setPower = function(type) {
		var xml = '<YAMAHA_AV cmd="PUT"><Main_Zone><Power_Control><Power>'+ type +'</Power></Power_Control></Main_Zone></YAMAHA_AV>';
		this.postXML(xml);
	}

	this.setVol = function(vol) {
		var xml = 	'<YAMAHA_AV cmd="PUT">'+
						'<Main_Zone>'+
							'<Volume>'+
								'<Lvl>'+
									'<Val>'+ vol +'</Val>'+
									'<Exp>1</Exp>'+
									'<Unit>dB</Unit>'+
								'</Lvl>'+
							'</Volume>'+
						'</Main_Zone>'+
					'</YAMAHA_AV>';
		
		this.postXML(xml);
	}

	handler = function () {
		console.log(arguments);
	}

	function setVolN(vol) {
		var invocation = new XMLHttpRequest();
		var body = 	'<YAMAHA_AV cmd="PUT">'+
						'<Main_Zone>'+
							'<Volume>'+
								'<Lvl>'+
									'<Val>'+ vol +'</Val>'+
									'<Exp>1</Exp>'+
									'<Unit>dB</Unit>'+
								'</Lvl>'+
							'</Volume>'+
						'</Main_Zone>'+
					'</YAMAHA_AV>',
			url = ip +'/YamahaRemoteControl/ctrl';
			
		  if(invocation)
			{
			  invocation.open('POST', url, true);
			  invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
			  invocation.setRequestHeader('Content-Type', 'application/xml');
			  invocation.onreadystatechange = handler;
			  invocation.send(body); 
			}
	}

	function openMovie() {
		setPower('On');
		setVol(-320);
		setInput('HDMI1');
		setAudioType('Spectacle');
	}

	function openRadio() {
		setPower('On');
		setVol(-500);
		setInput('NET RADIO');
		setAudioType('7ch Stereo');
	}
}