Skip to content

Commit 788b91b

Browse files
authored
Merge pull request #196 from EmixamPP/fix/tweak
fix: tweak command
2 parents b8ee83d + 3492128 commit 788b91b

6 files changed

Lines changed: 29 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Fri Sept 30 2024 - 6.0.4
2+
- Fix tweak command crashes
13
# Sun Sept 1 2024 - 6.0.3
24
- Fix inconsistent file logging
35
- Minor improvements
@@ -48,17 +50,17 @@
4850
- Add openrc support
4951
- Python >= 3.10
5052
# Son Feb 26 2023 - 4.5.0
51-
- Improvement of config generation
53+
- Improvement of config generation
5254
# Fri Feb 24 2023 - 4.4.2
5355
- Fix command not found
5456
- Smaller size
5557
# Fri Feb 17 2023 - 4.4.0
5658
- Total rework of the implementation
5759
- Support multiple emitters camera
58-
- Memorize broken instructions to skip them
60+
- Memorize broken instructions to skip them
5961
- Usage of /dev/v4l/by-path for persistence
6062
# Tue Sep 13 2022 - 4.1.5
61-
- Fix boot service for custom device
63+
- Fix boot service for custom device
6264
# Thu Aug 11 2022 - 4.1.4
6365
- Force V4l2 backend in opencv
6466
- Improvement of config generation
@@ -67,11 +69,11 @@
6769
- Fix camera triggering issue
6870
- Fix device symlink boot service side effect
6971
# Sun Jun 19 2022 - 4.0.0
70-
- Rework, optimization and improvement of config generation
72+
- Rework, optimization and improvement of config generation
7173
- Remove manual configuration commands
7274
- Remove option for integration into Howdy
7375
# Thu Dec 9 2021 - 3.2.5
74-
- Tweak for integration into Howdy(https://github.com/boltgolt/howdy)
76+
- Tweak for integration into Howdy(https://github.com/boltgolt/howdy)
7577
- Bash auto completion
7678
- Better systemd support
7779
# Thu Nov 4 2021 - 3.2.2

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'linux-enable-ir-emitter',
33
'cpp',
4-
version: '6.0.3',
4+
version: '6.0.4',
55
license: 'MIT',
66
default_options: [
77
'cpp_std=c++20',

src/camera/camera.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <cerrno>
77
#include <filesystem>
88
#include <format>
9+
#include <functional>
910
#include <regex>
1011
#include <stdexcept>
1112
#include <thread>
@@ -161,10 +162,10 @@ string Camera::device() const noexcept { return device_; }
161162

162163
void Camera::disable_gui() noexcept { no_gui_ = true; }
163164

164-
std::stop_source Camera::play() {
165-
open_cap();
165+
std::function<void()> Camera::play() {
166+
auto show_video = std::make_shared<jthread>([this](const std::stop_token &stop) {
167+
open_cap();
166168

167-
jthread show_video([this](const std::stop_token &stop) {
168169
cv::Mat frame;
169170
while (!stop.stop_requested()) {
170171
cv::imshow("linux-enable-ir-emitter", read1_unsafe());
@@ -174,9 +175,13 @@ std::stop_source Camera::play() {
174175
cv::destroyAllWindows();
175176
close_cap();
176177
});
177-
show_video.detach();
178178

179-
return show_video.get_stop_source();
179+
auto stop = [show_video]() {
180+
show_video->request_stop();
181+
show_video->join();
182+
};
183+
184+
return stop;
180185
}
181186

182187
void Camera::play_forever() {

src/camera/camera.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ class Camera {
160160

161161
/**
162162
* @brief Show a video feedback until the stop is requested.
163-
* You should not use the camera object until the `request_stop()` is called.
163+
* You should not use the camera object until the stop function is called.
164164
*
165165
* @throw CameraException if unable to open the camera device
166166
*
167-
* @return the stop source
167+
* @return the stop function
168168
*/
169-
std::stop_source play();
169+
std::function<void()> play();
170170

171171
/**
172172
* @brief Show a video feedback until the user exit by pressing any key.

src/configuration/finder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bool Finder::find(CameraInstructions &instructions) {
6464
return true;
6565
}
6666
} else
67-
logger::debug("The instruction is not valid.");
67+
logger::debug("The instruction does not enable the emitter.");
6868

6969
++neg_answer_counter;
7070
}

src/configuration/tweaker.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,30 @@ static optional<vector<uint8_t>> ask_for_new_cur(CameraInstruction &inst) {
6868
return {};
6969
}
7070

71+
vector<uint8_t> new_cur;
7172
istringstream iss(new_cur_str);
72-
auto new_cur_parsed =
73-
vector<int32_t>(istream_iterator<int32_t>{iss}, istream_iterator<int32_t>());
74-
75-
vector<uint8_t> new_cur(new_cur_parsed.size());
76-
for (auto v : new_cur_parsed) new_cur.push_back(static_cast<uint8_t>(v));
73+
std::transform(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
74+
std::back_inserter(new_cur),
75+
[](const std::string &val) { return static_cast<uint8_t>(std::stoi(val)); });
7776

7877
return new_cur;
7978
}
8079

8180
void Tweaker::tweak(CameraInstructions &instructions) {
8281
while (true) {
83-
auto video_feedback = camera->play();
82+
auto video_feedback_stop = camera->play();
8483

8584
size_t choice = ask_for_choice(instructions);
8685
if (choice == instructions.size()) {
87-
video_feedback.request_stop();
86+
video_feedback_stop();
8887
break;
8988
}
9089
auto &inst = instructions.at(choice);
9190

9291
auto prev_cur = inst.cur();
9392
auto new_cur = ask_for_new_cur(inst);
9493

95-
video_feedback.request_stop();
94+
video_feedback_stop();
9695

9796
if (!new_cur.has_value()) continue;
9897

0 commit comments

Comments
 (0)