- 论坛徽章:
- 0
|
这个是我的程序,在文本框中输入频率来控制蜂鸣器的频率,在调试过程中能打开文件,但是就是不叫。。求助各位大神。。
/* 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");
}
|
|