libgui/include/gui/VPadController.h

64 lines
2.1 KiB
C
Raw Normal View History

2017-10-29 10:28:14 +01:00
/****************************************************************************
* 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/>.
****************************************************************************/
#ifndef VPAD_CONTROLLER_H_
#define VPAD_CONTROLLER_H_
2018-06-21 20:44:58 +02:00
#include <gui/GuiController.h>
#include <vpad/input.h>
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
class VPadController : public GuiController {
2017-10-29 10:28:14 +01:00
public:
//!Constructor
2018-06-21 20:44:58 +02:00
VPadController(int32_t channel)
2022-02-05 14:28:08 +01:00
: GuiController(channel) {
2017-10-29 10:28:14 +01:00
memset(&vpad, 0, sizeof(vpad));
}
//!Destructor
2020-08-13 12:38:07 +02:00
virtual ~VPadController() {}
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
bool update(int32_t width, int32_t height) {
2017-10-29 10:28:14 +01:00
lastData = data;
2018-06-21 20:44:58 +02:00
VPADReadError vpadError = VPAD_READ_NO_SAMPLES;
VPADRead(VPAD_CHAN_0, &vpad, 1, &vpadError);
2017-10-29 10:28:14 +01:00
2020-08-13 12:38:07 +02:00
if (vpadError == VPAD_READ_SUCCESS) {
2022-02-05 14:28:08 +01:00
data.buttons_r = vpad.release;
data.buttons_h = vpad.hold;
data.buttons_d = vpad.trigger;
2018-06-21 20:44:58 +02:00
data.validPointer = !vpad.tpNormal.validity;
2022-02-05 14:28:08 +01:00
data.touched = vpad.tpNormal.touched;
2017-10-29 10:28:14 +01:00
2018-06-21 20:44:58 +02:00
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpCalib, &vpad.tpFiltered1);
2017-10-29 10:28:14 +01:00
//! calculate the screen offsets
2020-08-13 12:38:07 +02:00
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);
2017-10-29 10:28:14 +01:00
return true;
}
return false;
}
private:
2018-06-21 20:44:58 +02:00
VPADStatus vpad;
VPADTouchData tpCalib;
2017-10-29 10:28:14 +01:00
};
#endif