Skip to content

Commit 9320d6e

Browse files
authored
Pause the USB grabber when all LEDs are off to reduce load (#608)
1 parent da94f8a commit 9320d6e

File tree

10 files changed

+136
-13
lines changed

10 files changed

+136
-13
lines changed

Diff for: .github/workflows/image-builder-from-repo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393
echo "image=$IMAGE" >> $GITHUB_OUTPUT
9494
9595
# artifact upload will take care of zipping for us
96-
- uses: actions/upload-artifact@v1
96+
- uses: actions/upload-artifact@v3
9797
with:
9898
name: ${{ steps.copy.outputs.image }}
9999
path: ${{ steps.copy.outputs.image }}.img

Diff for: .github/workflows/image-builder.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
echo 'set -x' >> start_chroot_script
6666
echo 'set -e' >> start_chroot_script
6767
echo 'source /common.sh' >> start_chroot_script
68+
echo 'type -p curl >/dev/null || apt install curl -y' >> start_chroot_script
69+
echo 'curl -fsSL https://awawa-dev.github.io/hyperhdr.public.apt.gpg.key | dd of=/usr/share/keyrings/hyperhdr.public.apt.gpg.key \' >> start_chroot_script
70+
echo '&& chmod go+r /usr/share/keyrings/hyperhdr.public.apt.gpg.key \' >> start_chroot_script
71+
echo '&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hyperhdr.public.apt.gpg.key] https://awawa-dev.github.io $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hyperhdr.list > /dev/null \' >> start_chroot_script
6872
echo 'apt-get update' >> start_chroot_script
6973
echo 'cd /tmp' >> start_chroot_script
7074
echo 'wget ${{env.HYPERHDR_DEB}} -O hyperhdr.deb' >> start_chroot_script
@@ -94,7 +98,7 @@ jobs:
9498
echo "image=$IMAGE" >> $GITHUB_OUTPUT
9599
96100
# artifact upload will take care of zipping for us
97-
- uses: actions/upload-artifact@v1
101+
- uses: actions/upload-artifact@v3
98102
with:
99103
name: ${{ steps.copy.outputs.image }}
100104
path: ${{ steps.copy.outputs.image }}.img

Diff for: .github/workflows/push-master.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ jobs:
2828
linuxVersion: bullseye
2929
dockerName: Debian Bullseye (x86_64)
3030
platform: linux
31+
- dockerImage: x86_64
32+
linuxVersion: bookworm
33+
dockerName: Debian Bookworm (x86_64)
34+
platform: linux
3135
- dockerImage: x86_64
3236
linuxVersion: jammy
3337
dockerName: Ubuntu 22.04 LTS (x86_64)
@@ -39,7 +43,15 @@ jobs:
3943
- dockerImage: arm-64bit-aarch64
4044
linuxVersion: bullseye
4145
dockerName: Debian Bullseye (ARM 64-bit Raspberry Pi OS)
42-
platform: rpi
46+
platform: rpi
47+
- dockerImage: arm-32bit-armv6l
48+
linuxVersion: bookworm
49+
dockerName: Debian Bookworm (ARM 32-bit Raspberry Pi OS)
50+
platform: rpi
51+
- dockerImage: arm-64bit-aarch64
52+
linuxVersion: bookworm
53+
dockerName: Debian Bookworm (ARM 64-bit Raspberry Pi OS)
54+
platform: rpi
4355
- dockerImage: x86_64
4456
linuxVersion: ArchLinux
4557
dockerName: Arch Linux (x86_64)

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Pause the USB grabber when all LEDs are off #608 (v20 beta 🆕)
12
- Add support for HD108 led strip, 16/48bits colors #527 (v20 beta 🆕)
23
- Use optional system libs for compiling #541 (v20 beta 🆕)
34
- Update mbedtls to 3.4.0 #589 (v20 beta 🆕)

Diff for: include/base/GrabberWrapper.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
class GlobalSignals;
1919
class QTimer;
2020

21-
/// List of HyperHDR instances that requested screen capt
22-
static QList<int> GRABBER_VIDEO_CLIENTS;
23-
2421
///
2522
/// This class will be inherted by FramebufferWrapper and others which contains the real capture interface
2623
///
@@ -69,7 +66,7 @@ public slots:
6966
void stop();
7067

7168
private slots:
72-
void handleSourceRequest(hyperhdr::Components component, int hyperHdrInd, bool listen);
69+
void handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen);
7370

7471
signals:
7572
///
@@ -81,6 +78,7 @@ private slots:
8178
void cecKeyPressed(int key);
8279
void benchmarkUpdate(int status, QString message);
8380
void setBrightnessContrastSaturationHue(int brightness, int contrast, int saturation, int hue);
81+
void instancePauseChanged(int instance, bool isEnabled);
8482

8583
public:
8684
int getHdrToneMappingEnabled();
@@ -97,6 +95,7 @@ public slots:
9795
void setBrightnessContrastSaturationHueHandler(int brightness, int contrast, int saturation, int hue);
9896
void setQFrameDecimation(int setQframe);
9997
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
98+
void instancePauseChangedHandler(int instance, bool isEnabled);
10099

101100
protected:
102101
DetectionAutomatic::calibrationPoint parsePoint(int width, int height, QJsonObject element, bool& ok);
@@ -112,7 +111,11 @@ public slots:
112111
int _cecHdrStart;
113112
int _cecHdrStop;
114113
bool _autoResume;
114+
bool _isPaused;
115+
bool _pausingModeEnabled;
115116

116117
int _benchmarkStatus;
117118
QString _benchmarkMessage;
119+
QList<int> _running_clients;
120+
QList<int> _paused_clients;
118121
};

Diff for: sources/base/GrabberWrapper.cpp

+81-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber)
4949
, _cecHdrStart(0)
5050
, _cecHdrStop(0)
5151
, _autoResume(false)
52+
, _isPaused(false)
53+
, _pausingModeEnabled(false)
5254
, _benchmarkStatus(-1)
5355
, _benchmarkMessage("")
5456
{
@@ -65,6 +67,64 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber)
6567

6668
connect(this, &GrabberWrapper::setBrightnessContrastSaturationHue, this, &GrabberWrapper::setBrightnessContrastSaturationHueHandler);
6769

70+
connect(this, &GrabberWrapper::instancePauseChanged, this, &GrabberWrapper::instancePauseChangedHandler);
71+
}
72+
73+
void GrabberWrapper::instancePauseChangedHandler(int instance, bool isEnabled)
74+
{
75+
static int signature = 0;
76+
int trigger = 0;
77+
78+
if (!_pausingModeEnabled)
79+
return;
80+
81+
if (!isEnabled)
82+
{
83+
if (!_paused_clients.contains(instance))
84+
{
85+
_paused_clients.append(instance);
86+
trigger = 10000;
87+
}
88+
}
89+
else if (isEnabled)
90+
{
91+
if (_paused_clients.contains(instance))
92+
{
93+
_paused_clients.removeOne(instance);
94+
trigger = 1000;
95+
}
96+
}
97+
98+
if (trigger > 0)
99+
{
100+
int newSignature = ++signature;
101+
QTimer::singleShot(trigger, Qt::TimerType::PreciseTimer, this, [this, newSignature]() {
102+
if (signature == newSignature)
103+
{
104+
if (_paused_clients.length() == _running_clients.length() && _paused_clients.length() > 0)
105+
{
106+
if (!_isPaused)
107+
{
108+
Warning(_log, "LEDs are off and you have enabled the pausing feature for the USB grabber. Pausing the video grabber now.");
109+
auto _running_clients_copy = _running_clients;
110+
_running_clients.clear();
111+
handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, false);
112+
_running_clients = _running_clients_copy;
113+
_isPaused = true;
114+
}
115+
}
116+
else if (_paused_clients.length() < _running_clients.length() && _running_clients.length() > 0)
117+
{
118+
if (_isPaused)
119+
{
120+
Warning(_log, "LEDs are on. Resuming the video grabber now.");
121+
handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, true);
122+
_isPaused = false;
123+
}
124+
}
125+
}
126+
});
127+
}
68128
}
69129

