Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature to pause the USB grabber when all LEDs are off #608

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/image-builder-from-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
echo "image=$IMAGE" >> $GITHUB_OUTPUT

# artifact upload will take care of zipping for us
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.copy.outputs.image }}
path: ${{ steps.copy.outputs.image }}.img
6 changes: 5 additions & 1 deletion .github/workflows/image-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ jobs:
echo 'set -x' >> start_chroot_script
echo 'set -e' >> start_chroot_script
echo 'source /common.sh' >> start_chroot_script
echo 'type -p curl >/dev/null || apt install curl -y' >> start_chroot_script
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
echo '&& chmod go+r /usr/share/keyrings/hyperhdr.public.apt.gpg.key \' >> start_chroot_script
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
echo 'apt-get update' >> start_chroot_script
echo 'cd /tmp' >> start_chroot_script
echo 'wget ${{env.HYPERHDR_DEB}} -O hyperhdr.deb' >> start_chroot_script
Expand Down Expand Up @@ -94,7 +98,7 @@ jobs:
echo "image=$IMAGE" >> $GITHUB_OUTPUT

# artifact upload will take care of zipping for us
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v3
with:
name: ${{ steps.copy.outputs.image }}
path: ${{ steps.copy.outputs.image }}.img
14 changes: 13 additions & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ jobs:
linuxVersion: bullseye
dockerName: Debian Bullseye (x86_64)
platform: linux
- dockerImage: x86_64
linuxVersion: bookworm
dockerName: Debian Bookworm (x86_64)
platform: linux
- dockerImage: x86_64
linuxVersion: jammy
dockerName: Ubuntu 22.04 LTS (x86_64)
Expand All @@ -39,7 +43,15 @@ jobs:
- dockerImage: arm-64bit-aarch64
linuxVersion: bullseye
dockerName: Debian Bullseye (ARM 64-bit Raspberry Pi OS)
platform: rpi
platform: rpi
- dockerImage: arm-32bit-armv6l
linuxVersion: bookworm
dockerName: Debian Bookworm (ARM 32-bit Raspberry Pi OS)
platform: rpi
- dockerImage: arm-64bit-aarch64
linuxVersion: bookworm
dockerName: Debian Bookworm (ARM 64-bit Raspberry Pi OS)
platform: rpi
- dockerImage: x86_64
linuxVersion: ArchLinux
dockerName: Arch Linux (x86_64)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Pause the USB grabber when all LEDs are off #608 (v20 beta 🆕)
- Add support for HD108 led strip, 16/48bits colors #527 (v20 beta 🆕)
- Use optional system libs for compiling #541 (v20 beta 🆕)
- Update mbedtls to 3.4.0 #589 (v20 beta 🆕)
Expand Down
11 changes: 7 additions & 4 deletions include/base/GrabberWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
class GlobalSignals;
class QTimer;

/// List of HyperHDR instances that requested screen capt
static QList<int> GRABBER_VIDEO_CLIENTS;

///
/// This class will be inherted by FramebufferWrapper and others which contains the real capture interface
///
Expand Down Expand Up @@ -69,7 +66,7 @@ public slots:
void stop();

private slots:
void handleSourceRequest(hyperhdr::Components component, int hyperHdrInd, bool listen);
void handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen);

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

public:
int getHdrToneMappingEnabled();
Expand All @@ -97,6 +95,7 @@ public slots:
void setBrightnessContrastSaturationHueHandler(int brightness, int contrast, int saturation, int hue);
void setQFrameDecimation(int setQframe);
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
void instancePauseChangedHandler(int instance, bool isEnabled);

protected:
DetectionAutomatic::calibrationPoint parsePoint(int width, int height, QJsonObject element, bool& ok);
Expand All @@ -112,7 +111,11 @@ public slots:
int _cecHdrStart;
int _cecHdrStop;
bool _autoResume;
bool _isPaused;
bool _pausingModeEnabled;

int _benchmarkStatus;
QString _benchmarkMessage;
QList<int> _running_clients;
QList<int> _paused_clients;
};
87 changes: 81 additions & 6 deletions sources/base/GrabberWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber)
, _cecHdrStart(0)
, _cecHdrStop(0)
, _autoResume(false)
, _isPaused(false)
, _pausingModeEnabled(false)
, _benchmarkStatus(-1)
, _benchmarkMessage("")
{
Expand All @@ -65,6 +67,64 @@ GrabberWrapper::GrabberWrapper(const QString& grabberName, Grabber* ggrabber)

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

connect(this, &GrabberWrapper::instancePauseChanged, this, &GrabberWrapper::instancePauseChangedHandler);
}

