Hi. I have the following code as part of a larger code that reads inputs from UART. It is run based on what characters are received from UART.
void RCTIC_F(char output_cmdtype[], char output_cmdparam[]) { //output are messages from UART.
for (int repeat = 0; repeat < 5; repeat++) {
//SOME OPERATIONS THAT PROCESS THE MESSAGE
rtnProtocols(output_cmdtype, output_cmdparam); //Custom function to return message
delay(950); //Switch to non-blocking if possible.
}
}
And this is the code used to receive UART.
void loop() {
bool readyRead = true;
int i = 0;
if (Serial.available() > 0) {
i = msgReceiver('\n', readyRead); //msgReceiver is for turning the input to a char array. '\n' is end char. The output of msgReceiver is the char array position, so need to ++.
messageArray[27] = '\0'; // terminate the string
//Some other message processing functions
stringFunction *rtnpointer[] = {
RCTIC_F, SOME_OTHER_FUNCTIONS
};
input in = convert(input_cmdtype); //Using the char to enum converter.
rtnpointer[in](input_cmdtype, input_cmdparam);
}
}
}
input convert(char str[]) { //A char to enum converter.
switch (str[0]) {
case 'F':
if (strcmp (str, "FIRMV") == 0) return FIRMV;
else if (strcmp (str, "FCPWM") == 0) return FCPER;
else return INVAL;
break;
case 'P':
if (str[1] == 'R') {
if (strcmp (str, "PREVC") == 0) return PREVC;
else if (strcmp (str, "PREST") == 0) return PREST;
}
else if (strcmp (str, "PPFAC") == 0) return PPFAC;
else return INVAL;
break;
case 'R':
if (str[1] == 'Q') {
if (strcmp (str, "RQSPC") == 0) return RQSPC;
else if (strcmp (str, "RQPRE") == 0) return RQPRE;
}
else if (strcmp (str, "RCTIC") == 0) return RCTIC;
else return INVAL;
break;
default:
return INVAL;
}
}
I want to be able to break out of this function if an external message is received. Something like this:
void RCTIC_F(char output_cmdtype[], char output_cmdparam[]) { //output are messages from UART.
for (int repeat = 0; repeat < 5; repeat++) {
//SOME OPERATIONS THAT PROCESS THE MESSAGE
rtnProtocols(output_cmdtype, output_cmdparam); //Custom function to return message
delay(950); //Switch to non-blocking if possible.
if (RCBREIsTriggered == true)
return;
}
}
void RCBRE_F(char output_cmdtype[], char output_cmdparam[]) { //Resistance calibration test is being conducted, returns detected resistance from calibration test
RCBREIsTriggered = true;
rtnProtocols(output_cmdtype, output_cmdparam);
}
My issue is that with me using delay, I don't think I can read the UART inputs while delay is being run. I am wondering how I can read said input while in the function RCTIC, where there is a delay. Please let me know if more information is required.