70130
void GrabberWrapper::setCecStartStop(int cecHdrStart, int cecHdrStop)
@@ -208,16 +268,25 @@ QJsonObject GrabberWrapper::getJsonInfo()
208268
return grabbers;
209269
}
210270

211-
void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int hyperhdrInd, bool listen)
271+
void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen)
212272
{
213273
if (component == hyperhdr::Components::COMP_VIDEOGRABBER)
214274
{
215-
if (listen && !GRABBER_VIDEO_CLIENTS.contains(hyperhdrInd))
216-
GRABBER_VIDEO_CLIENTS.append(hyperhdrInd);
217-
else if (!listen)
218-
GRABBER_VIDEO_CLIENTS.removeOne(hyperhdrInd);
275+
if (instanceIndex >= 0)
276+
{
277+
if (listen && !_running_clients.contains(instanceIndex))
278+
{
279+
_running_clients.append(instanceIndex);
280+
_paused_clients.removeOne(instanceIndex);
281+
}
282+
else if (!listen)
283+
{
284+
_running_clients.removeOne(instanceIndex);
285+
_paused_clients.removeOne(instanceIndex);
286+
}
287+
}
219288

220-
if (GRABBER_VIDEO_CLIENTS.empty())
289+
if (_running_clients.empty())
221290
{
222291
stop();
223292

@@ -465,6 +534,12 @@ void GrabberWrapper::handleSettingsUpdate(settings::type type, const QJsonDocume
465534
Debug(_log, "Auto resume is: %s", (_autoResume) ? "enabled" : "disabled");
466535
}
467536

537+
if (_pausingModeEnabled != obj["led_off_pause"].toBool(false))
538+
{
539+
_pausingModeEnabled = obj["led_off_pause"].toBool(false);
540+
Debug(_log, "Pausing mode is: %s", (_pausingModeEnabled) ? "enabled" : "disabled");
541+
}
542+
468543
// crop for video
469544
_grabber->setCropping(
470545
obj["cropLeft"].toInt(0),

Diff for: sources/base/HyperHdrInstance.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ void HyperHdrInstance::setNewComponentState(hyperhdr::Components component, bool
398398
emit PerformanceCounters::getInstance()->newCounter(PerformanceReport(static_cast<int>(PerformanceReportType::LED), -1, "", -1, -1, -1, -1, getInstanceIndex()));
399399
else
400400
emit PerformanceCounters::getInstance()->removeCounter(static_cast<int>(PerformanceReportType::LED), getInstanceIndex());
401+
402+
if (GrabberWrapper::getInstance() != nullptr)
403+
{
404+
emit GrabberWrapper::getInstance()->instancePauseChanged(_instIndex, state);
405+
}
401406
}
402407
}
403408

Diff for: sources/base/schema/schema-videoGrabber.json

+9
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,15 @@
476476
"hidden":true
477477
},
478478
"propertyOrder" : 70
479+
},
480+
"led_off_pause" :
481+
{
482+
"type" : "boolean",
483+
"format": "checkbox",
484+
"title" : "edt_conf_stream_ledoff_title",
485+
"default" : false,
486+
"required" : true,
487+
"propertyOrder" : 72
479488
}
480489
},
481490
"additionalProperties" : false

Diff for: www/i18n/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,8 @@
12101210
"main_menu_grabber_lut_path_found_NOCRC" : "enable HDR in USB grabber options and refresh the page",
12111211
"main_menu_grabber_lut_restart" : "Please restart your system for the changes to take effect fully!<br>USB grabber config with Brightness=$1, Contrast=$2, Saturation=$3 was saved.",
12121212
"main_menu_grabber_lut_confirm" : "Are you sure to download and install new LUT file for your grabber?",
1213+
"edt_conf_stream_ledoff_expl": "Turn off the USB gripper completely after 10 seconds when all LED devices are off. Resume again when the LED device is enabled.",
1214+
"edt_conf_stream_ledoff_title": "Pause when LEDs are off",
12131215
"json_api_instanceCurrentState_header" : "Get instance current state",
12141216
"json_api_instanceCurrentState_expl" : "Get the current, updated state of the instance, such as the average color of the LEDs",
12151217
"general_btn_average_color" : "Average color",

Diff for: www/js/ledsim.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)