-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjoystick_state.cpp
46 lines (37 loc) · 1 KB
/
joystick_state.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "joystick_state.h"
#include <sstream>
void joystick_state::put_axis(unsigned char number, float value)
{
this->m_mapAxes[number] = value;
this->onAxisUpdated(number);
}
void joystick_state::put_button(unsigned char number, bool value)
{
this->m_mapButtons[number] = value;
this->onButtonUpdated(number);
}
float joystick_state::get_axis(unsigned char number)
{
return this->m_mapAxes[number];
}
bool joystick_state::get_button(unsigned char number)
{
return this->m_mapButtons[number];
}
std::string joystick_state::toString() const
{
std::stringstream ss;
for (auto kvp : this->m_mapAxes)
{
ss << "ax" << (int)kvp.first << "=" << kvp.second << " ";
}
ss << std::endl;
for (auto kvp : this->m_mapButtons)
{
ss << "bt" << (int)kvp.first << "=" << (kvp.second ? "ON" : "off") << " ";
}
ss << std::endl;
return ss.str();
}
void joystick_state::onButtonUpdated(unsigned char number) {}
void joystick_state::onAxisUpdated(unsigned char number) {}