Ncurses: movement [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.

What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.

Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR

Related

How to get available space on a network drive in c++? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I tried using std::filesystem::space(dir) but with no luck -> it cannot determine available disk space, sets it to uintmax.
auto info = std::filesystem::space("K:\\Dir");
if(info.available == static_cast<uintmax_t>(-1))
{
std::cout << "Error occurred!\n";
}
K:\Dir does indeed exist. And this snippet prints Error occurred for my drive mounted on K:.
If you want to get the free space you need to try
const std::filesystem::space_info spaceInfo = std::filesystem::space(dir);
cout << static_cast<std::intmax_t>(spaceInfo.free) << endl;
Here dir = "/path/to/dir/";
Refer cppreference

How to display asterisks (***) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to create an ATM application using c++ and I want to display asterisks (****) when I input the pin code. I haven't tried anything because I have no idea on how to do it.
Could someone help me?
A very small program which should help you get started for Windows would go like this:
int main(void)
{
char character = 0;
while (true)
{
character = _getch();
if (character == 13) //Enter
break;
else
{
putc('*');
//Do whatever
}
}
}
Please note that this code is off the top of my head and still requires the correct includes, but should point you in the right direction.
Please refer to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getch-getwch?view=msvc-160 for the documentation of _getch and http://www.asciitable.com/ for a list of control codes you might be getting.

Is it possible to create "quick time events" in C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have some knowledge about C++, but I stumbled upon an problem. I want the user to enter some text, but when it takes longer than X seconds, the program will go on. I guess, it is not possible, but maybe you know something about it.
It will be in the command line, without GUI.
I am not certain how the programm will look like, but it will be something like a CMD-RPG. I wanted to use Quick Time Events to make it a little bit more exciting.
I cant comment so I will just leave this here
Input with a timeout in C++
Since I cannot comment, I will simply leave this as an answer.
One possible way to solve this problem is to have 2 threads:
Input capture thread: since receiving input is a thread-blocking action, you should have a thread that simply polls for user input, placing that input into a thread-safe buffer
Quick-time function on main thread: a function that will be responsible for executing the quick-time event. Something like the following could be done (pseudo code):
clear input buffer //the buffer provided by the input capture thread
bool success = false;
while(current time < ending time)
{
if(input buffer isn't empty)
{
get contents of input buffer and send contents to cout
if (user has finished input correctly)
{
success = true;
break;
}
clear buffer
}
}
return success;
For this to work, you would need to turn off echo on the command prompt (see this page for more info)
Although Diogo's reference is excellent (and informative), I believe this answer is more applicable than since the OP has indicated that this program will be ran on Windows.

Remove character from String c++/Arduino UNO [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I need to delete some characters from string. When i used erase it doesn`t work, compilation error erase no member named. Please help me. Probaly it is because I writing for Arduino UNO.
Arduino String class is quite different from std::string. For example erase doesn't exists. But there is method remove.
Anyway, you should start with: https://www.arduino.cc/en/Reference/HomePage
Expanding on what KIIV suggested, you could possibly do something like this:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
String words = "This is a sentence."; //reassign same string at the start of loop.
delay(1000);
Serial.println(words);
char c;
char no = ' '; //character I want removed.
for (int i=0; i<words.length()-1;++i){
c = words.charAt(i);
if(c==no){
words.remove(i, 1);
}
}
Serial.println(words);
delay(5000);//5 second delay, for demo purposes.
}
The Libraries in Arduino are customized in order to factor the memory constraints of the target Micro controller. For example , the Uno runs on a mega328P Atmel (now Microchip) device, which has only has 32 KB flash memory.

Arduino double command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to find a way for my Arduino to recognize some of the commands I'm attempting to send over serial (via Raspberry Pi)
I'm come as far as to detect 2 commands, but I'm stuck at my last.
To give a little bit more detail, I have my fingerprint scanner (GT-511C3) connected, and the library installed that will make it work.
That said, with the first 2 commands consist the verifying of fingerprints to ID (which works great) and the enrolling of fingerprints to new ID's (also work great) these parts of the script are triggered by the respective ASCII code "0" and "1".
My last, and problematic command "2" to remove an ID, is where I'm seeking help with.
Here's the code I'm currently working with:
if(ser == '2'){
while(val2 == 0){
char val3 = 0;
delay(10);
Serial.println("Type the ID to be deleted");
delay(2500);
fps.DeleteID(Serial.read());
val3 == Serial.read();
delay(10);
Serial.println("Deleted ID:");
Serial.print(val3);
delay(10);
val2 = 1;
}
}
I'm attempting to send the ASCII code "2" over Raspberry Pi through serial to the Arduino, followed by the ID that needs to be removed. It triggers after the command "2" is send, but refuses to read the ID and as such, I'm unable to finish it.
Any help or insight would really be appreciated.
val3 == Serial.read(); should be val3 = Serial.read();. You have an extra = which turns it into a useless comparison.