diff --git a/Sming/Components/CommandProcessing/component.mk b/Sming/Components/CommandProcessing/component.mk index 3abdb1f5cf..71c9f17265 100644 --- a/Sming/Components/CommandProcessing/component.mk +++ b/Sming/Components/CommandProcessing/component.mk @@ -4,9 +4,6 @@ COMPONENT_SRCDIRS := \ COMPONENT_INCDIRS := $(COMPONENT_SRCDIRS) - -COMPONENT_DEPENDS := FlashString - COMPONENT_DOXYGEN_INPUT := src COMPONENT_DOCFILES := \ diff --git a/Sming/Components/CommandProcessing/samples/Arducam/app/ArduCamCommand.cpp b/Sming/Components/CommandProcessing/samples/Arducam/app/ArduCamCommand.cpp index eefab3ae65..c4bd3cddb3 100644 --- a/Sming/Components/CommandProcessing/samples/Arducam/app/ArduCamCommand.cpp +++ b/Sming/Components/CommandProcessing/samples/Arducam/app/ArduCamCommand.cpp @@ -23,9 +23,9 @@ void ArduCamCommand::initCommand() void ArduCamCommand::showSettings(ReadWriteStream& commandOutput) { // review settings - commandOutput.printf("ArduCam Settings:\n"); - commandOutput.printf(" img Type: [%s]\n", getImageType()); - commandOutput.printf(" img Size: [%s]\n", getImageSize()); + commandOutput << _F("ArduCam Settings:") << endl + << _F(" img Type: [") << getImageType() << ']' << endl + << _F(" img Size: [") << getImageSize() << ']' << endl; }; void ArduCamCommand::processSetCommands(String commandLine, ReadWriteStream& commandOutput) @@ -61,7 +61,6 @@ void ArduCamCommand::processSetCommands(String commandLine, ReadWriteStream& com showSettings(commandOutput); } - // handle command -> settings else if(commandToken[1] == "size") { if(numToken == 3) { if(commandToken[2] == "160") { @@ -109,7 +108,7 @@ void ArduCamCommand::processSetCommands(String commandLine, ReadWriteStream& com } } -void ArduCamCommand::setSize(String size) +void ArduCamCommand::setSize(const String& size) { if(size == "160x120") { imgSize = OV2640_160x120; @@ -151,26 +150,9 @@ void ArduCamCommand::setSize(String size) } } -void ArduCamCommand::setType(String type) +void ArduCamCommand::setType(const String& type) { - if(type == "BMP") { - myCAM.set_format(BMP); - if(imgType != BMP) { - // reset the cam - myCAM.InitCAM(); - imgType = BMP; - imgSize = OV2640_320x240; - } - } else { - myCAM.set_format(JPEG); - // reset the cam - if(imgType != JPEG) { - // reset the cam - myCAM.InitCAM(); - myCAM.OV2640_set_JPEG_size(imgSize); - imgType = JPEG; - } - } + setFormat(type == "BMP" ? BMP : JPEG); } void ArduCamCommand::setFormat(uint8 type) diff --git a/Sming/Components/CommandProcessing/samples/Arducam/app/application.cpp b/Sming/Components/CommandProcessing/samples/Arducam/app/application.cpp index 9b8c7731d3..fdc8ca2ac3 100644 --- a/Sming/Components/CommandProcessing/samples/Arducam/app/application.cpp +++ b/Sming/Components/CommandProcessing/samples/Arducam/app/application.cpp @@ -1,7 +1,6 @@ #include #include -//#include "CamSettings.h" #include #include @@ -42,7 +41,6 @@ HttpServer server; CommandProcessing::Handler commandHandler; -HexDump hdump; ArduCAM myCAM(OV2640, CAM_CS); ArduCamCommand arduCamCommand(myCAM, commandHandler); diff --git a/Sming/Components/CommandProcessing/samples/Arducam/include/ArduCamCommand.h b/Sming/Components/CommandProcessing/samples/Arducam/include/ArduCamCommand.h index 83f15001b7..e3f3ffc1c9 100644 --- a/Sming/Components/CommandProcessing/samples/Arducam/include/ArduCamCommand.h +++ b/Sming/Components/CommandProcessing/samples/Arducam/include/ArduCamCommand.h @@ -16,8 +16,8 @@ class ArduCamCommand virtual ~ArduCamCommand(); void initCommand(); const char* getContentType(); - void setSize(String size); - void setType(String type); + void setSize(const String& size); + void setType(const String& type); private: bool status = true; diff --git a/Sming/Components/CommandProcessing/samples/CommandLine/README.rst b/Sming/Components/CommandProcessing/samples/CommandLine/README.rst index 1c1b9048d8..29324f136a 100644 --- a/Sming/Components/CommandProcessing/samples/CommandLine/README.rst +++ b/Sming/Components/CommandProcessing/samples/CommandLine/README.rst @@ -1,4 +1,4 @@ CommandLine =========== -Demonstrates Sming's CommandProcessing capability via HTTP, FTP and serial interfaces. +Demonstrates Sming's CommandProcessing capability via serial interface. diff --git a/Sming/Components/CommandProcessing/samples/CommandLine/app/application.cpp b/Sming/Components/CommandProcessing/samples/CommandLine/app/application.cpp index 7c1b66d452..c91c116de1 100644 --- a/Sming/Components/CommandProcessing/samples/CommandLine/app/application.cpp +++ b/Sming/Components/CommandProcessing/samples/CommandLine/app/application.cpp @@ -14,22 +14,22 @@ void processExampleCommand(String commandLine, ReadWriteStream& commandOutput) Vector commandToken; int numToken = splitString(commandLine, ' ', commandToken); + // First token is "example" if(numToken == 1) { - commandOutput.printf("Example Commands available : \r\n"); - commandOutput.printf("on : Set example status ON\r\n"); - commandOutput.printf("off : Set example status OFF\r\n"); - commandOutput.printf("status : Show example status\r\n"); + commandOutput << _F("Example Commands available :") << endl; + commandOutput << _F("on : Set example status ON") << endl; + commandOutput << _F("off : Set example status OFF") << endl; + commandOutput << _F("status : Show example status") << endl; + } else if(commandToken[1] == "on") { + exampleStatus = true; + commandOutput << _F("Status ON") << endl; + } else if(commandToken[1] == "off") { + exampleStatus = false; + commandOutput << _F("Status OFF") << endl; + } else if(commandToken[1] == "status") { + commandOutput << _F("Example Status is ") << (exampleStatus ? "ON" : "OFF") << endl; } else { - if(commandToken[1] == "on") { - exampleStatus = true; - commandOutput.printf("Status ON\r\n"); - } else if(commandToken[1] == "off") { - exampleStatus = false; - commandOutput.printf("Status OFF\r\n"); - } else if(commandToken[1] == "status") { - String tempString = exampleStatus ? "ON" : "OFF"; - commandOutput.printf("Example Status is %s\r\n", tempString.c_str()); - }; + commandOutput << _F("Bad command") << endl; } } diff --git a/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.cpp b/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.cpp index 86e42b4f74..540d7b3d49 100644 --- a/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.cpp +++ b/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.cpp @@ -96,18 +96,15 @@ void Handler::processCommandLine(const String& cmdString) void Handler::registerSystemCommands() { String system = F("system"); - registerCommand(Command(F("status"), F("Displays System Information"), system, - Command::Callback(&Handler::procesStatusCommand, this))); - registerCommand(Command(F("echo"), F("Displays command entered"), system, - Command::Callback(&Handler::procesEchoCommand, this))); - registerCommand(Command(F("help"), F("Displays all available commands"), system, - Command::Callback(&Handler::procesHelpCommand, this))); - registerCommand(Command(F("debugon"), F("Set Serial debug on"), system, - Command::Callback(&Handler::procesDebugOnCommand, this))); - registerCommand(Command(F("debugoff"), F("Set Serial debug off"), system, - Command::Callback(&Handler::procesDebugOffCommand, this))); - registerCommand(Command(F("command"), F("Use verbose/silent/prompt as command options"), system, - Command::Callback(&Handler::processCommandOptions, this))); + registerCommand({F("status"), F("Displays System Information"), system, {&Handler::procesStatusCommand, this}}); + registerCommand({F("echo"), F("Displays command entered"), system, {&Handler::procesEchoCommand, this}}); + registerCommand({F("help"), F("Displays all available commands"), system, {&Handler::procesHelpCommand, this}}); + registerCommand({F("debugon"), F("Set Serial debug on"), system, {&Handler::procesDebugOnCommand, this}}); + registerCommand({F("debugoff"), F("Set Serial debug off"), system, {&Handler::procesDebugOffCommand, this}}); + registerCommand({F("command"), + F("Use verbose/silent/prompt as command options"), + system, + {&Handler::processCommandOptions, this}}); } Command Handler::getCommandDelegate(const String& commandString) @@ -150,35 +147,24 @@ void Handler::procesHelpCommand(String commandLine, ReadWriteStream& outputStrea { debug_d("HelpCommand entered"); outputStream.println(_F("Commands available are :")); - for(unsigned idx = 0; idx < registeredCommands.count(); idx++) { - outputStream.print(registeredCommands.valueAt(idx).name); - outputStream.print(" | "); - outputStream.print(registeredCommands.valueAt(idx).group); - outputStream.print(" | "); - outputStream.print(registeredCommands.valueAt(idx).description); - outputStream.print("\r\n"); + for(auto cmd : registeredCommands) { + outputStream << cmd->name << " | " << cmd->group << " | " << cmd->description << endl; } } void Handler::procesStatusCommand(String commandLine, ReadWriteStream& outputStream) { debug_d("StatusCommand entered"); - outputStream.println(_F("Sming Framework Version : " SMING_VERSION)); - outputStream.print(_F("ESP SDK version : ")); - outputStream.print(system_get_sdk_version()); - outputStream.println(); - outputStream.print(_F("Time = ")); - outputStream.print(SystemClock.getSystemTimeString()); - outputStream.println(); - outputStream.printf(_F("System Start Reason : %d\r\n"), system_get_rst_info()->reason); + outputStream << _F("Sming Framework Version : " SMING_VERSION) << endl; + outputStream << _F("ESP SDK version : ") << system_get_sdk_version() << endl; + outputStream << _F("Time = ") << SystemClock.getSystemTimeString() << endl; + outputStream << _F("System Start Reason : ") << system_get_rst_info()->reason << endl; } void Handler::procesEchoCommand(String commandLine, ReadWriteStream& outputStream) { debug_d("HelpCommand entered"); - outputStream.print(_F("You entered : '")); - outputStream.print(commandLine); - outputStream.println('\''); + outputStream << _F("You entered : '") << commandLine << '\'' << endl; } void Handler::procesDebugOnCommand(String commandLine, ReadWriteStream& outputStream) @@ -223,23 +209,19 @@ void Handler::processCommandOptions(String commandLine, ReadWriteStream& outputS break; } setCommandPrompt(commandToken[2]); - outputStream.print(_F("Prompt set to : ")); - outputStream.print(commandToken[2]); - outputStream.println(); + outputStream << _F("Prompt set to : ") << commandToken[2] << endl; break; default: errorCommand = true; } if(errorCommand) { - outputStream.print(_F("Unknown command : ")); - outputStream.print(commandLine); - outputStream.println(); + outputStream << _F("Unknown command : ") << commandLine << endl; } if(printUsage) { - outputStream.println(_F("command usage : \r\n")); - outputStream.println(_F("command verbose : Set verbose mode")); - outputStream.println(_F("command silent : Set silent mode")); - outputStream.println(_F("command prompt 'new prompt' : Set prompt to use")); + outputStream << _F("command usage :") << endl + << _F("command verbose : Set verbose mode") << endl + << _F("command silent : Set silent mode") << endl + << _F("command prompt 'new prompt' : Set prompt to use") << endl; } } diff --git a/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.h b/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.h index 243548ab92..25a7f6569e 100644 --- a/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.h +++ b/Sming/Components/CommandProcessing/src/CommandProcessing/Handler.h @@ -132,7 +132,7 @@ class Handler /** @brief Get the verbose mode * @retval VerboseMode Verbose mode */ - bool isVerbose() + bool isVerbose() const { return verboseMode; } @@ -150,7 +150,7 @@ class Handler * @note This is what is shown on the command line before user input * Default is Sming> */ - String getCommandPrompt() + const String& getCommandPrompt() const { return currentPrompt; } @@ -169,7 +169,7 @@ class Handler * @retval char The EOL character * @note Only supports one EOL, unlike Windows */ - char getCommandEOL() + char getCommandEOL() const { return currentEOL; } @@ -187,7 +187,7 @@ class Handler * @retval String The welcome message that is shown when clients connect * @note Only if verbose mode is enabled */ - String getCommandWelcomeMessage() + const String& getCommandWelcomeMessage() const { return currentWelcomeMessage; } diff --git a/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.cpp b/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.cpp new file mode 100644 index 0000000000..d044b19a52 --- /dev/null +++ b/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.cpp @@ -0,0 +1,15 @@ +#include "Utils.h" + +namespace CommandProcessing +{ +void enable(Handler& commandHandler, HardwareSerial& serial) +{ + commandHandler.setOutputStream(&serial, false); + Serial.onDataReceived([&commandHandler](Stream& source, char arrivedChar, uint16_t availableCharsCount) { + while(availableCharsCount--) { + commandHandler.process(source.read()); + } + }); +} + +} // namespace CommandProcessing diff --git a/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.h b/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.h index d66b7c333e..7ffd2cbac4 100644 --- a/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.h +++ b/Sming/Components/CommandProcessing/src/CommandProcessing/Utils.h @@ -5,14 +5,6 @@ namespace CommandProcessing { -void enable(Handler& commandHandler, HardwareSerial& serial) -{ - commandHandler.setOutputStream(&serial, false); - Serial.onDataReceived([&commandHandler](Stream& source, char arrivedChar, uint16_t availableCharsCount) { - while(availableCharsCount--) { - commandHandler.process(source.read()); - } - }); -} +void enable(Handler& commandHandler, HardwareSerial& serial); } // namespace CommandProcessing diff --git a/Sming/Core/HardwareSerial.h b/Sming/Core/HardwareSerial.h index c42dc8e27b..4416c338b2 100644 --- a/Sming/Core/HardwareSerial.h +++ b/Sming/Core/HardwareSerial.h @@ -114,10 +114,6 @@ class HardwareSerial : public ReadWriteStream { } - ~HardwareSerial() - { - } - void setPort(int uartPort) { end(); diff --git a/Sming/Libraries/USB b/Sming/Libraries/USB index 9055f1b444..ae08687c90 160000 --- a/Sming/Libraries/USB +++ b/Sming/Libraries/USB @@ -1 +1 @@ -Subproject commit 9055f1b4443d3bd5fbdd08147c74a6f0528a6a8a +Subproject commit ae08687c900582a94db86d4cff1c492317e52307 diff --git a/Sming/Libraries/USB.patch b/Sming/Libraries/USB.patch deleted file mode 100644 index 03bf285c67..0000000000 --- a/Sming/Libraries/USB.patch +++ /dev/null @@ -1,115 +0,0 @@ -diff --git a/component.mk b/component.mk -index 7f92e46..910e866 100644 ---- a/component.mk -+++ b/component.mk -@@ -27,6 +27,10 @@ CFG_TUSB_MCU := OPT_MCU_NONE - GLOBAL_CFLAGS += -DTUP_DCD_ENDPOINT_MAX=16 - endif - -+ -+COMPONENT_VARS += ENABLE_CMD_EXECUTOR -+ENABLE_CMD_EXECUTOR ?= 1 -+ - COMPONENT_VARS += USB_DEBUG_LEVEL - USB_DEBUG_LEVEL ?= 0 - -diff --git a/samples/Basic_Device/app/application.cpp b/samples/Basic_Device/app/application.cpp -index c294b25..81ec7bf 100644 ---- a/samples/Basic_Device/app/application.cpp -+++ b/samples/Basic_Device/app/application.cpp -@@ -231,7 +231,9 @@ void init() - timer.initializeMs<3000>(InterruptCallback([]() { - debug_i("Alive"); - // Un-comment this to demonstrated how to send keystrokes to the connected PC! -- // sendText(); -+#if CFG_TUD_HID -+ sendText(); -+#endif - })); - timer.start(); - } -diff --git a/src/USB/CDC/UsbSerial.cpp b/src/USB/CDC/UsbSerial.cpp -index b163726..29a27d6 100644 ---- a/src/USB/CDC/UsbSerial.cpp -+++ b/src/USB/CDC/UsbSerial.cpp -@@ -24,10 +24,6 @@ - #include "Platform/System.h" - #include - --#if ENABLE_CMD_EXECUTOR --#include --#endif -- - namespace USB::CDC - { - UsbSerial::UsbSerial() -@@ -72,10 +68,10 @@ void UsbSerial::processEvents() - receiveCallback(*this, peek(), available()); - } - #if ENABLE_CMD_EXECUTOR -- if(commandExecutor) { -+ if(commandHandler) { - uint8_t ch; - while(readBytes(&ch, 1)) { -- commandExecutor->executorReceive(ch); -+ commandHandler->process(ch); - } - } - #endif -@@ -114,11 +110,11 @@ void UsbSerial::commandProcessing(bool reqEnable) - { - #if ENABLE_CMD_EXECUTOR - if(reqEnable) { -- if(!commandExecutor) { -- commandExecutor.reset(new CommandExecutor(this)); -+ if(commandHandler) { -+ CommandProcessing::enable(commandHandler, *this); - } - } else { -- commandExecutor.reset(); -+ commandHandler = nullptr; - } - #endif - } -diff --git a/src/USB/CDC/UsbSerial.h b/src/USB/CDC/UsbSerial.h -index daa3616..45f0216 100644 ---- a/src/USB/CDC/UsbSerial.h -+++ b/src/USB/CDC/UsbSerial.h -@@ -24,6 +24,10 @@ - #include - #include - -+#if ENABLE_CMD_EXECUTOR -+#include -+#endif -+ - namespace USB::CDC - { - enum class Event { -@@ -44,7 +48,14 @@ public: - using TransmitComplete = Delegate; - - UsbSerial(); -- ~UsbSerial(); -+ -+#if ENABLE_CMD_EXECUTOR -+ UsbSerial(CommandProcessing::CommandHandler& commandHandler): commandHandler(&commandHandler) -+ { -+ } -+#endif -+ -+ virtual ~UsbSerial(); - - /** - * @brief Sets receiving buffer size -@@ -131,7 +142,9 @@ private: - - DataReceived receiveCallback; - TransmitComplete transmitCompleteCallback; -- std::unique_ptr commandExecutor; -+#if ENABLE_CMD_EXECUTOR -+ CommandProcessing::CommandHandler* commandHandler{nullptr}; -+#endif - uint16_t status{0}; - BitSet eventMask; - };