I have a program that is trying to record the a fixed number keys from any tv remote that will then be used to control a POV clock.
Essentially what I am trying to do is this in old school programming.
Writeln("Press up arrow:");
Readkey(m_nUpArrowKey);
Writeln("Press down arrow:");
Readkey(m_nDownArrowKey);
The problem is the damn remote keys are far more sensitive than a keyboard key and they repeat the key code even if you hold down the key for even the briefest of moments. So I am basically reading the same code for the above two different variables.
I cannot for the life of me figure out a way to consume the excess 'key strokes' until the user hits a different key on the remote.
Below is what I have at present but it locks up in side the loop while (results.value == nLastCode).
The other problem I have had is that a key press of the up arrow results in both m_nUpArrowCode and m_nDownArrowCode being filled with the same code from IRRecieve.decode(...).
Those who program the tvs must have the same sort of problem so how the buggery do they make the tv volume, for example, go up with discrete presses of the increase volume button rather than continuously as long as the increase volume button is depressed?
How do I make IRRecieve.decode(...) behave like Readkey in turbo pascal?
void CClock::doSetRemoteKeyCode(IRrecv &irrecv, decode_results &results)
{
bool bDone = false;
long unsigned *nStoredCode = &m_nUpArrowCode, nLastCode = 0;while (!bDone)
{
memset(&results, 0, sizeof results);
irrecv.resume();if (nStoredCode == &m_nUpArrowCode)
m_strPrompt = "HIT UP";
else if (nStoredCode == &m_nDownArrowCode)
m_strPrompt = "HIT DOWN";
else if (nStoredCode == &m_nLeftArrowCode)
m_strPrompt = "HIT LEFT";
else if (nStoredCode == &m_nRightArrowCode)
m_strPrompt = "HIT RIGHT";
else if (nStoredCode == &m_nEnterCode)
m_strPrompt = "Hit ENTER/OK";
else if (nStoredCode == &m_nExitCode)
m_strPrompt = "Hit EXIT/BACK/RETURN";
else if (nStoredCode == &m_nHomeCode)
m_strPrompt = "Hit HOME";Serial.println(m_strPrompt);
while (results.value == nLastCode)
{
if (irrecv.decode(&results))
nLastCode = results.value;
}
irrecv.resume();
(*nStoredCode) = results.value;if (results.value == nLastCode)
{
Serial.println("PPPPPPPPPPPPPPPPP");
Serial.println("nLastCode = ");
Serial.println(nLastCode);
Serial.println("results.value = ");
Serial.println(results.value);
Serial.println("PPPPPPPPPPPPPPPPP");
}
else if (nStoredCode == (&m_nUpArrowCode))
nStoredCode = &m_nDownArrowCode;
else if (nStoredCode == &m_nDownArrowCode)
nStoredCode = &m_nLeftArrowCode;
else if (nStoredCode == &m_nLeftArrowCode)
nStoredCode = &m_nRightArrowCode;
else if (nStoredCode == &m_nRightArrowCode)
nStoredCode = &m_nEnterCode;
else if (nStoredCode == &m_nEnterCode)
nStoredCode = &m_nExitCode;
else if (nStoredCode == &m_nExitCode)
nStoredCode = &m_nHomeCode;
else if (nStoredCode == &m_nHomeCode)
nStoredCode = NULL;bDone = nStoredCode == NULL;
}
memset(&results, 0, sizeof results);
m_nMode = m_eDisplayTime;
}