add a pause of 5 seconds after issuing reset so the user can exit the console
authorJim Morris <morris@wolfman.com>
Mon, 25 Feb 2013 05:09:40 +0000 (21:09 -0800)
committerJim Morris <morris@wolfman.com>
Mon, 25 Feb 2013 05:14:24 +0000 (21:14 -0800)
src/modules/utils/simpleshell/SimpleShell.cpp
src/modules/utils/simpleshell/SimpleShell.h

index 34d5f3a..e577408 100644 (file)
 void SimpleShell::on_module_loaded(){
     this->current_path = "/";
     this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
+    this->reset_delay_secs= 0;
+    
+    register_for_event(ON_IDLE);
+}
+
+void SimpleShell::on_idle(void*) {
+    // we are timing out for the reset
+    if (this->reset_delay_secs) {
+        if(time(NULL) >= this->reset_delay_secs){
+            system_reset(false);
+        }
+    }
 }
 
 // When a new line is received, check if it is a command, and if it is, act upon it
@@ -132,8 +144,8 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){
 
 // Reset the system
 void SimpleShell::reset_command( string parameters, StreamOutput* stream){
-    stream->printf("Smoothie out. Peace.\r\n");
-    system_reset(false);
+    stream->printf("Smoothie out. Peace. Rebooting in 5 seconds...\r\n");
+    this->reset_delay_secs= time(NULL) + 5; // reboot in 5 seconds
 }
 
 // go into dfu boot mode
@@ -159,7 +171,7 @@ void SimpleShell::help_command( string parameters, StreamOutput* stream ){
     stream->printf("abort - abort currently playing file\r\n");
     stream->printf("reset - reset smoothie\r\n");           
     stream->printf("dfu - enter dfu boot loader\r\n");          
-    stream->printf("break- break into debugger\r\n");           
+    stream->printf("break - break into debugger\r\n");          
     stream->printf("config-get [<configuration_source>] <configuration_setting>\r\n");
     stream->printf("config-set [<configuration_source>] <configuration_setting> <value>\r\n");
     stream->printf("config-load [<file_name>]\r\n");
index fb278ee..065dddd 100644 (file)
@@ -14,6 +14,7 @@
 #include "libs/utils.h"
 #include "libs/StreamOutput.h"
 
+#include "mbed.h" // for time_t and time()
 
 #define ls_command_checksum       CHECKSUM("ls")
 #define cd_command_checksum       CHECKSUM("cd")
@@ -30,6 +31,7 @@ class SimpleShell : public Module {
 
         void on_module_loaded();
         void on_console_line_received( void* argument );
+        void on_idle(void*);
         string absolute_from_relative( string path );
         void ls_command(   string parameters, StreamOutput* stream );
         void cd_command(   string parameters, StreamOutput* stream );
@@ -42,6 +44,7 @@ class SimpleShell : public Module {
         
     private:
         string current_path;
+        time_t reset_delay_secs;
 };