Advertisement
Guest User

Untitled

a guest
Apr 18th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. void execCmd(const char *set)
  2. {
  3.     char *cmdParam = CMDHandler.find(set, CMD_PARAM);
  4.  
  5.     if (!strcmp(cmdParam, "LED"))
  6.     {
  7.         // ONE WAY TO CHECK IF COMMAND HAS PARAM(S) - BEFORE GETTING PARAM(S) == BETTER WAY
  8.         if (!CMDHandler.count(CMDHandler.getNext(CMD_PARAM), CMD_PARAM))
  9.         {      
  10.             Serial.print(F("->> Command LED: Current LED status is "));
  11.             Serial.println(digitalRead(LED_PIN));
  12.             return;    
  13.         }
  14.  
  15.         cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
  16.         LEDStatus = 0;
  17.         uint8_t status = atoi(cmdParam);
  18.  
  19.         digitalWrite(LED_PIN, status);
  20.         Serial.print(F("->> Command led: LED Status is "));
  21.         Serial.println(status, DEC);
  22.     }
  23.     else if (!strcmp(cmdParam, "LOOP"))
  24.     {
  25.         cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
  26.  
  27.         // SECOND WAY TO CHECK IF COMMAND HAS PARAM(S) - AFTER GETTING EVERY PARAM
  28.         if (cmdParam == nullptr)
  29.         {
  30.             Serial.println(F("->> Command LOOP: Expected one parameter!"));
  31.             return;
  32.         }  
  33.  
  34.         uint8_t status = atoi(cmdParam);
  35.         if (status)
  36.         {
  37.             LEDStatus = 2;
  38.             digitalWrite(LED_PIN, HIGH);
  39.             Serial.println(F("->> Command LOOP: LED Blink Loop is on!"));
  40.             delay(blinkDuration);
  41.         }
  42.         else
  43.         {
  44.             LEDStatus = 0;
  45.             digitalWrite(LED_PIN, LOW);
  46.             Serial.println(F("->> Command LOOP: LED Blink Loop is off!"));         
  47.         }  
  48.     }
  49.     else if (!strcmp(cmdParam, "DURATION"))
  50.     {
  51.         if (!CMDHandler.count(CMDHandler.getNext(CMD_PARAM), CMD_PARAM))
  52.         {
  53.             Serial.print(F("->> Command DURATION: Current blink duration is "));
  54.             Serial.print(blinkDuration, DEC);
  55.             Serial.println("ms");
  56.             return;    
  57.         }
  58.  
  59.         cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
  60.         blinkDuration = atoi(cmdParam);
  61.  
  62.         Serial.print(F("->> Command DURATION: New blink duration is "));   
  63.         Serial.print(blinkDuration, DEC);
  64.         Serial.println("ms!"); 
  65.     }
  66.     else if (!strcmp(cmdParam, "HELP"))
  67.     {
  68.         Serial.println(F("------ HELP ------\n-> LED [0/1] - Turns off/on LED on pin 13\n-> LOOP [0/1] - Stops/starts blink loop with LED on pin 13\n-> DURATION [X] - Changes duration of LED loop blink. Recommended values is 50-500ms\n"));
  69.     }
  70.     else
  71.     {
  72.         Serial.print(F("->> Command "));
  73.         Serial.print(cmdParam);
  74.         Serial.println(F(" does not exist!"));
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement