replace all uses of module::kernel pointer with kernel::instance singleton pointer
authorMichael Moon <triffid.hunter@gmail.com>
Fri, 27 Dec 2013 02:09:01 +0000 (13:09 +1100)
committerMichael Moon <triffid.hunter@gmail.com>
Fri, 27 Dec 2013 02:09:01 +0000 (13:09 +1100)
13 files changed:
src/libs/Kernel.cpp
src/libs/SlowTicker.cpp
src/libs/USBDevice/USBMSD/USBMSD.cpp
src/libs/USBDevice/USBSerial/USBSerial.cpp
src/modules/communication/GcodeDispatch.cpp
src/modules/robot/Block.cpp
src/modules/robot/Block.h
src/modules/robot/Planner.cpp
src/modules/tools/extruder/Extruder.cpp
src/modules/tools/temperaturecontrol/TemperatureControl.cpp
src/modules/utils/PlayLed/PlayLed.cpp
src/modules/utils/panel/panels/I2CLCD.h
src/modules/utils/player/Player.cpp

index 0ab71f7..f87d4d3 100644 (file)
@@ -109,7 +109,6 @@ Kernel::Kernel(){
 
 // Add a module to Kernel. We don't actually hold a list of modules, we just tell it where Kernel is
 void Kernel::add_module(Module* module){
-    module->kernel = this;
     module->on_module_loaded();
 }
 
index cd173ff..9365a2d 100644 (file)
@@ -124,7 +124,7 @@ extern GPIO leds[];
 void SlowTicker::on_idle(void*)
 {
     static uint16_t ledcnt= 0;
-    if(kernel->use_leds) {
+    if(THEKERNEL->use_leds) {
         // flash led 3 to show we are alive
         leds[2]= (ledcnt++ & 0x1000) ? 1 : 0;
     }
@@ -132,13 +132,13 @@ void SlowTicker::on_idle(void*)
     // 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();
     }
 }
 
@@ -177,7 +177,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();
                 }
             }
         }
index 077273e..94b6bc9 100644 (file)
@@ -70,7 +70,7 @@
 // max packet size\r
 #define MAX_PACKET  MAX_PACKET_SIZE_EPBULK\r
 \r
-// #define iprintf(...) kernel->streams->printf(__VA_ARGS__)\r
+// #define iprintf(...) THEKERNEL->streams->printf(__VA_ARGS__)\r
 #define iprintf(...) do { } while (0)\r
 \r
 // CSW Status\r
index 9b0a32d..56c995d 100644 (file)
@@ -266,13 +266,13 @@ void USBSerial::on_main_loop(void *argument)
         if (attach)\r
         {\r
             attached = true;\r
-            kernel->streams->append_stream(this);\r
+            THEKERNEL->streams->append_stream(this);\r
             writeBlock((const uint8_t *) "Smoothie\nok\n", 12);\r
         }\r
         else\r
         {\r
             attached = false;\r
-            kernel->streams->remove_stream(this);\r
+            THEKERNEL->streams->remove_stream(this);\r
             txbuf.flush();\r
             rxbuf.flush();\r
             nl_in_rx = 0;\r
index 1b27e1c..b84da87 100644 (file)
@@ -122,27 +122,27 @@ void GcodeDispatch::on_console_line_received(void *line)
 
                             case 500: // M500 save volatile settings to config-override
                                 // delete the existing file
-                                remove(kernel->config_override_filename());
+                                remove(THEKERNEL->config_override_filename());
                                 // replace stream with one that writes to config-override file
-                                gcode->stream = new FileStream(kernel->config_override_filename());
+                                gcode->stream = new FileStream(THEKERNEL->config_override_filename());
                                 // dispatch the M500 here so we can free up the stream when done
                                 THEKERNEL->call_event(ON_GCODE_RECEIVED, gcode );
                                 delete gcode->stream;
                                 delete gcode;
-                                new_message.stream->printf("Settings Stored to %s\r\nok\r\n", kernel->config_override_filename());
+                                new_message.stream->printf("Settings Stored to %s\r\nok\r\n", THEKERNEL->config_override_filename());
                                 continue;
 
                             case 501: // M501 deletes config-override so everything defaults to what is in config
-                                remove(kernel->config_override_filename());
-                                new_message.stream->printf("config override file deleted %s, reboot needed\r\nok\r\n", kernel->config_override_filename());
+                                remove(THEKERNEL->config_override_filename());
+                                new_message.stream->printf("config override file deleted %s, reboot needed\r\nok\r\n", THEKERNEL->config_override_filename());
                                 delete gcode;
                                 continue;
 
                             case 503: { // M503 display live settings and indicates if there is an override file
-                                FILE *fd = fopen(kernel->config_override_filename(), "r");
+                                FILE *fd = fopen(THEKERNEL->config_override_filename(), "r");
                                 if(fd != NULL) {
                                     fclose(fd);
-                                    new_message.stream->printf("; config override present: %s\n",  kernel->config_override_filename());
+                                    new_message.stream->printf("; config override present: %s\n",  THEKERNEL->config_override_filename());
 
                                 } else {
                                     new_message.stream->printf("; No config override\n");
index 2cfe9a5..80a9f96 100644 (file)
@@ -30,8 +30,8 @@ Block::Block(){
     this->final_rate = -1;
 }
 
-void Block::debug(Kernel* kernel){
-    kernel->streams->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8f acc:%5d dec:%5d rates:%10d>%10d taken:%d ready:%d \r\n", this, this->steps[0], this->steps[1], this->steps[2], this->steps_event_count, this->nominal_rate, this->nominal_speed, this->millimeters, this->rate_delta, this->accelerate_until, this->decelerate_after, this->initial_rate, this->final_rate, this->times_taken, this->is_ready );
+void Block::debug(){
+    THEKERNEL->streams->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8f acc:%5d dec:%5d rates:%10d>%10d taken:%d ready:%d \r\n", this, this->steps[0], this->steps[1], this->steps[2], this->steps_event_count, this->nominal_rate, this->nominal_speed, this->millimeters, this->rate_delta, this->accelerate_until, this->decelerate_after, this->initial_rate, this->final_rate, this->times_taken, this->is_ready );
 }
 
 
@@ -51,7 +51,7 @@ void Block::calculate_trapezoid( double entryfactor, double exitfactor ){
     this->final_rate   = ceil(this->nominal_rate * exitfactor);    // (step/min)
 
     // How many steps to accelerate and decelerate
-    double acceleration_per_minute = this->rate_delta * this->planner->kernel->stepper->acceleration_ticks_per_second * 60.0; // ( step/min^2)
+    double acceleration_per_minute = this->rate_delta * THEKERNEL->stepper->acceleration_ticks_per_second * 60.0; // ( step/min^2)
     int accelerate_steps = ceil( this->estimate_acceleration_distance( this->initial_rate, this->nominal_rate, acceleration_per_minute ) );
     int decelerate_steps = floor( this->estimate_acceleration_distance( this->nominal_rate, this->final_rate,  -acceleration_per_minute ) );
 
@@ -163,10 +163,10 @@ void Block::append_gcode(Gcode* gcode){
 }
 
 // The attached gcodes are then poped and the on_gcode_execute event is called with them as a parameter
-void Block::pop_and_execute_gcode(Kernel* &kernel){
+void Block::pop_and_execute_gcode(){
     Block* block = const_cast<Block*>(this);
     for(unsigned short index=0; index<block->gcodes.size(); index++){
-        kernel->call_event(ON_GCODE_EXECUTE, &(block->gcodes[index]));
+        THEKERNEL->call_event(ON_GCODE_EXECUTE, &(block->gcodes[index]));
     }
 }
 
@@ -191,11 +191,11 @@ void Block::release(){
 
         // All modules are done with this block
         // Call the on_block_end event so all modules can act accordingly
-        this->conveyor->kernel->call_event(ON_BLOCK_END, this);
+        THEKERNEL->call_event(ON_BLOCK_END, this);
 
         // Gcodes corresponding to the *following* blocks are stored in this block. 
         // We execute them all in order when this block is finished executing
-        this->pop_and_execute_gcode(this->conveyor->kernel);
+        this->pop_and_execute_gcode();
        
         // We would normally delete this block directly here, but we can't, because this is interrupt context, no crazy memory stuff here
         // So instead we increment a counter, and it will be deleted in main loop context 
@@ -216,7 +216,7 @@ void Block::release(){
 
                     // Execute this candidate
                     conveyor->current_block = candidate;
-                    conveyor->kernel->call_event(ON_BLOCK_BEGIN, conveyor->current_block);
+                    THEKERNEL->call_event(ON_BLOCK_BEGIN, conveyor->current_block);
 
                     // If no module took this block, release it ourselves, as nothing else will do it otherwise
                     if( conveyor->current_block->times_taken < 1 ){
index 3dc6293..491ed68 100644 (file)
@@ -28,9 +28,9 @@ class Block {
         double intersection_distance(double initial_rate, double final_rate, double acceleration, double distance);
         void reverse_pass(Block* previous);
         void forward_pass(Block* next);
-        void debug(Kernel* kernel);
+        void debug();
         void append_gcode(Gcode* gcode);
-        void pop_and_execute_gcode(Kernel* &kernel);
+        void pop_and_execute_gcode();
         double get_duration_left(unsigned int already_taken_steps);
         void take();
         void release();
index 9c34076..6c657ee 100644 (file)
@@ -239,7 +239,7 @@ void Planner::dump_queue(){
     for( int index = 0; index <= THEKERNEL->conveyor->queue.size()-1; index++ ){
        if( index > 10 && index < THEKERNEL->conveyor->queue.size()-10 ){ continue; }
        THEKERNEL->streams->printf("block %03d > ", index);
-       THEKERNEL->conveyor->queue.get_ref(index)->debug(THEKERNEL);
+       THEKERNEL->conveyor->queue.get_ref(index)->debug();
     }
 }
 
index 621e05a..6c464ff 100644 (file)
@@ -264,9 +264,9 @@ void Extruder::on_gcode_execute(void* argument){
             if (gcode->has_letter('F'))
             {
                 this->feed_rate = gcode->get_value('F');
-                if (this->feed_rate > (this->max_speed * kernel->robot->seconds_per_minute))
-                    this->feed_rate = this->max_speed * kernel->robot->seconds_per_minute;
-                feed_rate /= kernel->robot->seconds_per_minute;
+                if (this->feed_rate > (this->max_speed * THEKERNEL->robot->seconds_per_minute))
+                    this->feed_rate = this->max_speed * THEKERNEL->robot->seconds_per_minute;
+                feed_rate /= THEKERNEL->robot->seconds_per_minute;
             }
         }else if( gcode->g == 90 ){ this->absolute_mode = true;
         }else if( gcode->g == 91 ){ this->absolute_mode = false;
index d202c8d..a746b59 100644 (file)
@@ -44,7 +44,7 @@ void TemperatureControl::on_module_loaded(){
 
 void TemperatureControl::on_main_loop(void* argument){
     if (this->min_temp_violated) {
-        kernel->streams->printf("Error: MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
+        THEKERNEL->streams->printf("Error: MINTEMP triggered on P%d.%d! check your thermistors!\n", this->thermistor_pin.port_number, this->thermistor_pin.pin);
         this->min_temp_violated = false;
     }
 }
@@ -287,7 +287,7 @@ uint32_t TemperatureControl::thermistor_read_tick(uint32_t dummy){
             pid_process(temperature);
             if ((temperature > target_temperature) && waiting)
             {
-                kernel->pauser->release();
+                THEKERNEL->pauser->release();
                 waiting = false;
             }
         }
@@ -345,7 +345,7 @@ int TemperatureControl::new_thermistor_reading()
 void TemperatureControl::on_second_tick(void* argument)
 {
     if (waiting)
-        kernel->streams->printf("%s:%3.1f /%3.1f @%d\n", designator.c_str(), get_temperature(), ((target_temperature == UNDEFINED)?0.0:target_temperature), o);
+        THEKERNEL->streams->printf("%s:%3.1f /%3.1f @%d\n", designator.c_str(), get_temperature(), ((target_temperature == UNDEFINED)?0.0:target_temperature), o);
 }
 
 void TemperatureControl::setPIDp(double p) {
index 3c67dc3..4be281d 100644 (file)
@@ -23,15 +23,15 @@ void PlayLed::on_module_loaded()
 
     on_config_reload(this);
 
-    kernel->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
+    THEKERNEL->slow_ticker->attach(4, this, &PlayLed::half_second_tick);
 }
 
 void PlayLed::on_config_reload(void* argument)
 {
     string ledpin = "4.28!";
 
-    ledpin = kernel->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
-    ledpin = kernel->config->value( play_led_pin_checksum  )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
+    ledpin = THEKERNEL->config->value( pause_led_pin_checksum )->by_default(ledpin)->as_string(); // check for pause_led_pin first
+    ledpin = THEKERNEL->config->value( play_led_pin_checksum  )->by_default(ledpin)->as_string(); // override with play_led_pin if it's found
 
     led.from_string(ledpin)->as_output()->set(false);
 }
@@ -53,9 +53,9 @@ void PlayLed::on_play(void* argument)
 
 uint32_t PlayLed::half_second_tick(uint32_t)
 {
-    if (kernel->pauser->paused())
+    if (THEKERNEL->pauser->paused())
         led.set(!led.get());
-    else led.set(!kernel->conveyor->is_queue_empty());
+    else led.set(!THEKERNEL->conveyor->is_queue_empty());
 
     return 0;
 }
index 3e9b8db..d23f514 100644 (file)
@@ -76,7 +76,6 @@ using namespace std;
 class I2CLCD : public LcdBase {
     public:
         I2CLCD() {
-            Kernel* kernel= THEKERNEL;
             // Default values
             this->i2c_address      = 0x27;
             this->backlightval     = 0x00;
@@ -88,11 +87,11 @@ class I2CLCD : public LcdBase {
             this->i2c = new mbed::I2C(P0_27, P0_28);   
         
             // configure the pins to use
-            this->encoder_a_pin.from_string(kernel->config->value( panel_checksum, encoder_a_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
-            this->encoder_b_pin.from_string(kernel->config->value( panel_checksum, encoder_b_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
-            this->click_pin.from_string(kernel->config->value( panel_checksum, click_button_pin_checksum )->by_default("nc")->as_string())->as_input()->pull_up();
-            this->up_pin.from_string(kernel->config->value( panel_checksum, up_button_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
-            this->down_pin.from_string(kernel->config->value( panel_checksum, down_button_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
+            this->encoder_a_pin.from_string(THEKERNEL->config->value( panel_checksum, encoder_a_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
+            this->encoder_b_pin.from_string(THEKERNEL->config->value( panel_checksum, encoder_b_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
+            this->click_pin.from_string(THEKERNEL->config->value( panel_checksum, click_button_pin_checksum )->by_default("nc")->as_string())->as_input()->pull_up();
+            this->up_pin.from_string(THEKERNEL->config->value( panel_checksum, up_button_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
+            this->down_pin.from_string(THEKERNEL->config->value( panel_checksum, down_button_pin_checksum)->by_default("nc")->as_string())->as_input()->pull_up();
 
         }
         virtual ~I2CLCD() {
index d32ed56..12c89d0 100644 (file)
@@ -34,7 +34,7 @@ void Player::on_module_loaded(){
 }
 
 void Player::on_second_tick(void*) {
-     if (!kernel->pauser->paused()) this->elapsed_secs++;
+     if (!THEKERNEL->pauser->paused()) this->elapsed_secs++;
 }
 
 void Player::on_gcode_received(void *argument) {