网页控制ARM板的LED

转自: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">
    <div align="left">
<table border="0" width="100%">      
<tr>
<td width="80px">
          <b> LED灯:</b>
</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">
        <input type="submit" value="确定" name="submit">
</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
      *cb_led=led1*)
          LED1_ON=1
          ;;
esac
 
case $QUERY_STRING in
      *cb_led=led2*)
          LED2_ON=1
          ;;
esac
 
case $QUERY_STRING in
      *cb_led=led3*)
          LED3_ON=1
          ;;
esac
 
case $QUERY_STRING in
      *cb_led=led4*)
          LED4_ON=1
          ;;
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];
      char led2[20];
      char led3[20];
      char led4[20];
  int i=0;
      int j=0;
      int i1=0;
      int j1=0;
      int flag=0;
      if(f == NULL)
      {
          printf("wrong!!");
      }
      else
      {
          while((ch=getc(f))!='\n')
          {
              if(ch!=' '&&flag==0)
              {
                  led1[i]=ch;
                  i++;
              }
              else if(flag==0)
              {
                  led1[i]='\0';
                  flag=1;
                  continue; 
              }
              else if(ch!=' '&&flag==1)
              {
                  led2[j]=ch;
                  j++;
              }
              else if(flag==1)
              {
                  led2[j]='\0';
                  flag=2;
                  continue;
              }
              else if(ch!=' '&&flag==2)
              {
                  led3[i1]=ch;
                  i1++;
              }
              else if(flag==2)
              {
                  led3[i1]='\0';
                  flag=3;
                  continue;
              }
              else if(ch!=' '&&flag==3)
              {
                  led4[j1]=ch;
                  j1++;
              }
              else if(flag==3)
              {
                  led4[j1]='\0';
                  flag=4;
                  continue;
              }
          }
      }
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#######################
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值