Skip to content

Commit

Permalink
gui: fixed laser preview toggle action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-0x7C6 committed Dec 6, 2019
1 parent dda4e88 commit 02978c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
10 changes: 4 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
project(laser-engraver-toolkit)
cmake_minimum_required(VERSION 3.12)

set(CMAKE_CXX_STANDARD 17)
project(laser-engraver-toolkit)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(VERSION_MAJOR 0)
set(VERSION_MINOR 7)
set(VERSION_PATCH 1)

find_package(Qt5 COMPONENTS Core Gui Widgets SerialPort REQUIRED)
find_package(Threads)

Expand Down
5 changes: 4 additions & 1 deletion src/gcode-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class gcode_generator {
std::string operator()(const instruction::set_home_position) const noexcept { return "G92 X0 Y0 Z0"; }
std::string operator()(const instruction::laser_off) const noexcept { return "M5"; }
std::string operator()(const instruction::laser_on) const noexcept { return "M3"; }
std::string operator()(const instruction::move_dpi v) const noexcept { return "G0 X" + std::to_string(static_cast<double>(v.x) / m_precision) + " Y" + std::to_string(static_cast<double>(v.y) / m_precision) + " S" + std::to_string(v.power); }
std::string operator()(const instruction::move_dpi v) const noexcept { return "G0 X" +
std::to_string(static_cast<double>(v.x) / m_precision) + " Y" +
std::to_string(static_cast<double>(v.y) / m_precision) +
(v.power.has_value() ? (" S" + std::to_string(v.power.value())) : std::string{}); }
std::string operator()(const instruction::move_mm v) const noexcept { return "G0 X" + std::to_string(v.x) + " Y" + std::to_string(v.y); }
std::string operator()(const instruction::power v) const noexcept { return "S" + std::to_string(v.duty); }
std::string operator()(const std::monostate) const noexcept { return {}; }
Expand Down
3 changes: 2 additions & 1 deletion src/instructions.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <externals/common/types.hpp>
#include <optional>

namespace instruction {

Expand All @@ -20,7 +21,7 @@ struct dwell {
struct move_dpi {
float x;
float y;
u16 power;
std::optional<u8> power;
};

struct move_mm {
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ MainWindow::MainWindow(QWidget *parent)
m_enableIfEngraverConnected.addAction(action);

m_enableIfEngraverConnected.setEnabled(false);
m_enableIfEngraverConnected.setExclusive(false);
m_actionDisconnectEngraver->setVisible(false);

auto window = menu->addMenu("&Window");
Expand Down
7 changes: 4 additions & 3 deletions src/semi-gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ semi::gcodes semi::generator::from_image(const QImage &img, semi::options opts,
for (auto y = 0; y < img.height(); ++y) {
for (auto px = 0; px < img.width(); ++px) {
const auto x = ((y % 2) == 0) ? px : img.width() - px - 1;
const auto pwr = 1.0 - QColor::fromRgb(img.pixel(x, y)).lightnessF();
const auto color = QColor::fromRgb(img.pixel(x, y));
const auto pwr = std::min(255, static_cast<int>(color.black() * opts.power_multiplier));

if (pwr != 0.0) {
if (pwr != 0) {
gcode_move(x, y, 0);
encode(instruction::power{static_cast<i16>(255 * (pwr * opts.power_multiplier))});
encode(instruction::power{pwr});
if (opts.force_dwell_time)
encode(instruction::dwell{opts.force_dwell_time.value()});
schedule_power_off = true;
Expand Down

0 comments on commit 02978c5

Please sign in to comment.