mDot AT-Firmware for testing
Dependencies: MTS-Serial libmDot-mbed5
Fork of Dot-AT-Firmware by
CommandTerminal/CmdWakePin.cpp@16:3b1d46c1db11, 2017-08-14 (annotated)
- Committer:
- Fran6
- Date:
- Mon Aug 14 12:40:21 2017 +0000
- Revision:
- 16:3b1d46c1db11
- Parent:
- 14:f9a77400b622
mDot AT-Firmware
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
4:666017851052 | 1 | #include "CmdWakePin.h" |
Mike Fiore |
4:666017851052 | 2 | |
Mike Fiore |
14:f9a77400b622 | 3 | CmdWakePin::CmdWakePin() |
Mike Fiore |
14:f9a77400b622 | 4 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
14:f9a77400b622 | 5 | : Command("Wake Pin", "AT+WP", "Wakeup DIO pin of sleep mode (1-8) (default: DI8, 1:DIN), deep-sleep uses DIO7", "(1-8)") |
Mike Fiore |
14:f9a77400b622 | 6 | #else |
Mike Fiore |
14:f9a77400b622 | 7 | : Command("Wake Pin", "AT+WP", "Wakeup GPIO pin of sleep mode (1-6) (default: WAKE, 1:UART1_RX), deep-sleep uses WAKE", "(1-6)") |
Mike Fiore |
14:f9a77400b622 | 8 | #endif /* TARGET_MTS_MDOT_F411RE */ |
Mike Fiore |
14:f9a77400b622 | 9 | { |
Mike Fiore |
4:666017851052 | 10 | _queryable = true; |
Mike Fiore |
4:666017851052 | 11 | } |
Mike Fiore |
4:666017851052 | 12 | |
Mike Fiore |
4:666017851052 | 13 | uint32_t CmdWakePin::action(std::vector<std::string> args) { |
Mike Fiore |
4:666017851052 | 14 | if (args.size() == 1) { |
Mike Fiore |
14:f9a77400b622 | 15 | CommandTerminal::Serial()->writef("%s\r\n", mDot::pinName2Str(CommandTerminal::Dot()->getWakePin()).c_str()); |
Mike Fiore |
4:666017851052 | 16 | } else if (args.size() == 2) { |
Mike Fiore |
9:ff62b20f7000 | 17 | int pin; |
Mike Fiore |
9:ff62b20f7000 | 18 | sscanf(args[1].c_str(), "%d", &pin); |
Mike Fiore |
4:666017851052 | 19 | |
Mike Fiore |
14:f9a77400b622 | 20 | CommandTerminal::Dot()->setWakePin(mDot::pinNum2Name(pin)); |
Mike Fiore |
4:666017851052 | 21 | } |
Mike Fiore |
4:666017851052 | 22 | |
Mike Fiore |
4:666017851052 | 23 | return 0; |
Mike Fiore |
4:666017851052 | 24 | } |
Mike Fiore |
4:666017851052 | 25 | |
Mike Fiore |
4:666017851052 | 26 | bool CmdWakePin::verify(std::vector<std::string> args) { |
Mike Fiore |
4:666017851052 | 27 | if (args.size() == 1) |
Mike Fiore |
4:666017851052 | 28 | return true; |
Mike Fiore |
4:666017851052 | 29 | |
Mike Fiore |
4:666017851052 | 30 | if (args.size() == 2) { |
Mike Fiore |
9:ff62b20f7000 | 31 | int pin; |
Mike Fiore |
9:ff62b20f7000 | 32 | if (sscanf(args[1].c_str(), "%d", &pin) != 1) { |
Mike Fiore |
14:f9a77400b622 | 33 | CommandTerminal::setErrorMessage("Invalid argument"); |
Mike Fiore |
4:666017851052 | 34 | return false; |
Mike Fiore |
4:666017851052 | 35 | } |
Mike Fiore |
4:666017851052 | 36 | |
Mike Fiore |
14:f9a77400b622 | 37 | #if defined(TARGET_MTS_MDOT_F411RE) |
Mike Fiore |
9:ff62b20f7000 | 38 | if (pin < 1 || pin > 8) { |
Mike Fiore |
14:f9a77400b622 | 39 | CommandTerminal::setErrorMessage("Invalid pin, expects (1-8)"); |
Mike Fiore |
14:f9a77400b622 | 40 | #else |
Mike Fiore |
14:f9a77400b622 | 41 | if (pin < 1 || pin > 6) { |
Mike Fiore |
14:f9a77400b622 | 42 | CommandTerminal::setErrorMessage("Invalid pin, expects (1-6)"); |
Mike Fiore |
14:f9a77400b622 | 43 | #endif /* TARGET_MTS_MDOT_F411RE */ |
Mike Fiore |
4:666017851052 | 44 | return false; |
Mike Fiore |
4:666017851052 | 45 | } |
Mike Fiore |
4:666017851052 | 46 | |
Mike Fiore |
4:666017851052 | 47 | return true; |
Mike Fiore |
4:666017851052 | 48 | } |
Mike Fiore |
4:666017851052 | 49 | |
Mike Fiore |
14:f9a77400b622 | 50 | CommandTerminal::setErrorMessage("Invalid arguments"); |
Mike Fiore |
4:666017851052 | 51 | return false; |
Mike Fiore |
4:666017851052 | 52 | } |