c - Beep command is ruining my function -


i've been fiddling code day i'm stuck yet again...thanks in advance

basically program giving me issues , below snippets of code believe causing problem. user can change "current temperature" , if exceeds threshold of high or low limit "comparelimit" function called...this function calls various other functions (such beeping, , allowing 1 line sensor records printed out on screen). following problems (please keep in mind have use beeping, although if have better method please advise):

  • beeping pain in ass, , entire "alarm" mode revolves around duration of beep. means everytime want press letter "o" print out report, prints on whim of coinciding end of beep trigger. how eliminate this?

  • i want allow user still able access last block of code (the case statements) while being in "while loop" of alarm mode, can exit alarm mode pressing r or f change temperature, , return system normal.

    void updatedisplay() { clrscr();     handle hconsole; //standard c library call  hconsole = getstdhandle(std_output_handle); //used output screen buffer allow coloured text  setconsoletextattribute(hconsole, 2); //sets output screen colour following text printf("\ncurrent temperature channel 1 %d\n\n", temperaturesensor1reading); printf("upper limit channel 1  %d\n\n", gethighlimit(ch1)); printf("lower limit channel 1  %d\n\n", getlowlimit(ch1)); setcurrenttemperature(ch1,temperaturesensor1reading); 

this block of code call functions other cpp source file in same project begin compare current temperature set limits.

comparedlimits1 = comparelimit(ch1); setconsoletextattribute(hconsole, 14);  if (comparedlimits1 == true) {     printf("please press o print out temperature report channel %i \n \n", selectchannel + 1);     printf("please press p silence alarm channel %i \n \n", selectchannel + 1); }  while(comparedlimits1 == true) {     activatealarm(ch1,temperaturesensor1reading);     comparedlogs1 = sensorlog();     if (comparedlogs1 == true) {         printf("\n channel %i has registered temperature of %i \n \n ", selectchannel+1, temperaturesensor1reading);     } } 

this function compares current temperature set temperature limits, , calls other functions "beep" or allow user print out 1 line "report".

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;     } } 

this piece of code still want able manipulate while user in "alarm" mode. user out of "alarm" mode have able reduce current temperature can done below case statements

if( _kbhit()  ) {     selectedcommand = _getch();      switch(selectedcommand) {         case 'r': //if user input r         case 'r'://if user input r             (*temperaturesensorreadings[selectchannel])++;             break; //exits loop          case 'f': //if user input 'f'         case 'f': //if user input 'f'                         (*temperaturesensorreadings[selectchannel])--;                       break; //exits loop 

instead of beep use playsound play .wav file instead using snd_async flag return , play sound asynchronously. can use 1 of system sounds 1 of predefined values.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -