2017-10-15 02:36:31 +00:00
|
|
|
//
|
|
|
|
// Joystick.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/10/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-10-15 02:36:31 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Joystick_hpp
|
|
|
|
#define Joystick_hpp
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Inputs {
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides an intermediate idealised model of a simple joystick, allowing a host
|
|
|
|
machine to toggle states, while an interested party either observes or polls.
|
|
|
|
*/
|
|
|
|
class Joystick {
|
|
|
|
public:
|
|
|
|
virtual ~Joystick() {}
|
2017-11-08 03:51:06 +00:00
|
|
|
|
2018-02-26 00:08:50 +00:00
|
|
|
struct DigitalInput {
|
|
|
|
enum Type {
|
|
|
|
Up, Down, Left, Right, Fire,
|
|
|
|
Key
|
|
|
|
} type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int index;
|
|
|
|
} control;
|
|
|
|
struct {
|
|
|
|
wchar_t symbol;
|
|
|
|
} key;
|
|
|
|
} info;
|
|
|
|
|
|
|
|
DigitalInput(Type type, int index = 0) : type(type) {
|
|
|
|
info.control.index = index;
|
|
|
|
}
|
|
|
|
DigitalInput(wchar_t symbol) : type(Key) {
|
|
|
|
info.key.symbol = symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (const DigitalInput &rhs) {
|
|
|
|
if(rhs.type != type) return false;
|
|
|
|
if(rhs.type == Key) {
|
|
|
|
return rhs.info.key.symbol == info.key.symbol;
|
|
|
|
} else {
|
|
|
|
return rhs.info.control.index == info.control.index;
|
|
|
|
}
|
|
|
|
}
|
2017-10-15 02:36:31 +00:00
|
|
|
};
|
|
|
|
|
2018-02-26 00:08:50 +00:00
|
|
|
virtual std::vector<DigitalInput> get_inputs() = 0;
|
|
|
|
|
2017-10-15 02:36:31 +00:00
|
|
|
// Host interface.
|
2018-02-26 00:08:50 +00:00
|
|
|
virtual void set_digital_input(const DigitalInput &digital_input, bool is_active) = 0;
|
2017-10-16 00:44:59 +00:00
|
|
|
virtual void reset_all_inputs() {
|
2018-02-26 00:08:50 +00:00
|
|
|
for(const auto &input: get_inputs()) {
|
|
|
|
set_digital_input(input, false);
|
|
|
|
}
|
2017-10-16 00:44:59 +00:00
|
|
|
}
|
2017-10-15 02:36:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Joystick_hpp */
|