Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99a2d17

Browse files
committed
Added 'fadeAmt' limit: 1-128
1 parent 4764c8f commit 99a2d17

File tree

1 file changed

+8
-3
lines changed
  • My-RTOS-Projects/04-CLI-LEDs/src

1 file changed

+8
-3
lines changed

My-RTOS-Projects/04-CLI-LEDs/src/main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void userCLITask(void *param) // Function
7171
buffer[index] = input; // write received character to buffer
7272
index++;
7373
}
74-
74+
7575
if(input == '\n') // Check when user presses ENTER key
7676
{
7777
Serial.print("\n");
@@ -118,7 +118,12 @@ void msgRXTask(void *param)
118118
char* tailPtr = someMsg.cmd + fadeLen; // pointer arithmetic: move pointer to integer value
119119
fadeAmt = atoi(tailPtr); // retreive integer value at end of string
120120
fadeAmt = abs(fadeAmt); // fadeAmt can't be negative
121-
121+
if(fadeAmt <= 0 || fadeAmt > 128)
122+
{
123+
Serial.println("Value Must Be Between 1 & 128");
124+
Serial.println("Returning....");
125+
continue;
126+
}
122127
xSemaphoreTake(mutex1, portMAX_DELAY); // enter critical section
123128
fadeInterval = fadeAmt; // Change global fade variable
124129
xSemaphoreGive(mutex1);
@@ -231,7 +236,7 @@ void msgRXTask(void *param)
231236
}
232237
else // Not a command: Print the message to the terminal
233238
{
234-
sprintf(buffer, "Not A Command: %s\n", someMsg.cmd);// print user message
239+
sprintf(buffer, "Invalid Command: %s\n", someMsg.cmd);// print user message
235240
Serial.print(buffer);
236241
memset(buffer, 0, BUF_LEN); // Clear input buffer
237242
}

0 commit comments

Comments
 (0)