summaryrefslogtreecommitdiffhomepage
path: root/tracker-wii
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:38:09 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:54:09 +0200
commit25b7bf6a9750f92bd75850740002d32dcf08470e (patch)
tree314e994452a3b56af7b9a9d7465e9f8c92cad791 /tracker-wii
parent0a1a0e9df00f37a210b67a11cf8f99550cafeeaf (diff)
tracker/wii: fix for mingw-w64
The module loses auto-pairing functionality, but it's at least useful to see GCC warnings. I don't intend to use GCC for actually running the module. Fix some warnings emitted by GCC, such as - memset(3) of non-POD struct - depending on "new T[0]" to return a null pointer - dependence on MSVC-specific pragmas for external libraries - lack of header guards - unintended usage of trigraph syntax Disable some GCC warnings for the "wiiyourself" library. It's not possible to patch it up, the code quality is that awful. Disable the builtin debug functionality since it depends on non-standard __VA_OPT__ (due in C++20). It's not possible to disable the warning emitted on the __VA_ARGS__ usage in GCC.
Diffstat (limited to 'tracker-wii')
-rw-r--r--tracker-wii/wii_camera.cpp14
-rw-r--r--tracker-wii/wii_camera.h2
-rw-r--r--tracker-wii/wii_frame.cpp20
-rw-r--r--tracker-wii/wii_point_extractor.cpp2
-rw-r--r--tracker-wii/wiiyourself/CMakeLists.txt5
-rw-r--r--tracker-wii/wiiyourself/warns-begin.hpp9
-rw-r--r--tracker-wii/wiiyourself/warns-end.hpp3
-rw-r--r--tracker-wii/wiiyourself/wiimote.cpp45
-rw-r--r--tracker-wii/wiiyourself/wiimote.h10
-rw-r--r--tracker-wii/wiiyourself/wiimote_common.h2
10 files changed, 72 insertions, 40 deletions
diff --git a/tracker-wii/wii_camera.cpp b/tracker-wii/wii_camera.cpp
index 93dfe4ff..38cbf26a 100644
--- a/tracker-wii/wii_camera.cpp
+++ b/tracker-wii/wii_camera.cpp
@@ -21,6 +21,7 @@
#include <opencv2/imgproc.hpp>
+#include <bthsdpdef.h>
#include <bluetoothapis.h>
using namespace pt_module;
@@ -79,6 +80,8 @@ WIICamera::result WIICamera::get_frame(pt_frame& frame_)
break;
case wii_cam_data_no_change:
return { false, cam_info };
+ default:
+ break;
}
return { true, cam_info };
@@ -109,9 +112,12 @@ void WIICamera::stop()
cam_desired = pt_camera_info();
}
-
wii_camera_status WIICamera::_pair()
{
+#if defined __MINGW32__
+ // missing prototypes and implib entries
+ return wii_cam_wait_for_connect;
+#else
wii_camera_status ret = wii_cam_wait_for_sync;
HBLUETOOTH_RADIO_FIND hbt;
BLUETOOTH_FIND_RADIO_PARAMS bt_param;
@@ -195,21 +201,25 @@ wii_camera_status WIICamera::_pair()
}
if (wiifound) { ret = wii_cam_wait_for_connect; }
return ret;
+#endif
}
wii_camera_status WIICamera::_get_frame(cv::Mat& frame)
{
+ (void)frame;
wii_camera_status ret = wii_cam_wait_for_connect;
if (!m_pDev->IsConnected()) {
qDebug() << "wii wait";
ret = _pair();
- switch(ret){
+ switch (ret) {
case wii_cam_wait_for_sync:
m_pDev->Disconnect();
goto goodbye;
case wii_cam_wait_for_connect:
break;
+ default:
+ break;
}
if (!m_pDev->Connect(wiimote::FIRST_AVAILABLE)) {
Beep(500, 30); Sleep(1000);
diff --git a/tracker-wii/wii_camera.h b/tracker-wii/wii_camera.h
index 55def206..f4ee5c00 100644
--- a/tracker-wii/wii_camera.h
+++ b/tracker-wii/wii_camera.h
@@ -41,7 +41,7 @@ struct WIICamera final : pt_camera
QString get_desired_name() const override;
QString get_active_name() const override;
- void set_fov(double value) override {}
+ void set_fov(double value) override { (void)value; }
void show_camera_settings() override;
private:
diff --git a/tracker-wii/wii_frame.cpp b/tracker-wii/wii_frame.cpp
index df7b9ca4..432b1f18 100644
--- a/tracker-wii/wii_frame.cpp
+++ b/tracker-wii/wii_frame.cpp
@@ -49,14 +49,18 @@ WIIPreview::WIIPreview(int w, int h)
QImage WIIPreview::get_bitmap()
{
- switch (status) {
- case wii_cam_wait_for_dongle:
- return QImage(":/Resources/usb.png");
- case wii_cam_wait_for_sync:
- return QImage(":/Resources/sync.png");
- case wii_cam_wait_for_connect:
- return QImage(":/Resources/on.png");
- }
+ switch (status) {
+ case wii_cam_wait_for_dongle:
+ return QImage(":/Resources/usb.png");
+ case wii_cam_wait_for_sync:
+ return QImage(":/Resources/sync.png");
+ case wii_cam_wait_for_connect:
+ return QImage(":/Resources/on.png");
+ case wii_cam_data_change:
+ case wii_cam_data_no_change:
+ break;
+ }
+
int stride = frame_out.step.p[0];
if (stride < 64 || stride < frame_out.cols * 4)
diff --git a/tracker-wii/wii_point_extractor.cpp b/tracker-wii/wii_point_extractor.cpp
index 215d50b8..1be6049b 100644
--- a/tracker-wii/wii_point_extractor.cpp
+++ b/tracker-wii/wii_point_extractor.cpp
@@ -57,7 +57,7 @@ void WIIPointExtractor::_draw_point(cv::Mat& preview_frame, const vec2& p, const
cv::Point(p2.x, p2.y + len),
color,
thinkness);
-};
+}
bool WIIPointExtractor::_draw_points(cv::Mat& preview_frame, const struct wii_info &wii, std::vector<vec2>& points)
{
diff --git a/tracker-wii/wiiyourself/CMakeLists.txt b/tracker-wii/wiiyourself/CMakeLists.txt
index 614ff1c3..fe6d62e8 100644
--- a/tracker-wii/wiiyourself/CMakeLists.txt
+++ b/tracker-wii/wiiyourself/CMakeLists.txt
@@ -1 +1,4 @@
-otr_module(wiiyourself STATIC NO-COMPAT NO-QT)
+if(WIN32)
+ otr_module(wiiyourself STATIC NO-COMPAT NO-QT)
+ target_link_libraries(${self} setupapi hid winmm)
+endif()
diff --git a/tracker-wii/wiiyourself/warns-begin.hpp b/tracker-wii/wiiyourself/warns-begin.hpp
new file mode 100644
index 00000000..ca2b6b93
--- /dev/null
+++ b/tracker-wii/wiiyourself/warns-begin.hpp
@@ -0,0 +1,9 @@
+#ifdef __GNUG__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wswitch"
+# pragma GCC diagnostic ignored "-Wreorder"
+# pragma GCC diagnostic ignored "-Wunused-variable"
+# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+# pragma GCC diagnostic ignored "-Wunused-parameter"
+# pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
diff --git a/tracker-wii/wiiyourself/warns-end.hpp b/tracker-wii/wiiyourself/warns-end.hpp
new file mode 100644
index 00000000..beaf245d
--- /dev/null
+++ b/tracker-wii/wiiyourself/warns-end.hpp
@@ -0,0 +1,3 @@
+#ifdef __GNUG__
+# pragma GCC diagnostic pop
+#endif
diff --git a/tracker-wii/wiiyourself/wiimote.cpp b/tracker-wii/wiiyourself/wiimote.cpp
index f53e1acf..0da0113b 100644
--- a/tracker-wii/wiiyourself/wiimote.cpp
+++ b/tracker-wii/wiiyourself/wiimote.cpp
@@ -8,15 +8,17 @@
//
// wiimote.cpp (tab = 4 spaces)
+#include "warns-begin.hpp"
+
// VC-specifics:
#ifdef _MSC_VER
// disable warning "C++ exception handler used, but unwind semantics are not enabled."
// in <xstring> (I don't use it - or just enable C++ exceptions)
# pragma warning(disable: 4530)
// auto-link with the necessary libs
-# pragma comment(lib, "setupapi.lib")
-# pragma comment(lib, "hid.lib") // for HID API (from DDK)
-# pragma comment(lib, "winmm.lib") // for timeGetTime()
+//# pragma comment(lib, "setupapi.lib")
+//# pragma comment(lib, "hid.lib") // for HID API (from DDK)
+//# pragma comment(lib, "winmm.lib") // for timeGetTime()
#endif // _MSC_VER
#include "wiimote.h"
@@ -24,14 +26,13 @@
extern "C" {
#include <hidsdi.h>// from WinDDK
}
+
#include <sys/types.h> // for _stat
#include <sys/stat.h> // "
+#include <cstring>
+#include <cstdio>
#include <process.h> // for _beginthreadex()
-#ifdef __BORLANDC__
-# include <cmath.h> // for orientation
-#else
-# include <math.h> // "
-#endif
+#include <math.h> // for orientation
#include <mmreg.h> // for WAVEFORMATEXTENSIBLE
#include <mmsystem.h> // for timeGetTime()
@@ -49,17 +50,12 @@ template<class T> inline T square(const T& val) { return val * val; }
// ------------------------------------------------------------------------------------
// Tracing & Debugging
// ------------------------------------------------------------------------------------
-#define PREFIX _T("WiiYourself! : ")
+#define PREFIX "WiiYourself: "
// comment these to auto-strip their code from the library:
// (they currently use OutputDebugString() via _TRACE() - change to suit)
-#if (_MSC_VER >= 1400) // VC 2005+ (earlier versions don't support variable args)
-# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n"), __VA_ARGS__)
-# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n"), __VA_ARGS__)
-#elif defined(__MINGW32__)
-# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n") , ##__VA_ARGS__)
-# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n") , ##__VA_ARGS__)
-#endif
+# define TRACE _TRACE
+# define WARN _TRACE
// uncomment any of these for deeper debugging:
//#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n"), __VA_ARGS__) // VC 2005+
//#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n") , ##__VA_ARGS__) // mingw
@@ -745,7 +741,7 @@ void wiimote::SetReportType(input_report type, bool continuous)
TYPE2NAME(IN_BUTTONS_ACCEL_EXT) :
TYPE2NAME(IN_BUTTONS_ACCEL_IR_EXT) :
TYPE2NAME(IN_BUTTONS_BALANCE_BOARD) :
- _T("(unknown??)");
+ _T("(unknown?)");
TRACE(_T("ReportType: %s (%s)"), name, (continuous ? _T("continuous") :
_T("non-continuous")));
#endif
@@ -2372,10 +2368,10 @@ unsigned __stdcall wiimote::SampleStreamThreadfunc(void* param)
// ------------------------------------------------------------------------------------
bool wiimote::Load16bitMonoSampleWAV(const TCHAR* filepath, wiimote_sample &out)
{
+ out = {};
// converts unsigned 16bit mono .wav audio data to the 4bit ADPCM variant
// used by the Wiimote (at least the closest match so far), and returns
// the data in a BYTE array (caller must delete[] it when no longer needed):
- memset(&out, 0, sizeof(out));
TRACE(_T("Loading '%s'"), filepath);
@@ -2543,10 +2539,10 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath,
speaker_freq freq,
wiimote_sample &out)
{
+ out = {};
// converts (.wav style) unsigned 16bit mono raw data to the 4bit ADPCM variant
// used by the Wiimote, and returns the data in a BYTE array (caller must
// delete[] it when no longer needed):
- memset(&out, 0, sizeof(out));
// get the length of the file
struct _stat file_info;
@@ -2564,12 +2560,11 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath,
unsigned total_samples = (len + 1) / 2; // round up just in case file is corrupt
// allocate a buffer to hold the samples to convert
- short *samples = new short[total_samples];
- _ASSERT(samples);
- if (!samples) {
+ if (!total_samples) {
TRACE(_T("Couldn't open '%s"), filepath);
return false;
}
+ short *samples = new short[total_samples];
// load them
FILE *file;
@@ -2608,10 +2603,11 @@ bool wiimote::Convert16bitMonoSamples(const short* samples,
speaker_freq freq,
wiimote_sample &out)
{
+ out = {};
+
// converts 16bit mono sample data to the native 4bit format used by the Wiimote,
// and returns the data in a BYTE array (caller must delete[] when no
// longer needed):
- memset(&out, 0, sizeof(0));
_ASSERT(samples && length);
if (!samples || !length)
@@ -2815,3 +2811,6 @@ void wiimote::StopRecording()
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
+
+#include "warns-end.hpp"
+
diff --git a/tracker-wii/wiiyourself/wiimote.h b/tracker-wii/wiiyourself/wiimote.h
index 3588b7c7..dac949c7 100644
--- a/tracker-wii/wiiyourself/wiimote.h
+++ b/tracker-wii/wiiyourself/wiimote.h
@@ -10,15 +10,15 @@
#pragma once
+#include "warns-begin.hpp"
+
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h> // auto Unicode/Ansi support
#include <queue> // for HID write method
#include <list> // for state recording
-#ifndef QWORD
- typedef unsigned __int64 QWORD;
-#endif
+typedef unsigned __int64 QWORD;
#ifdef _MSC_VER // VC-specific: _DEBUG build only _ASSERT() sanity checks
# include <crtdbg.h>
@@ -181,7 +181,7 @@ class wiimote : public wiimote_state
// get the frequency from speaker_freq enum
static const unsigned FreqLookup [TOTAL_FREQUENCIES];
- static const unsigned GetFreqLookup (unsigned index)
+ static unsigned GetFreqLookup(unsigned index)
{
_ASSERT(index < TOTAL_FREQUENCIES);
if(index >= TOTAL_FREQUENCIES)
@@ -486,3 +486,5 @@ volatile int MotionPlusDetectCount; // waiting for the result
unsigned ExtTriggerFlags;// extension changes "
} Recording;
};
+
+#include "warns-end.hpp"
diff --git a/tracker-wii/wiiyourself/wiimote_common.h b/tracker-wii/wiiyourself/wiimote_common.h
index c0fd01e1..9934d6ec 100644
--- a/tracker-wii/wiiyourself/wiimote_common.h
+++ b/tracker-wii/wiiyourself/wiimote_common.h
@@ -1,3 +1,5 @@
+#pragma once
+
// _______________________________________________________________________________
//
// - WiiYourself! - native C++ Wiimote library v1.15 RC