Added manual control for temperature and bed temperature

This commit is contained in:
Alessandro Ranellucci 2017-03-09 21:24:45 +01:00
parent f1f1444637
commit 28075264b8
4 changed files with 68 additions and 4 deletions

View File

@ -5,24 +5,29 @@ use strict;
use warnings; use warnings;
use utf8; use utf8;
use Scalar::Util qw(looks_like_number);
use Slic3r::Geometry qw(PI X Y unscale); use Slic3r::Geometry qw(PI X Y unscale);
use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap
wxBORDER_NONE wxTAB_TRAVERSAL); wxBORDER_NONE wxTAB_TRAVERSAL);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON); use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
use base qw(Wx::Dialog Class::Accessor); use base qw(Wx::Dialog Class::Accessor);
__PACKAGE__->mk_accessors(qw(sender config2 x_homed y_homed)); __PACKAGE__->mk_accessors(qw(sender writer config2 x_homed y_homed));
sub new { sub new {
my ($class, $parent, $config, $sender) = @_; my ($class, $parent, $config, $sender) = @_;
my $self = $class->SUPER::new($parent, -1, "Manual Control", wxDefaultPosition, my $self = $class->SUPER::new($parent, -1, "Manual Control", wxDefaultPosition,
[500,380], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); [500,400], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
$self->sender($sender); $self->sender($sender);
$self->writer(Slic3r::GCode::Writer->new);
$self->writer->config->apply_dynamic($config);
$self->config2({ $self->config2({
xy_travel_speed => 130, xy_travel_speed => 130,
z_travel_speed => 10, z_travel_speed => 10,
temperature => '',
bed_temperature => '',
}); });
my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1); my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1);
@ -133,7 +138,44 @@ sub new {
)); ));
$optgroup->append_line($line); $optgroup->append_line($line);
} }
{
my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
opt_id => 'temperature',
type => 's',
label => 'Temperature',
default => '',
sidetext => '°C',
default => $self->config2->{temperature},
));
$line->append_button("Set", "tick.png", sub {
if (!looks_like_number($self->config2->{temperature})) {
Slic3r::GUI::show_error($self, "Invalid temperature.");
return;
}
my $cmd = $self->writer->set_temperature($self->config2->{temperature});
$self->sender->send($cmd, 1);
});
$optgroup->append_line($line);
}
{
my $line = $optgroup->create_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
opt_id => 'bed_temperature',
type => 's',
label => 'Bed Temperature',
default => '',
sidetext => '°C',
default => $self->config2->{bed_temperature},
));
$line->append_button("Set", "tick.png", sub {
if (!looks_like_number($self->config2->{bed_temperature})) {
Slic3r::GUI::show_error($self, "Invalid bed temperature.");
return;
}
my $cmd = $self->writer->set_bed_temperature($self->config2->{bed_temperature});
$self->sender->send($cmd, 1);
});
$optgroup->append_line($line);
}
my $main_sizer = Wx::BoxSizer->new(wxVERTICAL); my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
$main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10); $main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10);
$main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10); $main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);

View File

@ -279,7 +279,7 @@ sub _update_connection_controls {
$self->{btn_manual_control}->Hide; $self->{btn_manual_control}->Hide;
$self->{btn_manual_control}->Disable; $self->{btn_manual_control}->Disable;
if ($self->is_connected) { if ($self->is_connected || 1) {
$self->{btn_connect}->Hide; $self->{btn_connect}->Hide;
$self->{btn_manual_control}->Show; $self->{btn_manual_control}->Show;
if (!$self->printing || $self->printing->paused) { if (!$self->printing || $self->printing->paused) {

View File

@ -282,6 +282,9 @@ has 'widget' => (is => 'rw');
has '_options' => (is => 'ro', default => sub { [] }); has '_options' => (is => 'ro', default => sub { [] });
has '_extra_widgets' => (is => 'ro', default => sub { [] }); has '_extra_widgets' => (is => 'ro', default => sub { [] });
use Wx qw(:button :misc :bitmap);
use Wx::Event qw(EVT_BUTTON);
# this method accepts a Slic3r::GUI::OptionsGroup::Option object # this method accepts a Slic3r::GUI::OptionsGroup::Option object
sub append_option { sub append_option {
my ($self, $option) = @_; my ($self, $option) = @_;
@ -293,6 +296,25 @@ sub append_widget {
push @{$self->_extra_widgets}, $widget; push @{$self->_extra_widgets}, $widget;
} }
sub append_button {
my ($self, $text, $icon, $cb, $ref) = @_;
$self->append_widget(sub {
my ($parent) = @_;
my $btn = Wx::Button->new($parent, -1,
$text, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
$btn->SetFont($Slic3r::GUI::small_font);
if ($Slic3r::GUI::have_button_icons) {
$btn->SetBitmap(Wx::Bitmap->new($Slic3r::var->($icon), wxBITMAP_TYPE_PNG));
}
$$ref = $btn if $ref;
EVT_BUTTON($parent, $btn, $cb);
return $btn;
});
}
sub get_options { sub get_options {
my ($self) = @_; my ($self) = @_;
return [ @{$self->_options} ]; return [ @{$self->_options} ];

BIN
var/tick.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B