// 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();
}
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;
}
// 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();
}
}
// 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();
}
}
}
// 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
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
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");
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 );
}
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 ) );
}
// 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]));
}
}
// 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
// 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 ){
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();
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();
}
}
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;
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;
}
}
pid_process(temperature);
if ((temperature > target_temperature) && waiting)
{
- kernel->pauser->release();
+ THEKERNEL->pauser->release();
waiting = false;
}
}
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) {
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);
}
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;
}
class I2CLCD : public LcdBase {
public:
I2CLCD() {
- Kernel* kernel= THEKERNEL;
// Default values
this->i2c_address = 0x27;
this->backlightval = 0x00;
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() {
}
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) {