Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void execCmd(const char *set)
- {
- char *cmdParam = CMDHandler.find(set, CMD_PARAM);
- if (!strcmp(cmdParam, "LED"))
- {
- // ONE WAY TO CHECK IF COMMAND HAS PARAM(S) - BEFORE GETTING PARAM(S) == BETTER WAY
- if (!CMDHandler.count(CMDHandler.getNext(CMD_PARAM), CMD_PARAM))
- {
- Serial.print(F("->> Command LED: Current LED status is "));
- Serial.println(digitalRead(LED_PIN));
- return;
- }
- cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
- LEDStatus = 0;
- uint8_t status = atoi(cmdParam);
- digitalWrite(LED_PIN, status);
- Serial.print(F("->> Command led: LED Status is "));
- Serial.println(status, DEC);
- }
- else if (!strcmp(cmdParam, "LOOP"))
- {
- cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
- // SECOND WAY TO CHECK IF COMMAND HAS PARAM(S) - AFTER GETTING EVERY PARAM
- if (cmdParam == nullptr)
- {
- Serial.println(F("->> Command LOOP: Expected one parameter!"));
- return;
- }
- uint8_t status = atoi(cmdParam);
- if (status)
- {
- LEDStatus = 2;
- digitalWrite(LED_PIN, HIGH);
- Serial.println(F("->> Command LOOP: LED Blink Loop is on!"));
- delay(blinkDuration);
- }
- else
- {
- LEDStatus = 0;
- digitalWrite(LED_PIN, LOW);
- Serial.println(F("->> Command LOOP: LED Blink Loop is off!"));
- }
- }
- else if (!strcmp(cmdParam, "DURATION"))
- {
- if (!CMDHandler.count(CMDHandler.getNext(CMD_PARAM), CMD_PARAM))
- {
- Serial.print(F("->> Command DURATION: Current blink duration is "));
- Serial.print(blinkDuration, DEC);
- Serial.println("ms");
- return;
- }
- cmdParam = CMDHandler.find(nullptr, CMD_PARAM);
- blinkDuration = atoi(cmdParam);
- Serial.print(F("->> Command DURATION: New blink duration is "));
- Serial.print(blinkDuration, DEC);
- Serial.println("ms!");
- }
- else if (!strcmp(cmdParam, "HELP"))
- {
- 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"));
- }
- else
- {
- Serial.print(F("->> Command "));
- Serial.print(cmdParam);
- Serial.println(F(" does not exist!"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement