use on_second_tick for reset timeout as smoothie board doesn't have a crysal on its RTC
authorJim Morris <morris@wolfman.com>
Wed, 6 Mar 2013 02:27:03 +0000 (18:27 -0800)
committerJim Morris <morris@wolfman.com>
Wed, 6 Mar 2013 02:27:03 +0000 (18:27 -0800)
src/modules/utils/simpleshell/SimpleShell.cpp
src/modules/utils/simpleshell/SimpleShell.h

index d3f764f..f642290 100644 (file)
@@ -22,13 +22,13 @@ void SimpleShell::on_module_loaded(){
     this->register_for_event(ON_CONSOLE_LINE_RECEIVED);
     this->reset_delay_secs= 0;
     
-    register_for_event(ON_IDLE);
+    register_for_event(ON_SECOND_TICK);
 }
 
-void SimpleShell::on_idle(void*) {
+void SimpleShell::on_second_tick(void*) {
     // we are timing out for the reset
-    if (this->reset_delay_secs) {
-        if(time(NULL) >= this->reset_delay_secs){
+    if (this->reset_delay_secs > 0) {
+        if(--this->reset_delay_secs == 0){
             system_reset(false);
         }
     }
@@ -146,7 +146,7 @@ void SimpleShell::cat_command( string parameters, StreamOutput* stream ){
 // Reset the system
 void SimpleShell::reset_command( string parameters, StreamOutput* stream){
     stream->printf("Smoothie out. Peace. Rebooting in 5 seconds...\r\n");
-    this->reset_delay_secs= time(NULL) + 5; // reboot in 5 seconds
+    this->reset_delay_secs= 5; // reboot in 5 seconds
 }
 
 // go into dfu boot mode
index 065dddd..4246b39 100644 (file)
@@ -14,8 +14,6 @@
 #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")
 #define pwd_command_checksum      CHECKSUM("pwd")
@@ -31,7 +29,7 @@ class SimpleShell : public Module {
 
         void on_module_loaded();
         void on_console_line_received( void* argument );
-        void on_idle(void*);
+        void on_second_tick(void*);
         string absolute_from_relative( string path );
         void ls_command(   string parameters, StreamOutput* stream );
         void cd_command(   string parameters, StreamOutput* stream );
@@ -44,7 +42,7 @@ class SimpleShell : public Module {
         
     private:
         string current_path;
-        time_t reset_delay_secs;
+        int reset_delay_secs;
 };