转自:http://blog.sina.com.cn/s/blog_67d069a90100pa2w.html
开发板------TQ2440,其内核 2.6.30.4
通过网页控制LED的实现
1、编写LED的驱动程序。生成EmbedSky_leds.ko文件,动态加载到ARM板上:在ARM板上,命令insmod EmbedSky_leds.ko加载驱动。通过测试文件来验证。
2、加载LED驱动后,编写LED的HTML文件-----------testleds.html。
3、编写针对testleds.html的cgi文件-------------------testleds.cgi
4、由于testleds.cgi文件中,/bin/echo $LED1_ON $LED2_ON
$LED3_ON $LED4_ON >> leds,针对testleds.html上的4个选项框的结果存储在leds文件中,若哪个被选中,则对应1,从左到右为LED1-----LED4,
如 1 1 1 1 ,表示四个框均选中。编写针对leds中内容采集的程序--------------从一个文件中读出数字1.c文件。该文件编写为一直循环,通过其中的for()语句控制。
5、led-result.template文件是用来针对testleds.html按钮提交后,出现一页面,可以返回到testleds.html页面。
################testleds.html########################
//testleds.html
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>LED灯测试</title>
<!--
body {
background-color: #FFFFFF;
);
}
-->
</style></head>
<body>
<h1 align="left">LED测试</h1>
<form method="get" action="testleds.cgi" name="LED-TEST">
<table border="0" width="100%">
<tr>
<td width="80px">
</td>
<td width="80px">
LED1<input type="checkbox" name="cb_led" value="led1" />
</td>
<td width="80px">
LED2<input type="checkbox" name="cb_led" value="led2" />
</td>
<td width="80px">
LED3<input type="checkbox" name="cb_led" value="led3" />
</td>
<td width="80px">
LED4<input type="checkbox" name="cb_led" value="led4" />
</td>
<td></td>
</tr>
<!--...-->
<tr>
<td width="80px">
</td>
<td></td>
</tr>
</table>
</div>
</form>
</body>
</html>
#########################以上为testleds.html################
############################testled.cgi##################################
#testled.cgi
#! /bin/sh
LED1_ON=0
LED2_ON=0
LED3_ON=0
LED4_ON=0
SPEED=1
case $QUERY_STRING in
esac
case $QUERY_STRING in
esac
case $QUERY_STRING in
esac
case $QUERY_STRING in
esac
/bin/echo $LED1_ON $LED2_ON
$LED3_ON $LED4_ON >> leds
/bin/echo "Content-type: text/html; charset=gb2312"
#/bin/echo
#/bin/echo $QUERY_STRING "STRING"
/bin/echo
/bin/cat led-result.template
exit 0
####################以上为testled.cgi############
#######################led-result.template##########################
<html>
<head>
<title>LED测试结果</title>
<style type="text/css">
<!--
body {
background-color: #666666;
}
-->
</style>
</head>
<body>
<p>LED设置已经提交</p>
<p><a href="leds.html">返回上一页</a></p>
</body>
</html>
####################以上为led-result.template######################
#######################从一个文件中读出数字1.c#######################################
//从一个文件中读出数字1.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
//int main(int argc, char **argv)
int main()
{
int on;
int led_no;
int fd;
FILE *f;
fd = open("/dev/EmbedSky-leds", 0);
//对应EmbedSky_leds.ko文件
if (fd < 0)
perror("open device leds");
exit(1);
}
int count;
for(count=0;count<20;count++)
{
f=fopen("/web/leds_testwln/leds","r");
char ch;
char led1[20];
int num1,num2,num3,num4;
num1=atoi(led1);
num2=atoi(led2);
num3=atoi(led3);
num4=atoi(led4);
ioctl(fd, num1, 0);
ioctl(fd, num2, 1);
ioctl(fd, num3, 2);
ioctl(fd, num4, 3);
sleep(1);
}
fclose(f);
close(fd);
return 0;
}
#####################从一个文件中读出数字1.c#######################