if( candidate.compare(setting) != 0 ){ buffer.clear(); continue; }
int free_space = int(int(buffer.find_first_of("\r\n#", begin_value+1))-begin_value);
if( int(value.length()) >= free_space ){
- //this->kernel->serial->printf("ERROR: Not enough room for value\r\n");
+ //this->kernel->streams->printf("ERROR: Not enough room for value\r\n");
fclose(lp);
return;
}
}
} while (c != EOF);
fclose(lp);
- //this->kernel->serial->printf("ERROR: configuration key not found\r\n");
+ //this->kernel->streams->printf("ERROR: configuration key not found\r\n");
}
// Return the value for a specific checksum
#include "libs/Adc.h"
#include "libs/Digipot.h"
#include "libs/Pauser.h"
+#include "libs/StreamOutputPool.h"
#include "modules/communication/SerialConsole.h"
#include "modules/communication/GcodeDispatch.h"
// Config first, because we need the baud_rate setting before we start serial
this->config = new Config();
// Serial second, because the other modules might want to say something
- this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
+ this->streams = new StreamOutputPool();
+ this->serial = new SerialConsole(USBTX, USBRX, this->config->value(uart0_checksum,baud_rate_setting_checksum)->by_default(9600)->as_number());
+
this->add_module( this->config );
this->add_module( this->serial );
-
+
// HAL stuff
this->slow_ticker = new SlowTicker();
this->step_ticker = new StepTicker();
#include "libs/Module.h"
#include "libs/Config.h"
#include "libs/SlowTicker.h"
+#include "libs/StreamOutputPool.h"
#include "libs/StepTicker.h"
#include "libs/Adc.h"
#include "libs/Digipot.h"
// These modules are aviable to all other modules
SerialConsole* serial;
+ StreamOutputPool* streams;
+
GcodeDispatch* gcode_dispatch;
Robot* robot;
Stepper* stepper;
+/*
+ This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
+ Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef STREAMOUTPUT_H
#define STREAMOUTPUT_H
--- /dev/null
+/*
+ This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
+ Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef STREAMOUTPUTPOOL_H
+#define STREAMOUTPUTPOOL_H
+
+using namespace std;
+#include <vector>
+#include <string>
+#include <cstdio>
+#include <cstdarg>
+
+#include "libs/StreamOutput.h"
+
+
+
+class StreamOutputPool {
+ public:
+ StreamOutputPool(){}
+ int printf(const std::string format, ...){
+ // Make the message
+ va_list args;
+ va_start(args, format);
+ int size = format.size() * 2;
+ char* buffer = new char[size];
+ while (vsprintf(buffer, format.c_str(), args) < 0){
+ delete[] buffer;
+ size *= 2;
+ buffer = new char[size];
+ }
+ string message = std::string(buffer);
+ va_end(args);
+
+ // Dispatch to all
+ for(unsigned int i=0; i < this->streams.size(); i++){
+ this->streams.at(i)->printf(message.c_str());
+ }
+
+ }
+
+ void append_stream(StreamOutput* stream){
+ this->streams.push_back(stream);
+ }
+
+
+ vector<StreamOutput*> streams;
+};
+
+
+
+
+
+
+
+
+
+#endif
\r
// We only call the command dispatcher in the main loop, nowhere else\r
this->register_for_event(ON_MAIN_LOOP);\r
+\r
+ // Add to the pack of streams kernel can call to, for example for broadcasting\r
+ this->kernel->streams->append_stream(this);\r
+\r
}\r
\r
\r
\r
\r
void USBCDCMSC::on_main_loop(void* argument){\r
- //if( this->configured() ){\r
- // this->kernel->serial->printf("a:%d\r\n", this->buffer.size());\r
- //}\r
if( this->has_char('\n') ){\r
int index = 0;\r
string received;\r
message.message = received;\r
message.stream = this;\r
this->kernel->call_event(ON_CONSOLE_LINE_RECEIVED, &message ); \r
- //this->kernel->serial->printf("received: %s \r\n", received.c_str() ); \r
- //this->printf("received: %s\r\n", received.c_str() ); \r
return;\r
}else{\r
received += c;\r
char received = this->_getc();\r
// convert CR to NL (for host OSs that don't send NL)\r
if( received == '\r' ){ received = '\n'; }\r
- //if( this->kernel != NULL ){ \r
- // this->kernel->serial->printf("received:%c\r\n", received); \r
- //} \r
this->buffer.push_back(received); \r
}\r
\r
Kernel* kernel = new Kernel();
- kernel->serial->printf("Smoothie ( grbl port ) version 0.6.1 \r\n");
+ kernel->streams->printf("Smoothie ( grbl port ) version 0.6.1 \r\n");
kernel->add_module( new Laser(p21) );
kernel->add_module( new Extruder() );
//kernel->add_module( &cdcmsc );
- kernel->serial->printf("start\r\n");
+ kernel->streams->printf("start\r\n");
while(1){
kernel->call_event(ON_MAIN_LOOP);
// We only call the command dispatcher in the main loop, nowhere else
this->register_for_event(ON_MAIN_LOOP);
+
+ // Add to the pack of streams kernel can call to, for example for broadcasting
+ this->kernel->streams->append_stream(this);
}
// Called on Serial::RxIrq interrupt, meaning we have received a char
}
void Block::debug(Kernel* kernel){
- kernel->serial->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8d 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 );
+ kernel->streams->printf("%p: steps:%4d|%4d|%4d(max:%4d) nominal:r%10d/s%6.1f mm:%9.6f rdelta:%8d 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 );
}
block->nominal_rate = 0;
}
- //this->kernel->serial->printf("nom_speed: %f nom_rate: %u step_event_count: %u block->steps_z: %u \r\n", block->nominal_speed, block->nominal_rate, block->steps_event_count, block->steps[2] );
+ //this->kernel->streams->printf("nom_speed: %f nom_rate: %u step_event_count: %u block->steps_z: %u \r\n", block->nominal_speed, block->nominal_rate, block->steps_event_count, block->steps[2] );
// Compute the acceleration rate for the trapezoid generator. Depending on the slope of the line
// average travel per step event changes. For a line along one axis the travel per step event
// 3. Recalculate trapezoids for all blocks.
//
void Planner::recalculate() {
- //this->kernel->serial->printf("recalculate last: %p, queue size: %d \r\n", this->kernel->player->queue.get_ref( this->kernel->player->queue.size()-1 ), this->kernel->player->queue.size() );
+ //this->kernel->streams->printf("recalculate last: %p, queue size: %d \r\n", this->kernel->player->queue.get_ref( this->kernel->player->queue.size()-1 ), this->kernel->player->queue.size() );
this->reverse_pass();
this->forward_pass();
this->recalculate_trapezoids();
while(block_index != this->kernel->player->queue.tail){
current = next;
next = &this->kernel->player->queue.buffer[block_index];
- //this->kernel->serial->printf("index:%d current:%p next:%p \r\n", block_index, current, next );
+ //this->kernel->streams->printf("index:%d current:%p next:%p \r\n", block_index, current, next );
if( current ){
// Recalculate if current block entry or exit junction speed has changed.
if( current->recalculate_flag || next->recalculate_flag ){
void Planner::dump_queue(){
for( int index = 0; index <= this->kernel->player->queue.size()-1; index++ ){
if( index > 10 && index < this->kernel->player->queue.size()-10 ){ continue; }
- this->kernel->serial->printf("block %03d > ", index);
+ this->kernel->streams->printf("block %03d > ", index);
this->kernel->player->queue.get_ref(index)->debug(this->kernel);
}
}
}else{
this->trapezoid_adjusted_rate = double(this->current_block->rate_delta) * 1.5;
//this->trapezoid_adjusted_rate = floor(double(this->trapezoid_adjusted_rate / 2 ));
- //this->kernel->serial->printf("over!\r\n");
}
if (this->trapezoid_adjusted_rate < this->current_block->final_rate ) {
this->trapezoid_adjusted_rate = this->current_block->final_rate;