免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 963 | 回复: 0
打印 上一主题 下一主题

求助各位大神 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-19 10:45 |只看该作者 |倒序浏览
这个是我的程序,在文本框中输入频率来控制蜂鸣器的频率,在调试过程中能打开文件,但是就是不叫。。求助各位大神。。
/* Change this if the SERVER_NAME environment variable does not report
        the true name of your web server. */
#if 1
#define SERVER_NAME cgiServerName
#endif
#if 0
#define SERVER_NAME "www.boutell.com"
#endif

/* You may need to change this, particularly under Windows;
        it is a reasonable guess as to an acceptable place to
        store a saved environment in order to test that feature.
        If that feature is not important to you, you needn't
        concern yourself with this. */

#ifdef WIN32
#define SAVED_ENVIRONMENT "c:\\cgicsave.env"
#else
#define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
#endif /* WIN32 */

#define VOID_ADDR 0x0000

#include <stdio.h>
#include "cgic.h"
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#define PWM_IOCTL_SET_FREQ 1
#define PWM_IOCTL_STOP 2

void ShowForm();
static int fd=-1;
int temp;
int frequency;
static void close_buzzer(void);
static void open_buzzer(void)
{
   fd=open("/dev/pwm",0);
   if(fd<0)
   {
    perror("open pwm_buzzer device");
    exit(1);
   }

   atexit(close_buzzer);
}

static void close_buzzer(void)
{
  if(fd>=0)
   {
     ioctl(fd,PWM_IOCTL_STOP);
      close(fd);
      fd=-1;
   }
}


static void set_buzzer_freq()
{
  int faint;
  int ret;
  fprintf(cgiOut, "<font>start!</font>\n");
  ret=ioctl(fd,PWM_IOCTL_SET_FREQ,faint);
  fprintf(cgiOut, "<font>end!</font>\n");
  if(ret<0)
  {
    //perror("set the frequency of the buzzer");
    fprintf(cgiOut, "<font>ret=%d</font>\n",ret);
    //exit(1);
    return;
  }
fprintf(cgiOut, "<font>Success!</font>\n");
  
}
void HandleSubmit()
{
  open_buzzer();
  set_buzzer_freq(temp);
}


int cgiMain() {
        cgiHeaderContentType("text/html");
        /* Top of the page */
        fprintf(cgiOut, "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
        fprintf(cgiOut, "<HEAD>\n");
        fprintf(cgiOut, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\n");
        fprintf(cgiOut, "<TITLE>buzzer</TITLE>\n");
        fprintf(cgiOut, "</HEAD>\n");
        fprintf(cgiOut, "<BODY>\n");
        if(cgiFormSubmitClicked("buzzer") == cgiFormSuccess)
        {
                temp=GetDataFromPage();               
                fprintf(cgiOut,"<hr>%d<hr>\n",temp);

                if(temp>0)HandleSubmit();
               // printf("hello\n");
               
        }       
        /* Now show the form */
        ShowForm();
        /* Finish up the page */
        fprintf(cgiOut, "</BODY></HTML>\n");
        return 0;
}

int GetDataFromPage()
{
        int buzzer;
        int freq1=cgiFormInteger("pinlv",&buzzer,1000);
        switch(freq1)
        {
        case  cgiFormEmpty:
                buzzer=-1;
                break;
        case  cgiFormBadType:       
                buzzer=-2;       
                break;
        case  cgiFormNotFound:
               buzzer=-3;       
                break;
        defaut:
               frequency=buzzer;
               return(buzzer);
                break;
        }
      return(buzzer);
}
void ShowForm()
{
        fprintf(cgiOut,"<form action=\"buzzer.cgi\" method=\"post\">\n");
        fprintf(cgiOut,"<input type=\"text\" value=\"\" name=\"pinlv\" /> \n");
        fprintf(cgiOut,"<input type=\"submit\" name=\"buzzer\" value=\"buzzer\" /></form>\n");
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP