Click here to Skip to main content
15,887,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All, below i attached a code where i need a control on recursive function. Means, it should wait for my button press signal to move further.

C++
void PlaySongs::performance(int step){

step++;

if (waitForInterruptSys (iOnePin, -1) >0)
{
   cout<<"Push Button is pressed"<<endl;

   SoundNamespace::SoundProject::SoundProject project;

   project.Init();
   project.InitSound();
   
   project.StartInterruptThreads();
   project.LoadProject();
   project.AdjustSounds();
   project.LoadSounds(true);
   project.StartPlayingSounds();
   
   cout << "Initialization finished." << endl;

// Some C++ control statement NEEDS here  <--

/* here i need control, so that, after button pressed on bread board, it should move further i.e. perform next statements, otherwise wait infinite time. something like cvWaitKey(0) from opencv. Interrupt detected by (waitForInterruptSys (iOnePin, -1) >0). like written above. */

if(step==3)
     return;
else
    performance(step);

}


I tried

C++
int first = std::cin.get();
std::cin.ignore(256, 'waitForInterruptSys (iOnePin, -1) >0');   ---> NOt sure, because i don't why std:: is not detecting ignore function and not at all confident on second parameter of ignore function

Anybody can suggest something ?? Thanks in advance.
Posted
Updated 14-Aug-15 11:49am
v2

1 solution

If "(waitForInterruptSys (iOnePin, -1)" represents your button press, change the if statement to a while statement ...

C++
if (waitForInterruptSys (iOnePin, -1) >0)
{
   cout<<"Push Button is pressed"<<endl;


... becomes ...

C++
while (waitForInterruptSys (iOnePin, -1) <= 0) NULL;
cout<<"Push Button is pressed"<<endl;


The "NULL" is just a placeholder since the while statement (like the if) expects a statement to follow. This effectively says "while (no button is pressed) do nothing".
 
Share this answer
 
v2
Comments
Philippe Mori 14-Aug-15 20:25pm    
I would suggest to always write { } around a block even if it contains a single statement and in particular use { } to show that nothing is done.
Sergey Alexandrovich Kryukov 14-Aug-15 21:27pm    
{} is a good idea, but { and } around a single statement is just a matter of taste. Perhaps it is easier to add more statements but no more readable in final code, takes more lines for no real reason. It depends on point of view.
—SA
Member 11292470 15-Aug-15 2:50am    
@bling -

while (waitForInterruptSys (iOnePin, -1) <= 0)
NULL;
cout<<"Push Button is pressed"<<endl; <------------------- This statement will executed then. i want to gain control over block of code whicht start with { cout<<..... till end }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900