void GrabberWrapper::instancePauseChangedHandler(int instance, bool isEnabled)
{
static int signature = 0;
int trigger = 0;

if (!_pausingModeEnabled)
return;

if (!isEnabled)
{
if (!_paused_clients.contains(instance))
{
_paused_clients.append(instance);
trigger = 10000;
}
}
else if (isEnabled)
{
if (_paused_clients.contains(instance))
{
_paused_clients.removeOne(instance);
trigger = 1000;
}
}

if (trigger > 0)
{
int newSignature = ++signature;
QTimer::singleShot(trigger, Qt::TimerType::PreciseTimer, this, [this, newSignature]() {
if (signature == newSignature)
{
if (_paused_clients.length() == _running_clients.length() && _paused_clients.length() > 0)
{
if (!_isPaused)
{
Warning(_log, "LEDs are off and you have enabled the pausing feature for the USB grabber. Pausing the video grabber now.");
auto _running_clients_copy = _running_clients;
_running_clients.clear();
handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, false);
_running_clients = _running_clients_copy;
_isPaused = true;
}
}
else if (_paused_clients.length() < _running_clients.length() && _running_clients.length() > 0)
{
if (_isPaused)
{
Warning(_log, "LEDs are on. Resuming the video grabber now.");
handleSourceRequest(hyperhdr::Components::COMP_VIDEOGRABBER, -1, true);
_isPaused = false;
}
}
}
});
}
}

void GrabberWrapper::setCecStartStop(int cecHdrStart, int cecHdrStop)
Expand Down Expand Up @@ -208,16 +268,25 @@ QJsonObject GrabberWrapper::getJsonInfo()
return grabbers;
}

void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int hyperhdrInd, bool listen)
void GrabberWrapper::handleSourceRequest(hyperhdr::Components component, int instanceIndex, bool listen)
{
if (component == hyperhdr::Components::COMP_VIDEOGRABBER)
{
if (listen && !GRABBER_VIDEO_CLIENTS.contains(hyperhdrInd))
GRABBER_VIDEO_CLIENTS.append(hyperhdrInd);
else if (!listen)
GRABBER_VIDEO_CLIENTS.removeOne(hyperhdrInd);
if (instanceIndex >= 0)
{
if (listen && !_running_clients.contains(instanceIndex))
{
_running_clients.append(instanceIndex);
_paused_clients.removeOne(instanceIndex);
}
else if (!listen)
{
_running_clients.removeOne(instanceIndex);
_paused_clients.removeOne(instanceIndex);
}
}

if (GRABBER_VIDEO_CLIENTS.empty())
if (_running_clients.empty())
{
stop();

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

if (_pausingModeEnabled != obj["led_off_pause"].toBool(false))
{
_pausingModeEnabled = obj["led_off_pause"].toBool(false);
Debug(_log, "Pausing mode is: %s", (_pausingModeEnabled) ? "enabled" : "disabled");
}

// crop for video
_grabber->setCropping(
obj["cropLeft"].toInt(0),
Expand Down
5 changes: 5 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ void HyperHdrInstance::setNewComponentState(hyperhdr::Components component, bool
emit PerformanceCounters::getInstance()->newCounter(PerformanceReport(static_cast<int>(PerformanceReportType::LED), -1, "", -1, -1, -1, -1, getInstanceIndex()));
else
emit PerformanceCounters::getInstance()->removeCounter(static_cast<int>(PerformanceReportType::LED), getInstanceIndex());

if (GrabberWrapper::getInstance() != nullptr)
{
emit GrabberWrapper::getInstance()->instancePauseChanged(_instIndex, state);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions sources/base/schema/schema-videoGrabber.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@
"hidden":true
},
"propertyOrder" : 70
},
"led_off_pause" :
{
"type" : "boolean",
"format": "checkbox",
"title" : "edt_conf_stream_ledoff_title",
"default" : false,
"required" : true,
"propertyOrder" : 72
}
},
"additionalProperties" : false
Expand Down
2 changes: 2 additions & 0 deletions www/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,8 @@
"main_menu_grabber_lut_path_found_NOCRC" : "enable HDR in USB grabber options and refresh the page",
"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.",
"main_menu_grabber_lut_confirm" : "Are you sure to download and install new LUT file for your grabber?",
"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.",
"edt_conf_stream_ledoff_title": "Pause when LEDs are off",
"json_api_instanceCurrentState_header" : "Get instance current state",
"json_api_instanceCurrentState_expl" : "Get the current, updated state of the instance, such as the average color of the LEDs",
"general_btn_average_color" : "Average color",
Expand Down
12 changes: 12 additions & 0 deletions www/js/ledsim.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.