C 嘟嘟声命令破坏了我的功能
我整天都在摆弄这段代码,但我又被卡住了……提前谢谢 基本上,这个程序给了我一些问题,下面是我认为导致问题的代码片段。基本上,用户可以更改其“当前温度”,如果超过上限或下限的阈值,则调用“compareLimit”函数……该函数然后调用各种其他函数(如蜂鸣声,并允许在屏幕上打印单线传感器记录)。但是,以下是我的问题(请记住,我必须使用蜂鸣声,但如果您有更好的方法,请提供建议):C 嘟嘟声命令破坏了我的功能,c,while-loop,compare,beep,C,While Loop,Compare,Beep,我整天都在摆弄这段代码,但我又被卡住了……提前谢谢 基本上,这个程序给了我一些问题,下面是我认为导致问题的代码片段。基本上,用户可以更改其“当前温度”,如果超过上限或下限的阈值,则调用“compareLimit”函数……该函数然后调用各种其他函数(如蜂鸣声,并允许在屏幕上打印单线传感器记录)。但是,以下是我的问题(请记住,我必须使用蜂鸣声,但如果您有更好的方法,请提供建议): 嘟嘟声是一种痛苦,我的整个“警报”模式围绕着嘟嘟声的持续时间。这意味着每当我想按字母“O”打印报告时,它会根据突发奇想
- 嘟嘟声是一种痛苦,我的整个“警报”模式围绕着嘟嘟声的持续时间。这意味着每当我想按字母“O”打印报告时,它会根据突发奇想打印报告,同时触发一声嘟嘟声。我如何消除这种情况
- 我想让用户即使在报警模式的“while loop”中也能访问最后一段代码(case语句),这样他们就可以通过按r或f来改变温度,从而真正退出报警模式,并使系统恢复正常
void updateDisplay() { clrscr(); HANDLE hConsole; //standard c library call hConsole = GetStdHandle(STD_OUTPUT_HANDLE); //used for output screen buffer to allow for coloured text SetConsoleTextAttribute(hConsole, 2); //sets output screen colour for following text printf("\nCurrent Temperature for channel 1 is %d\n\n", temperatureSensor1Reading); printf("Upper Limit for channel 1 is %d\n\n", getHighLimit(CH1)); printf("Lower Limit for channel 1 is %d\n\n", getLowLimit(CH1)); setCurrentTemperature(CH1,temperatureSensor1Reading);
comparedLimits1 = compareLimit(CH1);
SetConsoleTextAttribute(hConsole, 14);
if (comparedLimits1 == TRUE) {
printf("please press O to print out a temperature report for channel %i \n \n", selectChannel + 1);
printf("please press P to silence the alarm for channel %i \n \n", selectChannel + 1);
}
while(comparedLimits1 == TRUE) {
activateAlarm(CH1,temperatureSensor1Reading);
comparedLogs1 = sensorLog();
if (comparedLogs1 == TRUE) {
printf("\n Channel %i has registered a temperature of %i \n \n ", selectChannel+1, temperatureSensor1Reading);
}
}
这是我的函数,它将当前温度与设置的温度限制进行比较,并调用其他函数“嘟嘟”或允许用户打印一行“报告”
不要使用
Beep
播放.wav文件,而是使用SND_ASYNC
标志立即返回并异步播放声音。您甚至可以将其中一个系统声音与其中一个预定义值一起使用。神圣的文字墙。你能不能把这个问题分解成一个或多个简洁的、可回答的问题?嘿,乔纳森……我实际上花了20分钟来思考如何详细阐述这一点……如果我没有收到任何人的回复,我将重新编辑这篇文章……很抱歉,问题出在哪里?很可能是一个阻塞调用。第三个代码块,在activateAlarm函数中,它在那里被调用,然后转到另一个函数来实际执行嘟嘟声和嘟嘟声的持续时间。这听起来像是一般情况下您应该查看的。
temperature_t compareLimit (int channelID)
{
temperature_t limitIsExceeded = FALSE;
if ((temperatureChannel[channelID].currentTemperature > temperatureChannel[channelID].highLimit) | (temperatureChannel[channelID].currentTemperature < temperatureChannel[channelID].lowLimit))
limitIsExceeded = TRUE;
return limitIsExceeded;
}
void activateAlarm(int channelID, temperature_t temperature)
{
int key = 0;
if ((temperatureChannel[channelID].currentTemperature > temperatureChannel[channelID].highLimit) | (temperatureChannel[channelID].currentTemperature < temperatureChannel[channelID].lowLimit))
callBeep();
sensorLog();
if (_kbhit())
key = _getch();
if ((key == 'P') | (key == 'p')) {
silenceBeep();
}
}
void callBeep()
{
Beep(250,2000);
}
void silenceBeep()
{
Beep(0,2000);
}
temperature_t sensorLog()
{
int key = 0;
temperature_t notedLog = FALSE;
if (_kbhit())
key = _getch();
if ((key == 'O') | (key == 'o')) {
notedLog = TRUE;
return notedLog;
}
}
if( _kbhit() ) {
selectedCommand = _getch();
switch(selectedCommand) {
case 'R': //if user input is R
case 'r'://if user input is r
(*temperatureSensorReadings[selectChannel])++;
break; //exits loop
case 'F': //if user input is 'F'
case 'f': //if user input is 'f'
(*temperatureSensorReadings[selectChannel])--;
break; //exits loop