Add camera reboot option

This commit is contained in:
Gary Talent 2023-10-15 16:02:24 -05:00
parent 56f98eed60
commit ac7bb9c585
7 changed files with 52 additions and 22 deletions

View File

@ -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)

View File

@ -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}

View File

@ -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:

View File

@ -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':

View File

@ -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);
}

View File

@ -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);

View File

@ -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>(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
{