More work on print controller

This commit is contained in:
Alessandro Ranellucci 2015-01-03 23:25:55 +01:00
parent c06ce3b58c
commit 2c0d216c1a
15 changed files with 626 additions and 63 deletions

View file

@ -23,7 +23,8 @@ namespace Slic3r {
namespace asio = boost::asio;
GCodeSender::GCodeSender()
: io(), serial(io), can_send(false), sent(0), error(false), connected(false)
: io(), serial(io), can_send(false), sent(0), error(false), connected(false),
queue_paused(false)
{}
GCodeSender::~GCodeSender()
@ -140,6 +141,23 @@ GCodeSender::queue_size() const
return this->queue.size();
}
void
GCodeSender::pause_queue()
{
boost::lock_guard<boost::mutex> l(this->queue_mutex);
this->queue_paused = true;
}
void
GCodeSender::resume_queue()
{
{
boost::lock_guard<boost::mutex> l(this->queue_mutex);
this->queue_paused = false;
}
this->send();
}
void
GCodeSender::do_close()
{
@ -260,6 +278,7 @@ GCodeSender::send()
{
// printer is not connected or we're still waiting for the previous ack
if (!this->can_send) return;
if (this->queue_paused) return;
boost::lock_guard<boost::mutex> l(this->queue_mutex);
if (this->queue.empty()) return;

View file

@ -25,6 +25,8 @@ class GCodeSender : private boost::noncopyable {
bool error_status() const;
bool is_connected() const;
size_t queue_size() const;
void pause_queue();
void resume_queue();
private:
asio::io_service io;
@ -39,6 +41,7 @@ class GCodeSender : private boost::noncopyable {
mutable boost::mutex queue_mutex;
std::queue<std::string> queue;
bool can_send;
bool queue_paused;
size_t sent;
void set_baud_rate(unsigned int baud_rate);

View file

@ -161,6 +161,7 @@ class Print
PlaceholderParser placeholder_parser;
// TODO: status_cb
double total_used_filament, total_extruded_volume;
std::map<size_t,float> filament_stats;
PrintState<PrintStep> state;
// ordered collections of extrusion paths to build skirt loops and brim

View file

@ -661,6 +661,18 @@ PrintConfigDef::build_def() {
Options["seam_position"].enum_labels.push_back("Nearest");
Options["seam_position"].enum_labels.push_back("Aligned");
Options["serial_port"].type = coString;
Options["serial_port"].label = "Serial port";
Options["serial_port"].tooltip = "USB/serial port for printer connection.";
Options["serial_port"].cli = "serial-port=s";
Options["serial_speed"].type = coInt;
Options["serial_speed"].label = "Speed";
Options["serial_speed"].tooltip = "Speed (baud) of USB/serial port for printer connection.";
Options["serial_speed"].cli = "serial-speed=i";
Options["serial_speed"].min = 1;
Options["serial_speed"].max = 300000;
Options["skirt_distance"].type = coFloat;
Options["skirt_distance"].label = "Distance from object";
Options["skirt_distance"].tooltip = "Distance between skirt and object(s). Set this to zero to attach the skirt to the object(s) and get a brim for better adhesion.";

View file

@ -587,15 +587,21 @@ class HostConfig : public virtual StaticPrintConfig
public:
ConfigOptionString octoprint_host;
ConfigOptionString octoprint_apikey;
ConfigOptionString serial_port;
ConfigOptionInt serial_speed;
HostConfig() : StaticPrintConfig() {
this->octoprint_host.value = "";
this->octoprint_apikey.value = "";
this->serial_port.value = "";
this->serial_speed.value = 250000;
};
ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
if (opt_key == "octoprint_host") return &this->octoprint_host;
if (opt_key == "octoprint_apikey") return &this->octoprint_apikey;
if (opt_key == "serial_port") return &this->serial_port;
if (opt_key == "serial_speed") return &this->serial_speed;
return NULL;
};

View file

@ -16,6 +16,8 @@
bool is_connected() const;
int queue_size() const;
void send(std::string s);
void pause_queue();
void resume_queue();
};
#endif

View file

@ -174,6 +174,28 @@ _constant()
RETVAL.push_back(*e);
}
%};
void clear_filament_stats()
%code%{
THIS->filament_stats.clear();
%};
void set_filament_stats(int extruder_id, float length)
%code%{
THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
THIS->filament_stats[extruder_id] += length;
%};
SV* filament_stats()
%code%{
HV* hv = newHV();
for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
// stringify extruder_id
std::ostringstream ss;
ss << it->first;
std::string str = ss.str();
(void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
RETVAL = newRV_noinc((SV*)hv);
}
%};
void _simplify_slices(double distance);
double max_allowed_layer_height() const;
bool has_support_material() const;