provide one method to add gcode to blocks, reduce code duplication
[clinton/Smoothieware.git] / src / libs / SlowTicker.cpp
index 4557916..6961472 100644 (file)
@@ -37,7 +37,7 @@ SlowTicker::SlowTicker(){
 
     // TODO: What is this ??
     flag_1s_flag = 0;
-    flag_1s_count = SystemCoreClock;
+    flag_1s_count = SystemCoreClock>>2;
 
     g4_ticks = 0;
     g4_pause = false;
@@ -55,6 +55,7 @@ void SlowTicker::set_frequency( int frequency ){
     LPC_TIM2->MR0 = this->interval;
     LPC_TIM2->TCR = 3;  // Reset
     LPC_TIM2->TCR = 1;  // Reset
+    flag_1s_count= SystemCoreClock>>2;
 }
 
 // The actual interrupt being called by the timer, this is where work is done
@@ -118,18 +119,26 @@ bool SlowTicker::flag_1s(){
     return false;
 }
 
+#include "gpio.h"
+extern GPIO leds[];
 void SlowTicker::on_idle(void*)
 {
+    static uint16_t ledcnt= 0;
+    if(THEKERNEL->use_leds) {
+        // flash led 3 to show we are alive
+        leds[2]= (ledcnt++ & 0x1000) ? 1 : 0;
+    }
+
     // if interrupt has set the 1 second flag
     if (flag_1s())
         // fire the on_second_tick event
-        kernel->call_event(ON_SECOND_TICK);
+        THEKERNEL->call_event(ON_SECOND_TICK);
 
     // if G4 has finished, release our pause
     if (g4_pause && (g4_ticks == 0))
     {
         g4_pause = false;
-        kernel->pauser->release();
+        THEKERNEL->pauser->release();
     }
 }
 
@@ -138,12 +147,7 @@ void SlowTicker::on_gcode_received(void* argument){
     Gcode* gcode = static_cast<Gcode*>(argument);
     // Add the gcode to the queue ourselves if we need it
     if( gcode->has_g && gcode->g == 4 ){
-        if( this->kernel->conveyor->queue.size() == 0 ){
-            this->kernel->call_event(ON_GCODE_EXECUTE, gcode );
-        }else{
-            Block* block = this->kernel->conveyor->queue.get_ref( this->kernel->conveyor->queue.size() - 1 );
-            block->append_gcode(gcode);
-        }
+        THEKERNEL->conveyor->append_gcode(gcode);
     }
 }
 
@@ -168,7 +172,7 @@ void SlowTicker::on_gcode_execute(void* argument){
                 // at 120MHz core clock, the longest possible delay is (2^32 / (120MHz / 4)) = 143 seconds
                 if (!g4_pause){
                     g4_pause = true;
-                    kernel->pauser->take();
+                    THEKERNEL->pauser->take();
                 }
             }
         }