summaryrefslogtreecommitdiffhomepage
path: root/tracker-wii/wii_camera.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-06-17 11:58:04 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-06-17 12:19:25 +0200
commit2aee2a94ea53620e3da7f976875ca4101eec780d (patch)
treef2ff98bbf54040c9dcf48a7edb77248755d27f50 /tracker-wii/wii_camera.cpp
parent3f273418b564f8ca93ec687fa8ab7809099e6c67 (diff)
tracker/wii: clean up a little
Diffstat (limited to 'tracker-wii/wii_camera.cpp')
-rw-r--r--tracker-wii/wii_camera.cpp61
1 files changed, 28 insertions, 33 deletions
diff --git a/tracker-wii/wii_camera.cpp b/tracker-wii/wii_camera.cpp
index 98d180bf..1e05a11c 100644
--- a/tracker-wii/wii_camera.cpp
+++ b/tracker-wii/wii_camera.cpp
@@ -15,11 +15,9 @@
#include "wii_camera.h"
#include "wii_frame.hpp"
-#include "compat/sleep.hpp"
#include "compat/math-imports.hpp"
#include <opencv2/imgproc.hpp>
-
#include <bluetoothapis.h>
using namespace pt_module;
@@ -41,46 +39,46 @@ WIICamera::~WIICamera()
QString WIICamera::get_desired_name() const
{
- return desired_name;
+ return QStringLiteral("Wii");
}
QString WIICamera::get_active_name() const
{
- return active_name;
+ return get_desired_name();
}
void WIICamera::show_camera_settings()
{
-
}
WIICamera::result WIICamera::get_info() const
{
- if (cam_info.res_x == 0 || cam_info.res_y == 0)
- return result(false, pt_camera_info());
- return result(true, cam_info);
+ if (cam_info.res_x == 0 || cam_info.res_y == 0)
+ return result(false, pt_camera_info());
+ return result(true, cam_info);
}
WIICamera::result WIICamera::get_frame(pt_frame& frame_)
{
- cv::Mat& frame = frame_.as<WIIFrame>()->mat;
+ cv::Mat& frame = frame_.as<WIIFrame>()->mat;
struct wii_info& wii = frame_.as<WIIFrame>()->wii;
+ const wii_camera_status new_frame = get_frame(frame);
- const wii_camera_status new_frame = get_frame(frame);
//create a fake blank frame
- frame = cv::Mat(cam_info.res_x, cam_info.res_y, CV_8UC3, cv::Scalar(0, 0, 0));
+ frame.create(cam_info.res_x, cam_info.res_y, CV_8UC3);
+ frame.setTo({0});
wii.status = new_frame;
- switch (new_frame)
- {
+ switch (new_frame)
+ {
case wii_cam_data_change:
- get_status(wii);
- get_points(wii);
+ get_status(wii);
+ get_points(wii);
break;
case wii_cam_data_no_change:
return result(false, cam_info);
- default:
- break;
+ default:
+ break;
}
return result(true, cam_info);
@@ -88,30 +86,28 @@ WIICamera::result WIICamera::get_frame(pt_frame& frame_)
bool WIICamera::start(const pt_settings&)
{
+ if (m_pDev)
+ return true;
m_pDev = std::make_unique<wiimote>();
m_pDev->ChangedCallback = on_state_change;
m_pDev->CallbackTriggerFlags = (state_change_flags)(CONNECTED |
EXTENSION_CHANGED |
MOTIONPLUS_CHANGED);
- return true;
+ return true;
}
void WIICamera::stop()
{
- desired_name = QString();
- active_name = QString();
- cam_info = pt_camera_info();
- cam_desired = pt_camera_info();
- onExit = true;
-
- if (m_pDev)
- {
- m_pDev->ChangedCallback = nullptr;
- m_pDev->Disconnect();
- m_pDev = nullptr;
- }
-
- Beep(1000, 200);
+ if (!m_pDev)
+ return;
+
+ cam_info = {};
+ cam_desired = {};
+ pitch_ = 0; roll_ = 0;
+
+ m_pDev->ChangedCallback = nullptr;
+ m_pDev->Disconnect();
+ m_pDev = nullptr;
}
#ifdef __MINGW32__
@@ -149,7 +145,6 @@ wii_camera_status WIICamera::pair()
while (ibtidx < max_devices && BluetoothFindNextRadio(&bt_param, hbtlist + ibtidx));
BluetoothFindRadioClose(hbt);
-
int i;
bool error = false;
for (i = 0; i < ibtidx; i++)