mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-07 02:29:05 +08:00
Test button for serial connection
This commit is contained in:
parent
fc1a7471cf
commit
b309c61de3
@ -1000,7 +1000,8 @@ sub build {
|
|||||||
my $bed_shape_widget = sub {
|
my $bed_shape_widget = sub {
|
||||||
my ($parent) = @_;
|
my ($parent) = @_;
|
||||||
|
|
||||||
my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
my $btn = Wx::Button->new($parent, -1, "Set…", wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxBU_LEFT | wxBU_EXACTFIT);
|
||||||
$btn->SetFont($Slic3r::GUI::small_font);
|
$btn->SetFont($Slic3r::GUI::small_font);
|
||||||
if ($Slic3r::GUI::have_button_icons) {
|
if ($Slic3r::GUI::have_button_icons) {
|
||||||
$btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/cog.png", wxBITMAP_TYPE_PNG));
|
$btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/cog.png", wxBITMAP_TYPE_PNG));
|
||||||
@ -1077,8 +1078,42 @@ sub build {
|
|||||||
|
|
||||||
return $btn;
|
return $btn;
|
||||||
});
|
});
|
||||||
|
my $serial_test = sub {
|
||||||
|
my ($parent) = @_;
|
||||||
|
|
||||||
|
my $btn = $self->{serial_test_btn} = Wx::Button->new($parent, -1,
|
||||||
|
"Test", 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/wrench.png", wxBITMAP_TYPE_PNG));
|
||||||
|
}
|
||||||
|
|
||||||
|
EVT_BUTTON($self, $btn, sub {
|
||||||
|
my $sender = Slic3r::GCode::Sender->new;
|
||||||
|
my $res = $sender->connect(
|
||||||
|
$self->{config}->serial_port,
|
||||||
|
$self->{config}->serial_speed,
|
||||||
|
);
|
||||||
|
if ($res) {
|
||||||
|
{
|
||||||
|
# set up a timeout
|
||||||
|
my $timestamp = time();
|
||||||
|
my $CONNECTION_TIMEOUT = 3; # seconds
|
||||||
|
1 until $sender->is_connected || (time - $timestamp) >= $CONNECTION_TIMEOUT;
|
||||||
|
}
|
||||||
|
$res = $sender->is_connected;
|
||||||
|
}
|
||||||
|
if ($res) {
|
||||||
|
Slic3r::GUI::show_info($self, "Connection to printer works correctly.", "Success!");
|
||||||
|
} else {
|
||||||
|
Slic3r::GUI::show_error($self, "Connection failed.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return $btn;
|
||||||
|
};
|
||||||
$line->append_option($serial_port);
|
$line->append_option($serial_port);
|
||||||
$line->append_option($optgroup->get_option('serial_speed'));
|
$line->append_option($optgroup->get_option('serial_speed'));
|
||||||
|
$line->append_widget($serial_test);
|
||||||
$optgroup->append_line($line);
|
$optgroup->append_line($line);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -1114,7 +1149,8 @@ sub build {
|
|||||||
my $octoprint_host_test = sub {
|
my $octoprint_host_test = sub {
|
||||||
my ($parent) = @_;
|
my ($parent) = @_;
|
||||||
|
|
||||||
my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1, "Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
my $btn = $self->{octoprint_host_test_btn} = Wx::Button->new($parent, -1,
|
||||||
|
"Test", wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT);
|
||||||
$btn->SetFont($Slic3r::GUI::small_font);
|
$btn->SetFont($Slic3r::GUI::small_font);
|
||||||
if ($Slic3r::GUI::have_button_icons) {
|
if ($Slic3r::GUI::have_button_icons) {
|
||||||
$btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/wrench.png", wxBITMAP_TYPE_PNG));
|
$btn->SetBitmap(Wx::Bitmap->new("$Slic3r::var/wrench.png", wxBITMAP_TYPE_PNG));
|
||||||
@ -1300,6 +1336,11 @@ sub _update {
|
|||||||
my $config = $self->{config};
|
my $config = $self->{config};
|
||||||
|
|
||||||
$self->get_field('serial_speed')->toggle($config->get('serial_port'));
|
$self->get_field('serial_speed')->toggle($config->get('serial_port'));
|
||||||
|
if ($config->get('serial_speed') && $config->get('serial_port')) {
|
||||||
|
$self->{serial_test_btn}->Enable;
|
||||||
|
} else {
|
||||||
|
$self->{serial_test_btn}->Disable;
|
||||||
|
}
|
||||||
if ($config->get('octoprint_host') && eval "use LWP::UserAgent; 1") {
|
if ($config->get('octoprint_host') && eval "use LWP::UserAgent; 1") {
|
||||||
$self->{octoprint_host_test_btn}->Enable;
|
$self->{octoprint_host_test_btn}->Enable;
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,6 +29,7 @@ GCodeSender::GCodeSender()
|
|||||||
|
|
||||||
GCodeSender::~GCodeSender()
|
GCodeSender::~GCodeSender()
|
||||||
{
|
{
|
||||||
|
printf("disconnecting\n");
|
||||||
this->disconnect();
|
this->disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user