前面把boa移植好了现在就来用web控制led 见 Ttiny6410移植boa服务器
index:
<p> 控制灯1测试:</p>
<div>
<form method="get" action="/cgi-bin/leds.cgi">
<p>
<label>
<input type="radio" value="1" />
开灯 </label>
<br />
<label>
<input type="radio" value="0" checked/>
关灯</label>
<br />
<label>
<input type="radio" value="10" />
查看LED1状态 </label>
</p>
<p>
<label>
<input type="submit" value="OK!" />
</label>
</p>
</form>
</div>
<label>
</label>
leds.cgi:部分程序
led_fd=open("/dev/tiny6410-led",O_RDWR);
if(led_fd==-1)
{
perror("open tiny6410-led device failed\n");
printf("open tiny6410-led device failed\n");
exit(1);
}
else
{
//printf("open tiny6410-led device success!\n");
}
/*LED1*/
if(fifo_value[0]==0)
{
if(ioctl(led_fd,1,00)==0)
printf("CGI ioctl is ok\n");
else
printf("CGI ioctl is wrong\n");
printf("my led1 off!\n");
}
if(fifo_value[0]==1)
{
if(ioctl(led_fd,1,01)==0)
printf("CGI ioctl is ok\n");
else
printf("CGI ioctl is wrong\n");
printf("my led1 on!\n");
}
if(fifo_value[0]==10)
{
ioctl(led_fd,0,&arg);
_itoa(arg,s,2);
//printf("s=%s\n",s);
n=strlen(s);
//printf("n=%d\n",n);
//printf("s[0]=%c",s[0]);
if(s[0]=='0')
printf("led 1: ON\n");
else if(s[0]=='1')
printf("led 1: OFF\n");
}
效果图: