move the on_halt call into on_idle instead of from ISR
authorJim Morris <morris@wolfman.com>
Mon, 3 Nov 2014 20:26:03 +0000 (12:26 -0800)
committerJim Morris <morris@wolfman.com>
Mon, 3 Nov 2014 20:26:03 +0000 (12:26 -0800)
src/modules/utils/pausebutton/PauseButton.cpp
src/modules/utils/pausebutton/PauseButton.h

index a91d55f..8f72794 100644 (file)
@@ -22,6 +22,7 @@ PauseButton::PauseButton()
 {
     this->button_state = true;
     this->killed = false;
+    this->do_kill= false;
 }
 
 void PauseButton::on_module_loaded()
@@ -36,7 +37,7 @@ void PauseButton::on_module_loaded()
         this->pause_enable = false;
 
     } else if(this->kill_enable && !this->kill_button.connected() && !this->pause_enable && pause_button.connected()) {
-        // use pause button for kill button
+        // use pause button for kill button if kill buttin not specifically defined
         this->kill_button = this->pause_button;
     }
 
@@ -44,11 +45,22 @@ void PauseButton::on_module_loaded()
 
     if( (this->pause_enable && this->pause_button.connected()) || (this->kill_enable && this->kill_button.connected()) ) {
         THEKERNEL->slow_ticker->attach( 100, this, &PauseButton::button_tick );
+        this->register_for_event(ON_IDLE);
+    }
+}
+
+void PauseButton::on_idle(void *argument)
+{
+    if(do_kill) {
+        do_kill= false;
+        THEKERNEL->call_event(ON_HALT);
+        THEKERNEL->streams->printf("Kill button pressed - reset or M999 to continue\r\n");
     }
 }
 
 //TODO: Make this use InterruptIn
 //Check the state of the button and act accordingly based on current pause state
+// Note this is ISR sodon;t do anything nasty in here
 uint32_t PauseButton::button_tick(uint32_t dummy)
 {
     // If pause button changed
@@ -69,8 +81,9 @@ uint32_t PauseButton::button_tick(uint32_t dummy)
 
     if(!this->killed && this->kill_enable && this->kill_button.connected() && !this->kill_button.get()) {
         this->killed = true;
-        THEKERNEL->call_event(ON_HALT);
-        //THEKERNEL->streams->printf("Kill button pressed - reset required to continue\r\n"); // not in an interrupt
+        // we can't call this in ISR, and we need to block on_main_loop so do it in on_idle
+        // THEKERNEL->call_event(ON_HALT);
+        this->do_kill= true;
     }
 
     return 0;
index d822e63..7ca6222 100644 (file)
@@ -9,6 +9,7 @@ class PauseButton : public Module {
 
         void on_module_loaded();
         void on_console_line_received( void *argument );
+        void on_idle(void *argument);
         uint32_t button_tick(uint32_t dummy);
 
     private:
@@ -19,6 +20,7 @@ class PauseButton : public Module {
             bool kill_enable:1;
             bool button_state:1;
             bool killed:1;
+            volatile bool do_kill:1;
         };
 };