<html>
<body>

<?php
require_once("MiMicCore.php");
require_once("MiMicRemoteMcuInterface.php");
require_once("MiMic_LPC1769.php");
require_once("MiMic_LPCXpresso1769.php");
require_once("MiMic_LPC1769_Mcu.php");
require_once("MiMic_LPC1769_Port.php");
require_once("MiMic_LPC1769_Pin.php");
require_once("MiMic_LPC1769_Gpio.php");
require_once("MiMic_LPC1769_Adc.php");
require_once("MiMic_LPC1769_Pwm.php");



$OUTPUT_PIN=array('dir'=>1,'pin'=>array('mode'=>1,'od'=>0));

function gpiopin()
{
	global $OUTPUT_PIN;
	$mcu=new MiMic_LPC1769_Mcu("192.168.128.39");
	$pin=$mcu->getPin(MiMic_LPC1769::$P0[22],"GPIO");
	echo("D2<br/>");
	$pin->setOpt($OUTPUT_PIN);
	$pin->setValue(1);//ぴかーん
	echo($pin->getValue());//1
}
function gpioport()
{
	global $OUTPUT_PIN;
	$mcu=new MiMic_LPC1769_Mcu("192.168.128.39");
	$port=$mcu->getPort(
		array(MiMic_LPC1769::$P0[0],MiMic_LPC1769::$P0[1])
		,"GPIO");
	$port->setOpt($OUTPUT_PIN);
	$port->setValue(3);//ぴかーん
	echo($port->getValue());
}
function adport()
{
	global $OUTPUT_PIN;
	$mcu=new MiMic_LPC1769_Mcu("192.168.128.39");
	$port=$mcu->getPort(
		array(MiMic_LPC1769::$P0[23],MiMic_LPC1769::$P0[24])
		,"AD");
	
	print_r($port->getValues());
}
function adpin()
{
	global $OUTPUT_PIN;
	$mcu=new MiMic_LPC1769_Mcu("192.168.128.39");
	$pin=$mcu->getPin(MiMic_LPC1769::$P0[23],"AD");
	print_r($pin->getValue());
}

function pwmport($v)
{
	global $OUTPUT_PIN;
	$mcu=new MiMic_LPC1769_Mcu("192.168.128.39");
	$pin=$mcu->getPin(MiMic_LPC1769::$P2[0],"PWM");
	$pin->setDuty($v);
	print_r($v);
}

$filnam = "lock.cgi"; $fp = fopen($filnam,"r+");
while(flock($fp, LOCK_EX) == FALSE){   sleep(1); }
//ファイルから値読む
$a=fgets($fp);
fseek($fp,0);
$b=intval($a);
if($b<=20){$b=20;}
if($b>=320){$b=320;}
switch($_GET['c']){
case 'm':
    $b-=20;
    if($b<=20){$b=20;}
    if($b>=320){$b=320;}
    fputs($fp,$b."\n");
    pwmport((float)$b/1000);
    break;
case 'p':
    $b+=20;
    if($b<=20){$b=20;}
    if($b>=320){$b=320;}
    fputs($fp,$b."\n");
    pwmport((float)$b/1000);
    break;
default:
    break;
}
fclose($fp);



?>
<script type="text/javascript">
function xhr(url)
{
    var x = window.XDomainRequest ? new XDomainRequest() : new XMLHttpRequest();
    x.open("GET",url,false);
    x.send(null);
}
function plus(){xhr("./nyanko.php?c=p");}
function minus(){xhr("./nyanko.php?c=m");}
</script>
<h1>大回転にゃんこ MiMic PhpAPI実験台</h1>
<hr/>
こんとろーらー。反時計回り、時計回りでにゃんこがまわにゃんこがまわるよ。USTでラグがあるから5-30秒くらいかかるよ。<br/>
<input type="button" value="反時計回り" onclick="minus();" />
<input type="button" value="時計回り" onclick="plus();" /><br/>
<iframe src="http://www.ustream.tv/embed/345910" width="608" height="368" scrolling="no" frameborder="0" style="border: 0px none transparent;"></iframe>
</body>
</html>
