Skip to content

Commit

Permalink
Added manual control for temperature and bed temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Mar 9, 2017
1 parent f1f1444 commit 2807526
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
48 changes: 45 additions & 3 deletions lib/Slic3r/GUI/Controller/ManualControlDialog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@ use strict;
use warnings;
use utf8;

use Scalar::Util qw(looks_like_number);
use Slic3r::Geometry qw(PI X Y unscale);
use Wx qw(:dialog :id :misc :sizer :choicebook :button :bitmap
wxBORDER_NONE wxTAB_TRAVERSAL);
use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
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 {
my ($class, $parent, $config, $sender) = @_;

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->writer(Slic3r::GCode::Writer->new);
$self->writer->config->apply_dynamic($config);

$self->config2({
xy_travel_speed => 130,
z_travel_speed => 10,
temperature => '',
bed_temperature => '',
});

my $bed_sizer = Wx::FlexGridSizer->new(2, 3, 1, 1);
Expand Down Expand Up @@ -133,7 +138,44 @@ sub new {
));
$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);
$main_sizer->Add($bed_sizer, 1, wxEXPAND | wxALL, 10);
$main_sizer->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 10);
Expand Down
2 changes: 1 addition & 1 deletion lib/Slic3r/GUI/Controller/PrinterPanel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ sub _update_connection_controls {
$self->{btn_manual_control}->Hide;
$self->{btn_manual_control}->Disable;

if ($self->is_connected) {
if ($self->is_connected || 1) {
$self->{btn_connect}->Hide;
$self->{btn_manual_control}->Show;
if (!$self->printing || $self->printing->paused) {
Expand Down
22 changes: 22 additions & 0 deletions lib/Slic3r/GUI/OptionsGroup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ has 'widget' => (is => 'rw');
has '_options' => (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
sub append_option {
my ($self, $option) = @_;
Expand All @@ -293,6 +296,25 @@ sub append_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 {
my ($self) = @_;
return [ @{$self->_options} ];
Expand Down
Binary file added var/tick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2807526

Please sign in to comment.