Community
cancel
Showing results for 
Search instead for 
Did you mean: 
JPeep
Novice
1,324 Views

Break out of a while loop with keystroke on Edison with C++ ?

Jump to solution

Hello,

I would like the user of my program to be able to break out of a while loop be entering a keystroke. I am aware of several methods of doing this: using kbhit from conio.h, multithreading with something like boost, and GetAsyncKeyState() from windows.h. However, I have not been able to successfully implement these. I'm wondering if the problem could be that I'm using a Windows 7 machine to write programs for the Intel Edison's Yocto Linux. For instance, if I want to use the multithreading method should I download the boost header files for Linux and save it onto a file on my windows and then copy and paste the header path to my program?

The following two images show my attempt at using the boost header:

The following is the code that uses kbhit() from conio.h. This won't compile.

My program is a homemade pulse width modulator for an H-bridge. I was having issues with the pwm class so I made my own pwm function.

Thanks

Jordan

1 Solution
Pedro_M_Intel
Employee
116 Views

Hello Jordan1850,

I think what's happening is that you are trying to use functions that are Windows specific, as GetAsyncKeyState().

I suggest you to take a look at the following links that might help you:

http://stackoverflow.com/questions/2984307/c-key-pressed-in-linux-console http://stackoverflow.com/questions/2984307/c-key-pressed-in-linux-console

http://stackoverflow.com/questions/1485116/capturing-keystrokes-in-gnu-linux-in-c http://stackoverflow.com/questions/1485116/capturing-keystrokes-in-gnu-linux-in-c

Also, you could use an Edison's pin to set an interrupt, you could use an interruption instead as a keystroke, mraa has a function for interruptions. Take a look at it, it may interest you:

https://github.com/intel-iot-devkit/mraa/blob/master/examples/isr_pin6.c mraa/isr_pin6.c at master · intel-iot-devkit/mraa · GitHub

Peter.

View solution in original post

2 Replies
Pedro_M_Intel
Employee
117 Views

Hello Jordan1850,

I think what's happening is that you are trying to use functions that are Windows specific, as GetAsyncKeyState().

I suggest you to take a look at the following links that might help you:

http://stackoverflow.com/questions/2984307/c-key-pressed-in-linux-console http://stackoverflow.com/questions/2984307/c-key-pressed-in-linux-console

http://stackoverflow.com/questions/1485116/capturing-keystrokes-in-gnu-linux-in-c http://stackoverflow.com/questions/1485116/capturing-keystrokes-in-gnu-linux-in-c

Also, you could use an Edison's pin to set an interrupt, you could use an interruption instead as a keystroke, mraa has a function for interruptions. Take a look at it, it may interest you:

https://github.com/intel-iot-devkit/mraa/blob/master/examples/isr_pin6.c mraa/isr_pin6.c at master · intel-iot-devkit/mraa · GitHub

Peter.

View solution in original post

JPeep
Novice
116 Views

Hi Peter,

I will look into those solutions.

 

I found that I did not need to use the atomic boolean or the boost library. I was able to complete my task with just std::thread with the help of romankubanek's post:

Thank you for the help,

Jordan

Reply