wudd/source/input/VPADInput.h

61 lines
2.0 KiB
C
Raw Permalink Normal View History

2021-10-09 00:58:55 +02:00
#pragma once
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "Input.h"
2022-07-26 08:16:27 +02:00
#include <vpad/input.h>
2021-10-09 00:58:55 +02:00
class VPadInput : public Input {
public:
//!Constructor
VPadInput() {
memset(&vpad, 0, sizeof(vpad));
}
//!Destructor
2021-10-11 22:43:04 +02:00
~VPadInput() override = default;
2021-10-09 00:58:55 +02:00
bool update(int32_t width, int32_t height) {
lastData = data;
VPADReadError vpadError = VPAD_READ_NO_SAMPLES;
VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError);
if (vpadError == VPAD_READ_SUCCESS) {
2022-07-26 08:16:27 +02:00
data.buttons_r = vpad.release;
data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger;
2021-10-09 00:58:55 +02:00
data.validPointer = !vpad.tpNormal.validity;
2022-07-26 08:16:27 +02:00
data.touched = vpad.tpNormal.touched;
2021-10-09 00:58:55 +02:00
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
//! calculate the screen offsets
data.x = -(width >> 1) + (int32_t) (((float) tpCalib.x / 1280.0f) * (float) width);
data.y = -(height >> 1) + (int32_t) (float) height - (((float) tpCalib.y / 720.0f) * (float) height);
return true;
} else {
data.buttons_h = 0;
2021-10-09 00:58:55 +02:00
}
return false;
}
private:
VPADStatus vpad{};
VPADTouchData tpCalib{};
};