Repeating previous function(s) when a certain signal is received

Hey guys, I'm new here. I have been looking for a way to repeat a function that was previously called when a infrared remote signal is received. When a button on my remote is held down, it spews out pure F hex digits. I have been trying to write code that when the device receives pure F's, it will repeat the previous function it ran.
Just to clear confusion, I'm programming a small osoyoo car kit.
/*

enum DN

GO_REPEAT,
DEF
Drive_Num=DEF;


void go_Advance(void) //Forward
{
digitalWrite(RightDirectPin1,LOW);
digitalWrite(RightDirectPin2,HIGH);
digitalWrite(LeftDirectPin1,LOW);
digitalWrite(LeftDirectPin2,HIGH);
analogWrite(speedPinL,100);
analogWrite(speedPinR,100);
}

void do_Drive_Tick()
{
switch (Drive_Num)
{
case GO_REPEAT://Need code here to repeat previous function (in this case it was GO_ADVANCE)
case GO_ADVANCE:go_Advance();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
case GO_LEFT: go_Left();JogFlag = true;JogTimeCnt = 1;JogTime=millis();break;
default:break;




*/
if you have a big switch anyway, you keep drive_tick what it was and keep switching off it, and use a temporary variable. something like

read input into temp
if temp != fffff thing
drive-tick = temp; //it changed, else (implied) remains the same.
switch drive-tick... //etc .. uses new or repeats old value..

alternate ideas too late to try..

you can use a function pointer if you make all your functions compatible with the same interface.
or you can just keep like a char (255 functions) that represents which one was active and switch to call it (switches usually turn into lookups, very efficient). With the switch, you can call different parameter setups but you will still need to HAVE the right parameters to feed to it.
Last edited on
Topic archived. No new replies allowed.