Skip to content

Commit

Permalink
Merge pull request #196 from EmixamPP/fix/tweak
Browse files Browse the repository at this point in the history
fix: tweak command
  • Loading branch information
EmixamPP authored Sep 30, 2024
2 parents b8ee83d + 3492128 commit 788b91b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
15 changes: 10 additions & 5 deletions src/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cerrno>
#include <filesystem>
#include <format>
#include <functional>
#include <regex>
#include <stdexcept>
#include <thread>
Expand Down Expand Up @@ -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<void()> Camera::play() {
auto show_video = std::make_shared<jthread>([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());
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions src/camera/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void()> play();

/**
* @brief Show a video feedback until the user exit by pressing any key.
Expand Down
2 changes: 1 addition & 1 deletion src/configuration/finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 7 additions & 8 deletions src/configuration/tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,30 @@ static optional<vector<uint8_t>> ask_for_new_cur(CameraInstruction &inst) {
return {};
}

vector<uint8_t> new_cur;
istringstream iss(new_cur_str);
auto new_cur_parsed =
vector<int32_t>(istream_iterator<int32_t>{iss}, istream_iterator<int32_t>());

vector<uint8_t> new_cur(new_cur_parsed.size());
for (auto v : new_cur_parsed) new_cur.push_back(static_cast<uint8_t>(v));
std::transform(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
std::back_inserter(new_cur),
[](const std::string &val) { return static_cast<uint8_t>(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);

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;

Expand Down

0 comments on commit 788b91b

Please sign in to comment.