Nugget
Loading...
Searching...
No Matches
simplepad.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <EASTL/functional.h>
30#include <stdint.h>
31
32namespace psyqo {
33
47class SimplePad {
48 public:
49 enum Pad { Pad1, Pad2 };
50
51 enum Button {
52 Select = 0,
53 L3 = 1,
54 R3 = 2,
55 Start = 3,
56 Up = 4,
57 Right = 5,
58 Down = 6,
59 Left = 7,
60 L2 = 8,
61 R2 = 9,
62 L1 = 10,
63 R1 = 11,
65 Circle = 13,
66 Cross = 14,
67 Square = 15,
68 };
69
75
86 void initialize();
87
106 void setOnEvent(eastl::function<void(Event)>&& callback) { m_callback = eastl::move(callback); }
107
117 bool isPadConnected(Pad pad) const { return (m_padData[pad][0] & 0xff) == 0; }
118
129 bool isButtonPressed(Pad pad, Button button) const { return (m_padData[pad][1] & (1 << button)) == 0; }
130
131 private:
132 void processChanges(Pad pad);
133
134 uint16_t m_padData[2][0x11];
135 eastl::function<void(Event)> m_callback;
136 bool m_connected[2] = {false, false};
137 uint16_t m_buttons[2] = {0xffff, 0xffff};
138};
139
140} // namespace psyqo
A simple class to access the pads.
Definition simplepad.hh:47
Pad
Definition simplepad.hh:49
@ Pad2
Definition simplepad.hh:49
@ Pad1
Definition simplepad.hh:49
Button
Definition simplepad.hh:51
@ L2
Definition simplepad.hh:60
@ Square
Definition simplepad.hh:67
@ L3
Definition simplepad.hh:53
@ Up
Definition simplepad.hh:56
@ Right
Definition simplepad.hh:57
@ R2
Definition simplepad.hh:61
@ Triangle
Definition simplepad.hh:64
@ Cross
Definition simplepad.hh:66
@ Select
Definition simplepad.hh:52
@ Circle
Definition simplepad.hh:65
@ Down
Definition simplepad.hh:58
@ Start
Definition simplepad.hh:55
@ L1
Definition simplepad.hh:62
@ R3
Definition simplepad.hh:54
@ R1
Definition simplepad.hh:63
@ Left
Definition simplepad.hh:59
void setOnEvent(eastl::function< void(Event)> &&callback)
Sets the event callback function.
Definition simplepad.hh:106
bool isPadConnected(Pad pad) const
Returns the state of a pad.
Definition simplepad.hh:117
bool isButtonPressed(Pad pad, Button button) const
Returns the state of a button.
Definition simplepad.hh:129
void initialize()
Initializes the pads.
Definition simplepad.cpp:32
Definition cdrom-loader.hh:39
Definition simplepad.hh:70
Button button
Definition simplepad.hh:73
@ ButtonReleased
Definition simplepad.hh:71
@ PadConnected
Definition simplepad.hh:71
@ PadDisconnected
Definition simplepad.hh:71
@ ButtonPressed
Definition simplepad.hh:71
Pad pad
Definition simplepad.hh:72
enum psyqo::SimplePad::Event::@37 type
void void(ptr, size)