From ac7bb9c58571bbfd18bc698807ea9ed0be2fce05 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 15 Oct 2023 16:02:24 -0500 Subject: [PATCH] Add camera reboot option --- deps/buildcore/base.cmake | 1 + deps/buildcore/base.mk | 32 +++++++++++++-------------- deps/buildcore/scripts/pybb.py | 4 ++-- deps/buildcore/scripts/setup-build.py | 5 ++++- src/cameraclient.cpp | 14 +++++++++++- src/cameraclient.hpp | 4 ++++ src/mainwindow.cpp | 14 +++++++++++- 7 files changed, 52 insertions(+), 22 deletions(-) diff --git a/deps/buildcore/base.cmake b/deps/buildcore/base.cmake index bce3dd1..f4515fb 100644 --- a/deps/buildcore/base.cmake +++ b/deps/buildcore/base.cmake @@ -14,6 +14,7 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) + # enable ccache if(NOT DEFINED ENV{BUILDCORE_SUPPRESS_CCACHE}) find_program(CCACHE_PROGRAM ccache) diff --git a/deps/buildcore/base.mk b/deps/buildcore/base.mk index 4275750..441e901 100644 --- a/deps/buildcore/base.mk +++ b/deps/buildcore/base.mk @@ -6,6 +6,10 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. # +ifndef USE_CONAN + USE_CONAN=0 +endif + ifeq (${OS},Windows_NT) SHELL := powershell.exe .SHELLFLAGS := -NoProfile -Command @@ -78,6 +82,7 @@ purge: ${ENV_RUN} ${RM_RF} .current_build ${ENV_RUN} ${RM_RF} ${BUILD_PATH} ${ENV_RUN} ${RM_RF} dist + ${ENV_RUN} ${RM_RF} compile_commands.json .PHONY: test test: build ${ENV_RUN} mypy ${SCRIPTS} @@ -129,6 +134,8 @@ else ${ENV_RUN} ${VCPKG_DIR}/bootstrap-vcpkg.bat endif +endif + .PHONY: vcpkg-install vcpkg-install: ifneq (${OS},windows) @@ -137,39 +144,30 @@ else ${VCPKG_DIR}/vcpkg install --triplet x64-windows ${VCPKG_PKGS} endif -else ifdef USE_CONAN # USE_VCPKG ################################################ - -.PHONY: setup-conan +ifeq (${USE_CONAN},1) # USE_CONAN ################################################ +.PHONY: conan-config conan-config: - ${ENV_RUN} conan profile new ${PROJECT_NAME} --detect --force -ifeq ($(OS),linux) - ${ENV_RUN} conan profile update settings.compiler.libcxx=libstdc++11 ${PROJECT_NAME} -else - ${ENV_RUN} conan profile update settings.compiler.cppstd=20 ${PROJECT_NAME} -ifeq ($(OS),windows) - ${ENV_RUN} conan profile update settings.compiler.runtime=static ${PROJECT_NAME} -endif -endif + ${ENV_RUN} conan profile detect -f --name ${PROJECT_NAME} .PHONY: conan conan: ${ENV_RUN} ${PYBB} conan-install ${PROJECT_NAME} -endif # USE_VCPKG ############################################### +endif # USE_CONAN ############################################### ifeq (${OS},darwin) .PHONY: configure-xcode configure-xcode: - ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_tool=xcode --current_build=0 --build_root=${BUILD_PATH} + ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_tool=xcode --current_build=0 --build_root=${BUILD_PATH} --use_conan=${USE_CONAN} endif .PHONY: configure-release configure-release: - ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=release --build_root=${BUILD_PATH} + ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=release --build_root=${BUILD_PATH} --use_conan=${USE_CONAN} .PHONY: configure-debug configure-debug: - ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=debug --build_root=${BUILD_PATH} + ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=debug --build_root=${BUILD_PATH} --use_conan=${USE_CONAN} .PHONY: configure-asan configure-asan: - ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=asan --build_root=${BUILD_PATH} + ${ENV_RUN} ${SETUP_BUILD} ${VCPKG_TOOLCHAIN} --build_type=asan --build_root=${BUILD_PATH} --use_conan=${USE_CONAN} diff --git a/deps/buildcore/scripts/pybb.py b/deps/buildcore/scripts/pybb.py index e7f18ca..38b3c55 100644 --- a/deps/buildcore/scripts/pybb.py +++ b/deps/buildcore/scripts/pybb.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 # -# Copyright 2016 - 2021 gary@drinkingtea.net +# Copyright 2016 - 2023 gary@drinkingtea.net # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -74,7 +74,7 @@ def conan() -> int: return 1 if err != 0: return err - args = ['conan', 'install', '../', '--build=missing', '-pr', project_name] + args = ['conan', 'install', '../', '-of', '.', '--build=missing', '-pr', project_name] os.chdir(conan_dir) err = subprocess.run(args).returncode if err != 0: diff --git a/deps/buildcore/scripts/setup-build.py b/deps/buildcore/scripts/setup-build.py index c218fe3..016b611 100644 --- a/deps/buildcore/scripts/setup-build.py +++ b/deps/buildcore/scripts/setup-build.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 # -# Copyright 2016 - 2021 gary@drinkingtea.net +# Copyright 2016 - 2023 gary@drinkingtea.net # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this @@ -28,6 +28,7 @@ def main() -> int: parser.add_argument('--build_root', help='Path to the root of build directories (must be in project dir)', default='build') parser.add_argument('--toolchain', help='Path to CMake toolchain file', default='') parser.add_argument('--current_build', help='Indicates whether or not to make this the active build', default=1) + parser.add_argument('--use_conan', help='Indicates whether or not should use .conanbuild/conan_toolchain.cmake', default='0') args = parser.parse_args() if args.build_type == 'asan': @@ -76,6 +77,8 @@ def main() -> int: '-DBUILDCORE_BUILD_CONFIG={:s}'.format(build_config), '-DBUILDCORE_TARGET={:s}'.format(args.target), ] + if args.use_conan != '0': + cmake_cmd.append('-DCMAKE_TOOLCHAIN_FILE={:s}'.format('.conanbuild/conan_toolchain.cmake')) if qt_path != '': cmake_cmd.append(qt_path) if platform.system() == 'Windows': diff --git a/src/cameraclient.cpp b/src/cameraclient.cpp index 2673b60..2b654c2 100644 --- a/src/cameraclient.cpp +++ b/src/cameraclient.cpp @@ -73,6 +73,11 @@ void CameraClient::setHue(int val) { } } +void CameraClient::reboot() { + post("/cgi-bin/param.cgi?post_reboot"); + emit pollFailed(); +} + void CameraClient::setBaseUrl() { auto const [host, port] = getCameraConnectionData(); m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port)); @@ -81,7 +86,14 @@ void CameraClient::setBaseUrl() { void CameraClient::get(QString const&urlExt) { QUrl url(QString(m_baseUrl) + urlExt); QNetworkRequest rqst(url); - auto reply = m_nam->get(rqst); + auto const reply = m_nam->get(rqst); + connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater); +} + +void CameraClient::post(QString const&urlExt) { + QUrl url(QString(m_baseUrl) + urlExt); + QNetworkRequest rqst(url); + auto const reply = m_nam->post(rqst, QByteArray{}); connect(reply, &QIODevice::readyRead, reply, &QObject::deleteLater); } diff --git a/src/cameraclient.hpp b/src/cameraclient.hpp index 58c76b2..4e77591 100644 --- a/src/cameraclient.hpp +++ b/src/cameraclient.hpp @@ -39,12 +39,16 @@ class CameraClient: public QObject { void setHue(int val); + void reboot(); + public slots: void setBaseUrl(); private: void get(QString const&url); + void post(QString const&url); + void poll(); void handlePollResponse(QNetworkReply *reply); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dd2d1b7..996463a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -112,7 +112,7 @@ void MainWindow::setupMenu() { } // camera preset menu { - auto const menu = menuBar()->addMenu(tr("&Camera Preset")); + auto const menu = menuBar()->addMenu(tr("&Camera")); for (auto i = 0; i < std::min(9, MaxCameraPresets); ++i) { auto const cameraPresetAct = new QAction(tr("Camera Preset &%1").arg(i + 1), this); cameraPresetAct->setShortcut(Qt::ALT | static_cast(Qt::Key_1 + i)); @@ -121,6 +121,18 @@ void MainWindow::setupMenu() { }); menu->addAction(cameraPresetAct); } + menu->addSeparator(); + auto const rebootAct = new QAction(tr("&Reboot"), this); + connect(rebootAct, &QAction::triggered, &m_cameraClient, [this] { + QMessageBox confirm(this); + confirm.setText(tr("Are you sure you want to reboot the camera? This will take about 20 seconds.")); + confirm.addButton(tr("&No"), QMessageBox::ButtonRole::NoRole); + confirm.addButton(tr("&Yes"), QMessageBox::ButtonRole::YesRole); + if (confirm.exec() == QMessageBox::YesRole) { + m_cameraClient.reboot(); + } + }); + menu->addAction(rebootAct); } // help menu {