diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c9df62..2b749e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +# Fri Sept 30 2024 - 6.0.4 +- Fix tweak command crashes # Sun Sept 1 2024 - 6.0.3 - Fix inconsistent file logging - Minor improvements @@ -48,17 +50,17 @@ - Add openrc support - Python >= 3.10 # Son Feb 26 2023 - 4.5.0 -- Improvement of config generation +- Improvement of config generation # Fri Feb 24 2023 - 4.4.2 - Fix command not found - Smaller size # Fri Feb 17 2023 - 4.4.0 - Total rework of the implementation - Support multiple emitters camera -- Memorize broken instructions to skip them +- Memorize broken instructions to skip them - Usage of /dev/v4l/by-path for persistence # Tue Sep 13 2022 - 4.1.5 -- Fix boot service for custom device +- Fix boot service for custom device # Thu Aug 11 2022 - 4.1.4 - Force V4l2 backend in opencv - Improvement of config generation @@ -67,11 +69,11 @@ - Fix camera triggering issue - Fix device symlink boot service side effect # Sun Jun 19 2022 - 4.0.0 -- Rework, optimization and improvement of config generation +- Rework, optimization and improvement of config generation - Remove manual configuration commands - Remove option for integration into Howdy # Thu Dec 9 2021 - 3.2.5 -- Tweak for integration into Howdy(https://github.com/boltgolt/howdy) +- Tweak for integration into Howdy(https://github.com/boltgolt/howdy) - Bash auto completion - Better systemd support # Thu Nov 4 2021 - 3.2.2 diff --git a/meson.build b/meson.build index e70808c..918b883 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'linux-enable-ir-emitter', 'cpp', - version: '6.0.3', + version: '6.0.4', license: 'MIT', default_options: [ 'cpp_std=c++20', diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index 94c2cbe..b7c0b17 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -161,10 +162,10 @@ string Camera::device() const noexcept { return device_; } void Camera::disable_gui() noexcept { no_gui_ = true; } -std::stop_source Camera::play() { - open_cap(); +std::function Camera::play() { + auto show_video = std::make_shared([this](const std::stop_token &stop) { + open_cap(); - jthread show_video([this](const std::stop_token &stop) { cv::Mat frame; while (!stop.stop_requested()) { cv::imshow("linux-enable-ir-emitter", read1_unsafe()); @@ -174,9 +175,13 @@ std::stop_source Camera::play() { cv::destroyAllWindows(); close_cap(); }); - show_video.detach(); - return show_video.get_stop_source(); + auto stop = [show_video]() { + show_video->request_stop(); + show_video->join(); + }; + + return stop; } void Camera::play_forever() { diff --git a/src/camera/camera.hpp b/src/camera/camera.hpp index 413670d..6db6baa 100644 --- a/src/camera/camera.hpp +++ b/src/camera/camera.hpp @@ -160,13 +160,13 @@ class Camera { /** * @brief Show a video feedback until the stop is requested. - * You should not use the camera object until the `request_stop()` is called. + * You should not use the camera object until the stop function is called. * * @throw CameraException if unable to open the camera device * - * @return the stop source + * @return the stop function */ - std::stop_source play(); + std::function play(); /** * @brief Show a video feedback until the user exit by pressing any key. diff --git a/src/configuration/finder.cpp b/src/configuration/finder.cpp index d310f2c..d0f783d 100644 --- a/src/configuration/finder.cpp +++ b/src/configuration/finder.cpp @@ -64,7 +64,7 @@ bool Finder::find(CameraInstructions &instructions) { return true; } } else - logger::debug("The instruction is not valid."); + logger::debug("The instruction does not enable the emitter."); ++neg_answer_counter; } diff --git a/src/configuration/tweaker.cpp b/src/configuration/tweaker.cpp index 0129fd7..463111e 100644 --- a/src/configuration/tweaker.cpp +++ b/src/configuration/tweaker.cpp @@ -68,23 +68,22 @@ static optional> ask_for_new_cur(CameraInstruction &inst) { return {}; } + vector new_cur; istringstream iss(new_cur_str); - auto new_cur_parsed = - vector(istream_iterator{iss}, istream_iterator()); - - vector new_cur(new_cur_parsed.size()); - for (auto v : new_cur_parsed) new_cur.push_back(static_cast(v)); + std::transform(std::istream_iterator(iss), std::istream_iterator(), + std::back_inserter(new_cur), + [](const std::string &val) { return static_cast(std::stoi(val)); }); return new_cur; } void Tweaker::tweak(CameraInstructions &instructions) { while (true) { - auto video_feedback = camera->play(); + auto video_feedback_stop = camera->play(); size_t choice = ask_for_choice(instructions); if (choice == instructions.size()) { - video_feedback.request_stop(); + video_feedback_stop(); break; } auto &inst = instructions.at(choice); @@ -92,7 +91,7 @@ void Tweaker::tweak(CameraInstructions &instructions) { auto prev_cur = inst.cur(); auto new_cur = ask_for_new_cur(inst); - video_feedback.request_stop(); + video_feedback_stop(); if (!new_cur.has_value()) continue;