mirror of
https://github.com/jtgans/g13gui.git
synced 2025-07-10 11:19:00 -04:00
g13d: Get rid of some of the G13_ prefixing for classes
This commit is contained in:
parent
1918d6875c
commit
22cd1c9351
@ -11,19 +11,19 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
G13_Action::~G13_Action() {
|
Action::~Action() {
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Action_Keys::G13_Action_Keys(G13_Device &keypad,
|
Action_Keys::Action_Keys(Device &keypad,
|
||||||
const std::string &keys_string)
|
const std::string &keys_string)
|
||||||
: G13_Action(keypad) {
|
: Action(keypad) {
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
boost::split(keys, keys_string, boost::is_any_of("+"));
|
boost::split(keys, keys_string, boost::is_any_of("+"));
|
||||||
|
|
||||||
BOOST_FOREACH (std::string const &key, keys) {
|
BOOST_FOREACH (std::string const &key, keys) {
|
||||||
auto kval = manager().find_input_key_value(key);
|
auto kval = manager().find_input_key_value(key);
|
||||||
if (kval == BAD_KEY_VALUE) {
|
if (kval == BAD_KEY_VALUE) {
|
||||||
throw G13_CommandException("create action unknown key : " + key);
|
throw CommandException("create action unknown key : " + key);
|
||||||
}
|
}
|
||||||
_keys.push_back(kval);
|
_keys.push_back(kval);
|
||||||
}
|
}
|
||||||
@ -31,17 +31,17 @@ G13_Action_Keys::G13_Action_Keys(G13_Device &keypad,
|
|||||||
std::vector<int> _keys;
|
std::vector<int> _keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Action_Keys::~G13_Action_Keys() {
|
Action_Keys::~Action_Keys() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_Keys::act(G13_Device &g13, bool is_down) {
|
void Action_Keys::act(Device &g13, bool is_down) {
|
||||||
for (auto key : _keys) {
|
for (auto key : _keys) {
|
||||||
g13.send_event(EV_KEY, key, is_down);
|
g13.send_event(EV_KEY, key, is_down);
|
||||||
G13_LOG(trace, "sending KEY " << (is_down ? "DOWN " : "UP ") << key);
|
G13_LOG(trace, "sending KEY " << (is_down ? "DOWN " : "UP ") << key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_Keys::dump(std::ostream &out) const {
|
void Action_Keys::dump(std::ostream &out) const {
|
||||||
out << " SEND KEYS: ";
|
out << " SEND KEYS: ";
|
||||||
|
|
||||||
for (size_t i = 0; i < _keys.size(); i++) {
|
for (size_t i = 0; i < _keys.size(); i++) {
|
||||||
@ -50,39 +50,39 @@ void G13_Action_Keys::dump(std::ostream &out) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Action_PipeOut::G13_Action_PipeOut(G13_Device &keypad,
|
Action_PipeOut::Action_PipeOut(Device &keypad,
|
||||||
const std::string &out)
|
const std::string &out)
|
||||||
: G13_Action(keypad),
|
: Action(keypad),
|
||||||
_out(out + "\n") {
|
_out(out + "\n") {
|
||||||
}
|
}
|
||||||
G13_Action_PipeOut::~G13_Action_PipeOut() {
|
Action_PipeOut::~Action_PipeOut() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_PipeOut::act(G13_Device &kp, bool is_down) {
|
void Action_PipeOut::act(Device &kp, bool is_down) {
|
||||||
if (is_down) {
|
if (is_down) {
|
||||||
kp.write_output_pipe(_out);
|
kp.write_output_pipe(_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_PipeOut::dump(std::ostream &o) const {
|
void Action_PipeOut::dump(std::ostream &o) const {
|
||||||
o << "WRITE PIPE : " << repr(_out);
|
o << "WRITE PIPE : " << repr(_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Action_Command::G13_Action_Command(G13_Device &keypad,
|
Action_Command::Action_Command(Device &keypad,
|
||||||
const std::string &cmd)
|
const std::string &cmd)
|
||||||
: G13_Action(keypad),
|
: Action(keypad),
|
||||||
_cmd(cmd) {
|
_cmd(cmd) {
|
||||||
}
|
}
|
||||||
G13_Action_Command::~G13_Action_Command() {
|
Action_Command::~Action_Command() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_Command::act(G13_Device &kp, bool is_down) {
|
void Action_Command::act(Device &kp, bool is_down) {
|
||||||
if (is_down) {
|
if (is_down) {
|
||||||
keypad().command(_cmd.c_str());
|
keypad().command(_cmd.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Action_Command::dump(std::ostream &o) const {
|
void Action_Command::dump(std::ostream &o) const {
|
||||||
o << "COMMAND : " << repr(_cmd);
|
o << "COMMAND : " << repr(_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,49 +9,49 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_Device;
|
class Device;
|
||||||
class G13_Manager;
|
class Manager;
|
||||||
|
|
||||||
/*! holds potential actions which can be bound to G13 activity
|
/*! holds potential actions which can be bound to G13 activity
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class G13_Action {
|
class Action {
|
||||||
public:
|
public:
|
||||||
G13_Action(G13_Device &keypad) : _keypad(keypad) {
|
Action(Device &keypad) : _keypad(keypad) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~G13_Action();
|
virtual ~Action();
|
||||||
|
|
||||||
virtual void act(G13_Device &, bool is_down) = 0;
|
virtual void act(Device &, bool is_down) = 0;
|
||||||
virtual void dump(std::ostream &) const = 0;
|
virtual void dump(std::ostream &) const = 0;
|
||||||
|
|
||||||
void act(bool is_down) {
|
void act(bool is_down) {
|
||||||
act(keypad(), is_down);
|
act(keypad(), is_down);
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Device &keypad() {
|
Device &keypad() {
|
||||||
return _keypad;
|
return _keypad;
|
||||||
}
|
}
|
||||||
const G13_Device &keypad() const {
|
const Device &keypad() const {
|
||||||
return _keypad;
|
return _keypad;
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Manager &manager();
|
Manager &manager();
|
||||||
const G13_Manager &manager() const;
|
const Manager &manager() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
G13_Device &_keypad;
|
Device &_keypad;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* action to send one or more keystrokes
|
* action to send one or more keystrokes
|
||||||
*/
|
*/
|
||||||
class G13_Action_Keys : public G13_Action {
|
class Action_Keys : public Action {
|
||||||
public:
|
public:
|
||||||
G13_Action_Keys(G13_Device &keypad, const std::string &keys);
|
Action_Keys(Device &keypad, const std::string &keys);
|
||||||
virtual ~G13_Action_Keys();
|
virtual ~Action_Keys();
|
||||||
|
|
||||||
virtual void act(G13_Device &, bool is_down);
|
virtual void act(Device &, bool is_down);
|
||||||
virtual void dump(std::ostream &) const;
|
virtual void dump(std::ostream &) const;
|
||||||
|
|
||||||
std::vector<LINUX_KEY_VALUE> _keys;
|
std::vector<LINUX_KEY_VALUE> _keys;
|
||||||
@ -60,12 +60,12 @@ class G13_Action_Keys : public G13_Action {
|
|||||||
/*!
|
/*!
|
||||||
* action to send a string to the output pipe
|
* action to send a string to the output pipe
|
||||||
*/
|
*/
|
||||||
class G13_Action_PipeOut : public G13_Action {
|
class Action_PipeOut : public Action {
|
||||||
public:
|
public:
|
||||||
G13_Action_PipeOut(G13_Device &keypad, const std::string &out);
|
Action_PipeOut(Device &keypad, const std::string &out);
|
||||||
virtual ~G13_Action_PipeOut();
|
virtual ~Action_PipeOut();
|
||||||
|
|
||||||
virtual void act(G13_Device &, bool is_down);
|
virtual void act(Device &, bool is_down);
|
||||||
virtual void dump(std::ostream &) const;
|
virtual void dump(std::ostream &) const;
|
||||||
|
|
||||||
std::string _out;
|
std::string _out;
|
||||||
@ -74,32 +74,32 @@ class G13_Action_PipeOut : public G13_Action {
|
|||||||
/*!
|
/*!
|
||||||
* action to send a command to the g13
|
* action to send a command to the g13
|
||||||
*/
|
*/
|
||||||
class G13_Action_Command : public G13_Action {
|
class Action_Command : public Action {
|
||||||
public:
|
public:
|
||||||
G13_Action_Command(G13_Device &keypad, const std::string &cmd);
|
Action_Command(Device &keypad, const std::string &cmd);
|
||||||
virtual ~G13_Action_Command();
|
virtual ~Action_Command();
|
||||||
|
|
||||||
virtual void act(G13_Device &, bool is_down);
|
virtual void act(Device &, bool is_down);
|
||||||
virtual void dump(std::ostream &) const;
|
virtual void dump(std::ostream &) const;
|
||||||
|
|
||||||
std::string _cmd;
|
std::string _cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<G13_Action> G13_ActionPtr;
|
typedef std::shared_ptr<Action> ActionPtr;
|
||||||
|
|
||||||
template <class PARENT_T>
|
template <class PARENT_T>
|
||||||
class G13_Actionable {
|
class Actionable {
|
||||||
public:
|
public:
|
||||||
G13_Actionable(PARENT_T &parent_arg, const std::string &name)
|
Actionable(PARENT_T &parent_arg, const std::string &name)
|
||||||
: _name(name),
|
: _name(name),
|
||||||
_parent_ptr(&parent_arg) {
|
_parent_ptr(&parent_arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~G13_Actionable() {
|
virtual ~Actionable() {
|
||||||
_parent_ptr = 0;
|
_parent_ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_ActionPtr action() const {
|
ActionPtr action() const {
|
||||||
return _action;
|
return _action;
|
||||||
}
|
}
|
||||||
const std::string &name() const {
|
const std::string &name() const {
|
||||||
@ -111,20 +111,20 @@ class G13_Actionable {
|
|||||||
const PARENT_T &parent() const {
|
const PARENT_T &parent() const {
|
||||||
return *_parent_ptr;
|
return *_parent_ptr;
|
||||||
}
|
}
|
||||||
G13_Manager &manager() {
|
Manager &manager() {
|
||||||
return _parent_ptr->manager();
|
return _parent_ptr->manager();
|
||||||
}
|
}
|
||||||
const G13_Manager &manager() const {
|
const Manager &manager() const {
|
||||||
return _parent_ptr->manager();
|
return _parent_ptr->manager();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void set_action(const G13_ActionPtr &action) {
|
virtual void set_action(const ActionPtr &action) {
|
||||||
_action = action;
|
_action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
G13_ActionPtr _action;
|
ActionPtr _action;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PARENT_T *_parent_ptr;
|
PARENT_T *_parent_ptr;
|
||||||
|
@ -104,7 +104,7 @@ int g13_create_uinput(void) {
|
|||||||
return ufile;
|
return ufile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::send_event(int type, int code, int val) {
|
void Device::send_event(int type, int code, int val) {
|
||||||
memset(&_event, 0, sizeof(_event));
|
memset(&_event, 0, sizeof(_event));
|
||||||
gettimeofday(&_event.time, 0);
|
gettimeofday(&_event.time, 0);
|
||||||
_event.type = type;
|
_event.type = type;
|
||||||
@ -119,7 +119,7 @@ void G13_Device::send_event(int type, int code, int val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::write_output_pipe(const std::string &out) {
|
void Device::write_output_pipe(const std::string &out) {
|
||||||
// TODO(jtgans): Make this actually verify it writes all bytes
|
// TODO(jtgans): Make this actually verify it writes all bytes
|
||||||
auto result = write(_output_pipe_fid, out.c_str(), out.size());
|
auto result = write(_output_pipe_fid, out.c_str(), out.size());
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
@ -128,7 +128,7 @@ void G13_Device::write_output_pipe(const std::string &out) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::set_mode_leds(int leds) {
|
void Device::set_mode_leds(int leds) {
|
||||||
unsigned char usb_data[] = {5, 0, 0, 0, 0};
|
unsigned char usb_data[] = {5, 0, 0, 0, 0};
|
||||||
usb_data[1] = leds;
|
usb_data[1] = leds;
|
||||||
int r = libusb_control_transfer(
|
int r = libusb_control_transfer(
|
||||||
@ -141,7 +141,7 @@ void G13_Device::set_mode_leds(int leds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::set_key_color(int red, int green, int blue) {
|
void Device::set_key_color(int red, int green, int blue) {
|
||||||
int error;
|
int error;
|
||||||
unsigned char usb_data[] = {5, 0, 0, 0, 0};
|
unsigned char usb_data[] = {5, 0, 0, 0, 0};
|
||||||
usb_data[1] = red;
|
usb_data[1] = red;
|
||||||
@ -157,7 +157,7 @@ void G13_Device::set_key_color(int red, int green, int blue) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::register_context(libusb_context *_ctx) {
|
void Device::register_context(libusb_context *_ctx) {
|
||||||
ctx = _ctx;
|
ctx = _ctx;
|
||||||
|
|
||||||
int leds = 0;
|
int leds = 0;
|
||||||
@ -183,7 +183,7 @@ void G13_Device::register_context(libusb_context *_ctx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::cleanup() {
|
void Device::cleanup() {
|
||||||
remove(_input_pipe_name.c_str());
|
remove(_input_pipe_name.c_str());
|
||||||
remove(_output_pipe_name.c_str());
|
remove(_output_pipe_name.c_str());
|
||||||
ioctl(_uinput_fid, UI_DEV_DESTROY);
|
ioctl(_uinput_fid, UI_DEV_DESTROY);
|
||||||
@ -195,7 +195,7 @@ void G13_Device::cleanup() {
|
|||||||
/*! reads and processes key state report from G13
|
/*! reads and processes key state report from G13
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int G13_Device::read_keys() {
|
int Device::read_keys() {
|
||||||
unsigned char buffer[G13_REPORT_SIZE];
|
unsigned char buffer[G13_REPORT_SIZE];
|
||||||
int size;
|
int size;
|
||||||
int error =
|
int error =
|
||||||
@ -217,7 +217,7 @@ int G13_Device::read_keys() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::read_config_file(const std::string &filename) {
|
void Device::read_config_file(const std::string &filename) {
|
||||||
std::ifstream s(filename);
|
std::ifstream s(filename);
|
||||||
|
|
||||||
G13_LOG(info, "reading configuration from " << filename);
|
G13_LOG(info, "reading configuration from " << filename);
|
||||||
@ -245,7 +245,7 @@ void G13_Device::read_config_file(const std::string &filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::read_commands() {
|
void Device::read_commands() {
|
||||||
fd_set set;
|
fd_set set;
|
||||||
FD_ZERO(&set);
|
FD_ZERO(&set);
|
||||||
FD_SET(_input_pipe_fid, &set);
|
FD_SET(_input_pipe_fid, &set);
|
||||||
@ -281,7 +281,7 @@ void G13_Device::read_commands() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Device::G13_Device(G13_Manager &manager, libusb_device_handle *handle,
|
Device::Device(Manager &manager, libusb_device_handle *handle,
|
||||||
int _id)
|
int _id)
|
||||||
: _id_within_manager(_id),
|
: _id_within_manager(_id),
|
||||||
handle(handle),
|
handle(handle),
|
||||||
@ -290,7 +290,7 @@ G13_Device::G13_Device(G13_Manager &manager, libusb_device_handle *handle,
|
|||||||
_manager(manager),
|
_manager(manager),
|
||||||
_lcd(*this),
|
_lcd(*this),
|
||||||
_stick(*this) {
|
_stick(*this) {
|
||||||
_current_profile = ProfilePtr(new G13_Profile(*this, "default"));
|
_current_profile = ProfilePtr(new Profile(*this, "default"));
|
||||||
_profiles["default"] = _current_profile;
|
_profiles["default"] = _current_profile;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(keys); i++) {
|
for (unsigned int i = 0; i < sizeof(keys); i++) {
|
||||||
@ -303,7 +303,7 @@ G13_Device::G13_Device(G13_Manager &manager, libusb_device_handle *handle,
|
|||||||
_init_commands();
|
_init_commands();
|
||||||
}
|
}
|
||||||
|
|
||||||
FontPtr G13_Device::switch_to_font(const std::string &name) {
|
FontPtr Device::switch_to_font(const std::string &name) {
|
||||||
FontPtr rv = _fonts[name];
|
FontPtr rv = _fonts[name];
|
||||||
if (rv) {
|
if (rv) {
|
||||||
_current_font = rv;
|
_current_font = rv;
|
||||||
@ -311,34 +311,34 @@ FontPtr G13_Device::switch_to_font(const std::string &name) {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::switch_to_profile(const std::string &name) {
|
void Device::switch_to_profile(const std::string &name) {
|
||||||
_current_profile = profile(name);
|
_current_profile = profile(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfilePtr G13_Device::profile(const std::string &name) {
|
ProfilePtr Device::profile(const std::string &name) {
|
||||||
ProfilePtr rv = _profiles[name];
|
ProfilePtr rv = _profiles[name];
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
rv = ProfilePtr(new G13_Profile(*_current_profile, name));
|
rv = ProfilePtr(new Profile(*_current_profile, name));
|
||||||
_profiles[name] = rv;
|
_profiles[name] = rv;
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_ActionPtr G13_Device::make_action(const std::string &action) {
|
ActionPtr Device::make_action(const std::string &action) {
|
||||||
if (!action.size()) {
|
if (!action.size()) {
|
||||||
throw G13_CommandException("empty action string");
|
throw CommandException("empty action string");
|
||||||
}
|
}
|
||||||
if (action[0] == '>') {
|
if (action[0] == '>') {
|
||||||
return G13_ActionPtr(new G13_Action_PipeOut(*this, &action[1]));
|
return ActionPtr(new Action_PipeOut(*this, &action[1]));
|
||||||
} else if (action[0] == '!') {
|
} else if (action[0] == '!') {
|
||||||
return G13_ActionPtr(new G13_Action_Command(*this, &action[1]));
|
return ActionPtr(new Action_Command(*this, &action[1]));
|
||||||
} else {
|
} else {
|
||||||
return G13_ActionPtr(new G13_Action_Keys(*this, action));
|
return ActionPtr(new Action_Keys(*this, action));
|
||||||
}
|
}
|
||||||
throw G13_CommandException("can't create action for " + action);
|
throw CommandException("can't create action for " + action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::dump(std::ostream &o, int detail) {
|
void Device::dump(std::ostream &o, int detail) {
|
||||||
o << "G13 id=" << id_within_manager() << std::endl
|
o << "G13 id=" << id_within_manager() << std::endl
|
||||||
<< " input_pipe_name=" << repr(_input_pipe_name) << std::endl
|
<< " input_pipe_name=" << repr(_input_pipe_name) << std::endl
|
||||||
<< " output_pipe_name=" << repr(_output_pipe_name) << std::endl
|
<< " output_pipe_name=" << repr(_output_pipe_name) << std::endl
|
||||||
@ -375,14 +375,14 @@ inline const char *advance_ws(const char *&source, std::string &dest) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct command_adder {
|
struct command_adder {
|
||||||
command_adder(G13_Device::CommandFunctionTable &t, const char *name)
|
command_adder(Device::CommandFunctionTable &t, const char *name)
|
||||||
: _t(t),
|
: _t(t),
|
||||||
_name(name) {
|
_name(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Device::CommandFunctionTable &_t;
|
Device::CommandFunctionTable &_t;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
command_adder &operator+=(G13_Device::COMMAND_FUNCTION f) {
|
command_adder &operator+=(Device::COMMAND_FUNCTION f) {
|
||||||
_t[_name] = f;
|
_t[_name] = f;
|
||||||
return *this;
|
return *this;
|
||||||
};
|
};
|
||||||
@ -400,7 +400,7 @@ struct command_adder {
|
|||||||
BOOST_PP_STRINGIZE(name)); \
|
BOOST_PP_STRINGIZE(name)); \
|
||||||
BOOST_PP_CAT(add_, name) += [this](const char *remainder)
|
BOOST_PP_CAT(add_, name) += [this](const char *remainder)
|
||||||
|
|
||||||
void G13_Device::_init_commands() {
|
void Device::_init_commands() {
|
||||||
G13_DEVICE_COMMAND(out) {
|
G13_DEVICE_COMMAND(out) {
|
||||||
lcd().write_string(remainder);
|
lcd().write_string(remainder);
|
||||||
}
|
}
|
||||||
@ -477,10 +477,10 @@ void G13_Device::_init_commands() {
|
|||||||
advance_ws(remainder, zonename);
|
advance_ws(remainder, zonename);
|
||||||
|
|
||||||
if (operation != "add") {
|
if (operation != "add") {
|
||||||
G13_StickZone *zone = _stick.zone(zonename);
|
StickZone *zone = _stick.zone(zonename);
|
||||||
|
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
throw G13_CommandException("unknown stick zone");
|
throw CommandException("unknown stick zone");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation == "action") {
|
if (operation == "action") {
|
||||||
@ -489,10 +489,10 @@ void G13_Device::_init_commands() {
|
|||||||
double x1, y1, x2, y2;
|
double x1, y1, x2, y2;
|
||||||
|
|
||||||
if (sscanf(remainder, "%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != 4) {
|
if (sscanf(remainder, "%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != 4) {
|
||||||
throw G13_CommandException("bad bounds format");
|
throw CommandException("bad bounds format");
|
||||||
}
|
}
|
||||||
|
|
||||||
zone->set_bounds(G13_ZoneBounds(x1, y1, x2, y2));
|
zone->set_bounds(ZoneBounds(x1, y1, x2, y2));
|
||||||
} else if (operation == "del") {
|
} else if (operation == "del") {
|
||||||
_stick.remove_zone(*zone);
|
_stick.remove_zone(*zone);
|
||||||
} else {
|
} else {
|
||||||
@ -531,7 +531,7 @@ void G13_Device::_init_commands() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::command(char const *str) {
|
void Device::command(char const *str) {
|
||||||
const char *remainder = str;
|
const char *remainder = str;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -552,14 +552,14 @@ void G13_Device::command(char const *str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::init_lcd() {
|
void Device::init_lcd() {
|
||||||
int error = libusb_control_transfer(handle, 0, 9, 1, 0, 0, 0, 1000);
|
int error = libusb_control_transfer(handle, 0, 9, 1, 0, 0, 0, 1000);
|
||||||
if (error) {
|
if (error) {
|
||||||
G13_LOG(error, "Error when initializing lcd endpoint");
|
G13_LOG(error, "Error when initializing lcd endpoint");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::write_lcd(unsigned char *data, size_t size) {
|
void Device::write_lcd(unsigned char *data, size_t size) {
|
||||||
init_lcd();
|
init_lcd();
|
||||||
if (size != G13_LCD_BUFFER_SIZE) {
|
if (size != G13_LCD_BUFFER_SIZE) {
|
||||||
G13_LOG(error, "Invalid LCD data size " << size << ", should be "
|
G13_LOG(error, "Invalid LCD data size " << size << ", should be "
|
||||||
@ -579,7 +579,7 @@ void G13_Device::write_lcd(unsigned char *data, size_t size) {
|
|||||||
<< error << ", " << bytes_written << " bytes written");
|
<< error << ", " << bytes_written << " bytes written");
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::write_lcd_file(const std::string &filename) {
|
void Device::write_lcd_file(const std::string &filename) {
|
||||||
std::filebuf *pbuf;
|
std::filebuf *pbuf;
|
||||||
std::ifstream filestr;
|
std::ifstream filestr;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -598,7 +598,7 @@ void G13_Device::write_lcd_file(const std::string &filename) {
|
|||||||
write_lcd((unsigned char *)buffer, size);
|
write_lcd((unsigned char *)buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::parse_joystick(unsigned char *buf) {
|
void Device::parse_joystick(unsigned char *buf) {
|
||||||
_stick.parse_joystick(buf);
|
_stick.parse_joystick(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,16 +15,16 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_Manager;
|
class Manager;
|
||||||
|
|
||||||
class G13_Device {
|
class Device {
|
||||||
public:
|
public:
|
||||||
G13_Device(G13_Manager &manager, libusb_device_handle *handle, int id);
|
Device(Manager &manager, libusb_device_handle *handle, int id);
|
||||||
|
|
||||||
G13_Manager &manager() {
|
Manager &manager() {
|
||||||
return _manager;
|
return _manager;
|
||||||
}
|
}
|
||||||
const G13_Manager &manager() const {
|
const Manager &manager() const {
|
||||||
return _manager;
|
return _manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,10 +34,10 @@ class G13_Device {
|
|||||||
const G13_LCD &lcd() const {
|
const G13_LCD &lcd() const {
|
||||||
return _lcd;
|
return _lcd;
|
||||||
}
|
}
|
||||||
G13_Stick &stick() {
|
Stick &stick() {
|
||||||
return _stick;
|
return _stick;
|
||||||
}
|
}
|
||||||
const G13_Stick &stick() const {
|
const Stick &stick() const {
|
||||||
return _stick;
|
return _stick;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class G13_Device {
|
|||||||
int read_keys();
|
int read_keys();
|
||||||
void parse_joystick(unsigned char *buf);
|
void parse_joystick(unsigned char *buf);
|
||||||
|
|
||||||
G13_ActionPtr make_action(const std::string &);
|
ActionPtr make_action(const std::string &);
|
||||||
|
|
||||||
void set_key_color(int red, int green, int blue);
|
void set_key_color(int red, int green, int blue);
|
||||||
void set_mode_leds(int leds);
|
void set_mode_leds(int leds);
|
||||||
@ -67,15 +67,15 @@ class G13_Device {
|
|||||||
bool is_set(int key);
|
bool is_set(int key);
|
||||||
bool update(int key, bool v);
|
bool update(int key, bool v);
|
||||||
|
|
||||||
// used by G13_Manager
|
// used by Manager
|
||||||
void cleanup();
|
void cleanup();
|
||||||
void register_context(libusb_context *ctx);
|
void register_context(libusb_context *ctx);
|
||||||
void write_lcd_file(const std::string &filename);
|
void write_lcd_file(const std::string &filename);
|
||||||
|
|
||||||
G13_Font ¤t_font() {
|
Font ¤t_font() {
|
||||||
return *_current_font;
|
return *_current_font;
|
||||||
}
|
}
|
||||||
G13_Profile ¤t_profile() {
|
Profile ¤t_profile() {
|
||||||
return *_current_profile;
|
return *_current_profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class G13_Device {
|
|||||||
void init_lcd();
|
void init_lcd();
|
||||||
void _init_commands();
|
void _init_commands();
|
||||||
|
|
||||||
// typedef void (COMMAND_FUNCTION)( G13_Device*, const char *, const char * );
|
// typedef void (COMMAND_FUNCTION)( Device*, const char *, const char * );
|
||||||
CommandFunctionTable _command_table;
|
CommandFunctionTable _command_table;
|
||||||
|
|
||||||
struct timeval _event_time;
|
struct timeval _event_time;
|
||||||
@ -113,18 +113,18 @@ class G13_Device {
|
|||||||
std::map<std::string, ProfilePtr> _profiles;
|
std::map<std::string, ProfilePtr> _profiles;
|
||||||
ProfilePtr _current_profile;
|
ProfilePtr _current_profile;
|
||||||
|
|
||||||
G13_Manager &_manager;
|
Manager &_manager;
|
||||||
G13_LCD _lcd;
|
G13_LCD _lcd;
|
||||||
G13_Stick _stick;
|
Stick _stick;
|
||||||
|
|
||||||
bool keys[G13_NUM_KEYS];
|
bool keys[G13_NUM_KEYS];
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool G13_Device::is_set(int key) {
|
inline bool Device::is_set(int key) {
|
||||||
return keys[key];
|
return keys[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool G13_Device::update(int key, bool v) {
|
inline bool Device::update(int key, bool v) {
|
||||||
bool old = keys[key];
|
bool old = keys[key];
|
||||||
keys[key] = v;
|
keys[key] = v;
|
||||||
return old != v;
|
return old != v;
|
||||||
|
16
g13d/font.cc
16
g13d/font.cc
@ -8,15 +8,15 @@ namespace G13 {
|
|||||||
|
|
||||||
#include "font8x8.h"
|
#include "font8x8.h"
|
||||||
|
|
||||||
G13_Font::G13_Font() : _name("default"), _width(8) {
|
Font::Font() : _name("default"), _width(8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Font::G13_Font(const std::string &name, unsigned int width)
|
Font::Font(const std::string &name, unsigned int width)
|
||||||
: _name(name),
|
: _name(name),
|
||||||
_width(width) {
|
_width(width) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_FontChar::set_character(unsigned char *data, int width,
|
void FontChar::set_character(unsigned char *data, int width,
|
||||||
unsigned flags) {
|
unsigned flags) {
|
||||||
unsigned char *dest = bits_regular;
|
unsigned char *dest = bits_regular;
|
||||||
memset(dest, 0, CHAR_BUF_SIZE);
|
memset(dest, 0, CHAR_BUF_SIZE);
|
||||||
@ -45,19 +45,19 @@ int GetFontCharacterCount(T (&)[size]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class ARRAY_T, class FLAGST>
|
template <class ARRAY_T, class FLAGST>
|
||||||
void G13_Font::install_font(ARRAY_T &data, FLAGST flags, int first) {
|
void Font::install_font(ARRAY_T &data, FLAGST flags, int first) {
|
||||||
for (int i = 0; i < GetFontCharacterCount(data); i++) {
|
for (int i = 0; i < GetFontCharacterCount(data); i++) {
|
||||||
_chars[i + first].set_character(&data[i][0], _width, flags);
|
_chars[i + first].set_character(&data[i][0], _width, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Device::_init_fonts() {
|
void Device::_init_fonts() {
|
||||||
_current_font = FontPtr(new G13_Font("8x8", 8));
|
_current_font = FontPtr(new Font("8x8", 8));
|
||||||
_fonts[_current_font->name()] = _current_font;
|
_fonts[_current_font->name()] = _current_font;
|
||||||
|
|
||||||
_current_font->install_font(font8x8_basic, G13_FontChar::FF_ROTATE, 0);
|
_current_font->install_font(font8x8_basic, FontChar::FF_ROTATE, 0);
|
||||||
|
|
||||||
FontPtr fiveXeight(new G13_Font("5x8", 5));
|
FontPtr fiveXeight(new Font("5x8", 5));
|
||||||
fiveXeight->install_font(font5x8, 0, 32);
|
fiveXeight->install_font(font5x8, 0, 32);
|
||||||
_fonts[fiveXeight->name()] = fiveXeight;
|
_fonts[fiveXeight->name()] = fiveXeight;
|
||||||
}
|
}
|
||||||
|
16
g13d/font.h
16
g13d/font.h
@ -7,12 +7,12 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_FontChar {
|
class FontChar {
|
||||||
public:
|
public:
|
||||||
static const int CHAR_BUF_SIZE = 8;
|
static const int CHAR_BUF_SIZE = 8;
|
||||||
enum FONT_FLAGS { FF_ROTATE = 0x01 };
|
enum FONT_FLAGS { FF_ROTATE = 0x01 };
|
||||||
|
|
||||||
G13_FontChar() {
|
FontChar() {
|
||||||
memset(bits_regular, 0, CHAR_BUF_SIZE);
|
memset(bits_regular, 0, CHAR_BUF_SIZE);
|
||||||
memset(bits_inverted, 0, CHAR_BUF_SIZE);
|
memset(bits_inverted, 0, CHAR_BUF_SIZE);
|
||||||
}
|
}
|
||||||
@ -22,10 +22,10 @@ class G13_FontChar {
|
|||||||
unsigned char bits_inverted[CHAR_BUF_SIZE];
|
unsigned char bits_inverted[CHAR_BUF_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
class G13_Font {
|
class Font {
|
||||||
public:
|
public:
|
||||||
G13_Font();
|
Font();
|
||||||
G13_Font(const std::string &name, unsigned int width = 8);
|
Font(const std::string &name, unsigned int width = 8);
|
||||||
|
|
||||||
void set_character(unsigned int c, unsigned char *data);
|
void set_character(unsigned int c, unsigned char *data);
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class G13_Font {
|
|||||||
return _width;
|
return _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
const G13_FontChar &char_data(unsigned int x) {
|
const FontChar &char_data(unsigned int x) {
|
||||||
return _chars[x];
|
return _chars[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +47,10 @@ class G13_Font {
|
|||||||
std::string _name;
|
std::string _name;
|
||||||
unsigned int _width;
|
unsigned int _width;
|
||||||
|
|
||||||
G13_FontChar _chars[256];
|
FontChar _chars[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<G13_Font> FontPtr;
|
typedef std::shared_ptr<Font> FontPtr;
|
||||||
|
|
||||||
} // namespace G13
|
} // namespace G13
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ const LINUX_KEY_VALUE BAD_KEY_VALUE = -1;
|
|||||||
|
|
||||||
typedef int G13_KEY_INDEX;
|
typedef int G13_KEY_INDEX;
|
||||||
|
|
||||||
class G13_CommandException : public std::exception {
|
class CommandException : public std::exception {
|
||||||
public:
|
public:
|
||||||
G13_CommandException(const std::string &reason) : _reason(reason) {
|
CommandException(const std::string &reason) : _reason(reason) {
|
||||||
}
|
}
|
||||||
virtual ~G13_CommandException() throw() {
|
virtual ~CommandException() throw() {
|
||||||
}
|
}
|
||||||
virtual const char *what() const throw() {
|
virtual const char *what() const throw() {
|
||||||
return _reason.c_str();
|
return _reason.c_str();
|
||||||
|
@ -31,7 +31,7 @@ void G13_LCD::image(unsigned char *data, int size) {
|
|||||||
_keypad.write_lcd(data, size);
|
_keypad.write_lcd(data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_LCD::G13_LCD(G13_Device &keypad) : _keypad(keypad) {
|
G13_LCD::G13_LCD(Device &keypad) : _keypad(keypad) {
|
||||||
cursor_col = 0;
|
cursor_col = 0;
|
||||||
cursor_row = 0;
|
cursor_row = 0;
|
||||||
text_mode = 0;
|
text_mode = 0;
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_Device;
|
class Device;
|
||||||
|
|
||||||
class G13_LCD {
|
class G13_LCD {
|
||||||
public:
|
public:
|
||||||
G13_LCD(G13_Device &keypad);
|
G13_LCD(Device &keypad);
|
||||||
|
|
||||||
G13_Device &_keypad;
|
Device &_keypad;
|
||||||
unsigned char image_buf[G13_LCD_BUF_SIZE + 8];
|
unsigned char image_buf[G13_LCD_BUF_SIZE + 8];
|
||||||
unsigned cursor_row;
|
unsigned cursor_row;
|
||||||
unsigned cursor_col;
|
unsigned cursor_col;
|
||||||
|
@ -10,7 +10,7 @@ namespace po = boost::program_options;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
G13::G13_Manager manager;
|
G13::Manager manager;
|
||||||
manager.set_log_level("info");
|
manager.set_log_level("info");
|
||||||
|
|
||||||
// Declare the supported options.
|
// Declare the supported options.
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
void G13_Manager::discover_g13s(libusb_device **devs, ssize_t count,
|
void Manager::discover_g13s(libusb_device **devs, ssize_t count,
|
||||||
std::vector<G13_Device *> &g13s) {
|
std::vector<Device *> &g13s) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
libusb_device_descriptor desc;
|
libusb_device_descriptor desc;
|
||||||
int r = libusb_get_device_descriptor(devs[i], &desc);
|
int r = libusb_get_device_descriptor(devs[i], &desc);
|
||||||
@ -50,17 +50,17 @@ void G13_Manager::discover_g13s(libusb_device **devs, ssize_t count,
|
|||||||
G13_LOG(error, "Cannot Claim Interface");
|
G13_LOG(error, "Cannot Claim Interface");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g13s.push_back(new G13_Device(*this, handle, g13s.size()));
|
g13s.push_back(new Device(*this, handle, g13s.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::set_log_level(::boost::log::trivial::severity_level lvl) {
|
void Manager::set_log_level(::boost::log::trivial::severity_level lvl) {
|
||||||
boost::log::core::get()->set_filter(::boost::log::trivial::severity >= lvl);
|
boost::log::core::get()->set_filter(::boost::log::trivial::severity >= lvl);
|
||||||
G13_OUT("set log level to " << lvl);
|
G13_OUT("set log level to " << lvl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::set_log_level(const std::string &level) {
|
void Manager::set_log_level(const std::string &level) {
|
||||||
#define CHECK_LEVEL(L) \
|
#define CHECK_LEVEL(L) \
|
||||||
if (level == BOOST_PP_STRINGIZE(L)) { \
|
if (level == BOOST_PP_STRINGIZE(L)) { \
|
||||||
set_log_level(::boost::log::trivial::L); \
|
set_log_level(::boost::log::trivial::L); \
|
||||||
@ -77,7 +77,7 @@ void G13_Manager::set_log_level(const std::string &level) {
|
|||||||
G13_LOG(error, "unknown log level" << level);
|
G13_LOG(error, "unknown log level" << level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::cleanup() {
|
void Manager::cleanup() {
|
||||||
G13_LOG(info, "cleaning up");
|
G13_LOG(info, "cleaning up");
|
||||||
|
|
||||||
for (auto device : g13s) {
|
for (auto device : g13s) {
|
||||||
@ -88,15 +88,15 @@ void G13_Manager::cleanup() {
|
|||||||
libusb_exit(ctx);
|
libusb_exit(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Manager::G13_Manager() : devs(0), ctx(0) {
|
Manager::Manager() : devs(0), ctx(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool G13_Manager::running = true;
|
bool Manager::running = true;
|
||||||
void G13_Manager::set_stop(int) {
|
void Manager::set_stop(int) {
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string G13_Manager::string_config_value(const std::string &name) const {
|
std::string Manager::string_config_value(const std::string &name) const {
|
||||||
try {
|
try {
|
||||||
return find_or_throw(_string_config_values, name);
|
return find_or_throw(_string_config_values, name);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -104,7 +104,7 @@ std::string G13_Manager::string_config_value(const std::string &name) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::set_string_config_value(const std::string &name,
|
void Manager::set_string_config_value(const std::string &name,
|
||||||
const std::string &value) {
|
const std::string &value) {
|
||||||
G13_LOG(info, "set_string_config_value " << name << " = " << repr(value));
|
G13_LOG(info, "set_string_config_value " << name << " = " << repr(value));
|
||||||
_string_config_values[name] = value;
|
_string_config_values[name] = value;
|
||||||
@ -112,7 +112,7 @@ void G13_Manager::set_string_config_value(const std::string &name,
|
|||||||
|
|
||||||
#define CONTROL_DIR std::string("/tmp/")
|
#define CONTROL_DIR std::string("/tmp/")
|
||||||
|
|
||||||
std::string G13_Manager::make_pipe_name(G13_Device *d, bool is_input) {
|
std::string Manager::make_pipe_name(Device *d, bool is_input) {
|
||||||
if (is_input) {
|
if (is_input) {
|
||||||
std::string config_base = string_config_value("pipe_in");
|
std::string config_base = string_config_value("pipe_in");
|
||||||
if (config_base.size()) {
|
if (config_base.size()) {
|
||||||
@ -141,7 +141,7 @@ std::string G13_Manager::make_pipe_name(G13_Device *d, bool is_input) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int G13_Manager::run() {
|
int Manager::run() {
|
||||||
init_keynames();
|
init_keynames();
|
||||||
display_keys();
|
display_keys();
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ int G13_Manager::run() {
|
|||||||
input_name_to_key[name] = keyval; \
|
input_name_to_key[name] = keyval; \
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::init_keynames() {
|
void Manager::init_keynames() {
|
||||||
int key_index = 0;
|
int key_index = 0;
|
||||||
|
|
||||||
BOOST_PP_SEQ_FOR_EACH(ADD_G13_KEY_MAPPING, _, G13_KEY_SEQ);
|
BOOST_PP_SEQ_FOR_EACH(ADD_G13_KEY_MAPPING, _, G13_KEY_SEQ);
|
||||||
@ -230,7 +230,7 @@ void G13_Manager::init_keynames() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LINUX_KEY_VALUE
|
LINUX_KEY_VALUE
|
||||||
G13_Manager::find_g13_key_value(const std::string &keyname) const {
|
Manager::find_g13_key_value(const std::string &keyname) const {
|
||||||
auto i = g13_name_to_key.find(keyname);
|
auto i = g13_name_to_key.find(keyname);
|
||||||
if (i == g13_name_to_key.end()) {
|
if (i == g13_name_to_key.end()) {
|
||||||
return BAD_KEY_VALUE;
|
return BAD_KEY_VALUE;
|
||||||
@ -239,7 +239,7 @@ G13_Manager::find_g13_key_value(const std::string &keyname) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LINUX_KEY_VALUE
|
LINUX_KEY_VALUE
|
||||||
G13_Manager::find_input_key_value(const std::string &keyname) const {
|
Manager::find_input_key_value(const std::string &keyname) const {
|
||||||
// if there is a KEY_ prefix, strip it off
|
// if there is a KEY_ prefix, strip it off
|
||||||
if (!strncmp(keyname.c_str(), "KEY_", 4)) {
|
if (!strncmp(keyname.c_str(), "KEY_", 4)) {
|
||||||
return find_input_key_value(keyname.c_str() + 4);
|
return find_input_key_value(keyname.c_str() + 4);
|
||||||
@ -252,7 +252,7 @@ G13_Manager::find_input_key_value(const std::string &keyname) const {
|
|||||||
return i->second;
|
return i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string G13_Manager::find_input_key_name(LINUX_KEY_VALUE v) const {
|
std::string Manager::find_input_key_name(LINUX_KEY_VALUE v) const {
|
||||||
try {
|
try {
|
||||||
return find_or_throw(input_key_to_name, v);
|
return find_or_throw(input_key_to_name, v);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -260,7 +260,7 @@ std::string G13_Manager::find_input_key_name(LINUX_KEY_VALUE v) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string G13_Manager::find_g13_key_name(G13_KEY_INDEX v) const {
|
std::string Manager::find_g13_key_name(G13_KEY_INDEX v) const {
|
||||||
try {
|
try {
|
||||||
return find_or_throw(g13_key_to_name, v);
|
return find_or_throw(g13_key_to_name, v);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -268,7 +268,7 @@ std::string G13_Manager::find_g13_key_name(G13_KEY_INDEX v) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Manager::display_keys() {
|
void Manager::display_keys() {
|
||||||
G13_OUT("Known keys on G13:");
|
G13_OUT("Known keys on G13:");
|
||||||
G13_OUT(Helper::map_keys_out(g13_name_to_key));
|
G13_OUT(Helper::map_keys_out(g13_name_to_key));
|
||||||
|
|
||||||
|
@ -13,9 +13,9 @@ namespace G13 {
|
|||||||
/*!
|
/*!
|
||||||
* top level class, holds what would otherwise be in global variables
|
* top level class, holds what would otherwise be in global variables
|
||||||
*/
|
*/
|
||||||
class G13_Manager {
|
class Manager {
|
||||||
public:
|
public:
|
||||||
G13_Manager();
|
Manager();
|
||||||
|
|
||||||
G13_KEY_INDEX find_g13_key_value(const std::string &keyname) const;
|
G13_KEY_INDEX find_g13_key_value(const std::string &keyname) const;
|
||||||
std::string find_g13_key_name(G13_KEY_INDEX) const;
|
std::string find_g13_key_name(G13_KEY_INDEX) const;
|
||||||
@ -31,7 +31,7 @@ class G13_Manager {
|
|||||||
std::string string_config_value(const std::string &name) const;
|
std::string string_config_value(const std::string &name) const;
|
||||||
void set_string_config_value(const std::string &name, const std::string &val);
|
void set_string_config_value(const std::string &name, const std::string &val);
|
||||||
|
|
||||||
std::string make_pipe_name(G13_Device *d, bool is_input);
|
std::string make_pipe_name(Device *d, bool is_input);
|
||||||
|
|
||||||
void set_log_level(::boost::log::trivial::severity_level lvl);
|
void set_log_level(::boost::log::trivial::severity_level lvl);
|
||||||
void set_log_level(const std::string &);
|
void set_log_level(const std::string &);
|
||||||
@ -40,14 +40,14 @@ class G13_Manager {
|
|||||||
void init_keynames();
|
void init_keynames();
|
||||||
void display_keys();
|
void display_keys();
|
||||||
void discover_g13s(libusb_device **devs, ssize_t count,
|
void discover_g13s(libusb_device **devs, ssize_t count,
|
||||||
std::vector<G13_Device *> &g13s);
|
std::vector<Device *> &g13s);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
std::string logo_filename;
|
std::string logo_filename;
|
||||||
libusb_device **devs;
|
libusb_device **devs;
|
||||||
|
|
||||||
libusb_context *ctx;
|
libusb_context *ctx;
|
||||||
std::vector<G13_Device *> g13s;
|
std::vector<Device *> g13s;
|
||||||
|
|
||||||
std::map<G13_KEY_INDEX, std::string> g13_key_to_name;
|
std::map<G13_KEY_INDEX, std::string> g13_key_to_name;
|
||||||
std::map<std::string, G13_KEY_INDEX> g13_name_to_key;
|
std::map<std::string, G13_KEY_INDEX> g13_name_to_key;
|
||||||
@ -64,15 +64,15 @@ class G13_Manager {
|
|||||||
|
|
||||||
// inlines
|
// inlines
|
||||||
|
|
||||||
inline G13_Manager &G13_Action::manager() {
|
inline Manager &Action::manager() {
|
||||||
return _keypad.manager();
|
return _keypad.manager();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const G13_Manager &G13_Action::manager() const {
|
inline const Manager &Action::manager() const {
|
||||||
return _keypad.manager();
|
return _keypad.manager();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const G13_Manager &G13_Profile::manager() const {
|
inline const Manager &Profile::manager() const {
|
||||||
return _keypad.manager();
|
return _keypad.manager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
namespace G13 {
|
namespace G13 {
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
|
|
||||||
void G13_Key::dump(std::ostream &o) const {
|
void Key::dump(std::ostream &o) const {
|
||||||
o << manager().find_g13_key_name(index()) << "(" << index() << ") : ";
|
o << manager().find_g13_key_name(index()) << "(" << index() << ") : ";
|
||||||
|
|
||||||
if (action()) {
|
if (action()) {
|
||||||
@ -25,7 +25,7 @@ void G13_Key::dump(std::ostream &o) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Key::parse_key(unsigned char *byte, G13_Device *g13) {
|
void Key::parse_key(unsigned char *byte, Device *g13) {
|
||||||
bool key_is_down = byte[_index.offset] & _index.mask;
|
bool key_is_down = byte[_index.offset] & _index.mask;
|
||||||
bool key_state_changed = g13->update(_index.index, key_is_down);
|
bool key_state_changed = g13->update(_index.index, key_is_down);
|
||||||
|
|
||||||
@ -34,13 +34,13 @@ void G13_Key::parse_key(unsigned char *byte, G13_Device *g13) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Profile::_init_keys() {
|
void Profile::_init_keys() {
|
||||||
int key_index = 0;
|
int key_index = 0;
|
||||||
|
|
||||||
// create a G13_Key entry for every key in G13_KEY_SEQ
|
// create a Key entry for every key in G13_KEY_SEQ
|
||||||
#define INIT_KEY(r, data, elem) \
|
#define INIT_KEY(r, data, elem) \
|
||||||
{ \
|
{ \
|
||||||
G13_Key key(*this, BOOST_PP_STRINGIZE(elem), key_index++); \
|
Key key(*this, BOOST_PP_STRINGIZE(elem), key_index++); \
|
||||||
_keys.push_back(key); \
|
_keys.push_back(key); \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ void G13_Profile::_init_keys() {
|
|||||||
// now disable testing for keys in G13_NONPARSED_KEY_SEQ
|
// now disable testing for keys in G13_NONPARSED_KEY_SEQ
|
||||||
#define MARK_NON_PARSED_KEY(r, data, elem) \
|
#define MARK_NON_PARSED_KEY(r, data, elem) \
|
||||||
{ \
|
{ \
|
||||||
G13_Key *key = find_key(BOOST_PP_STRINGIZE(elem)); \
|
Key *key = find_key(BOOST_PP_STRINGIZE(elem)); \
|
||||||
assert(key); \
|
assert(key); \
|
||||||
key->_should_parse = false; \
|
key->_should_parse = false; \
|
||||||
}
|
}
|
||||||
@ -59,9 +59,9 @@ void G13_Profile::_init_keys() {
|
|||||||
BOOST_PP_SEQ_FOR_EACH(MARK_NON_PARSED_KEY, _, G13_NONPARSED_KEY_SEQ)
|
BOOST_PP_SEQ_FOR_EACH(MARK_NON_PARSED_KEY, _, G13_NONPARSED_KEY_SEQ)
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Profile::dump(std::ostream &o) const {
|
void Profile::dump(std::ostream &o) const {
|
||||||
o << "Profile " << repr(name()) << std::endl;
|
o << "Profile " << repr(name()) << std::endl;
|
||||||
BOOST_FOREACH (const G13_Key &key, _keys) {
|
BOOST_FOREACH (const Key &key, _keys) {
|
||||||
if (key.action()) {
|
if (key.action()) {
|
||||||
o << " ";
|
o << " ";
|
||||||
key.dump(o);
|
key.dump(o);
|
||||||
@ -69,7 +69,7 @@ void G13_Profile::dump(std::ostream &o) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void G13_Profile::parse_keys(unsigned char *buf) {
|
void Profile::parse_keys(unsigned char *buf) {
|
||||||
buf += 3;
|
buf += 3;
|
||||||
for (size_t i = 0; i < _keys.size(); i++) {
|
for (size_t i = 0; i < _keys.size(); i++) {
|
||||||
if (_keys[i]._should_parse) {
|
if (_keys[i]._should_parse) {
|
||||||
@ -78,7 +78,7 @@ void G13_Profile::parse_keys(unsigned char *buf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Key *G13_Profile::find_key(const std::string &keyname) {
|
Key *Profile::find_key(const std::string &keyname) {
|
||||||
auto key = _keypad.manager().find_g13_key_value(keyname);
|
auto key = _keypad.manager().find_g13_key_value(keyname);
|
||||||
|
|
||||||
// TODO(jtgans): Check this is the proper type
|
// TODO(jtgans): Check this is the proper type
|
||||||
|
@ -42,21 +42,21 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_Device;
|
class Device;
|
||||||
class G13_Key;
|
class Key;
|
||||||
class G13_Profile;
|
class Profile;
|
||||||
|
|
||||||
/*! manages the bindings for a G13 key
|
/*! manages the bindings for a G13 key
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class G13_Key : public G13_Actionable<G13_Profile> {
|
class Key : public Actionable<Profile> {
|
||||||
public:
|
public:
|
||||||
void dump(std::ostream &o) const;
|
void dump(std::ostream &o) const;
|
||||||
G13_KEY_INDEX index() const {
|
G13_KEY_INDEX index() const {
|
||||||
return _index.index;
|
return _index.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_key(unsigned char *byte, G13_Device *g13);
|
void parse_key(unsigned char *byte, Device *g13);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct KeyIndex {
|
struct KeyIndex {
|
||||||
@ -68,17 +68,17 @@ class G13_Key : public G13_Actionable<G13_Profile> {
|
|||||||
unsigned char mask;
|
unsigned char mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
// G13_Profile is the only class able to instantiate G13_Keys
|
// Profile is the only class able to instantiate Keys
|
||||||
friend class G13_Profile;
|
friend class Profile;
|
||||||
|
|
||||||
G13_Key(G13_Profile &mode, const std::string &name, int index)
|
Key(Profile &mode, const std::string &name, int index)
|
||||||
: G13_Actionable<G13_Profile>(mode, name),
|
: Actionable<Profile>(mode, name),
|
||||||
_index(index),
|
_index(index),
|
||||||
_should_parse(true) {
|
_should_parse(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Key(G13_Profile &mode, const G13_Key &key)
|
Key(Profile &mode, const Key &key)
|
||||||
: G13_Actionable<G13_Profile>(mode, key.name()),
|
: Actionable<Profile>(mode, key.name()),
|
||||||
_index(key._index),
|
_index(key._index),
|
||||||
_should_parse(key._should_parse) {
|
_should_parse(key._should_parse) {
|
||||||
set_action(key.action());
|
set_action(key.action());
|
||||||
@ -94,22 +94,22 @@ class G13_Key : public G13_Actionable<G13_Profile> {
|
|||||||
* This allows a keypad to have multiple configured
|
* This allows a keypad to have multiple configured
|
||||||
* profiles and switch between them easily
|
* profiles and switch between them easily
|
||||||
*/
|
*/
|
||||||
class G13_Profile {
|
class Profile {
|
||||||
public:
|
public:
|
||||||
G13_Profile(G13_Device &keypad, const std::string &name_arg)
|
Profile(Device &keypad, const std::string &name_arg)
|
||||||
: _keypad(keypad),
|
: _keypad(keypad),
|
||||||
_name(name_arg) {
|
_name(name_arg) {
|
||||||
_init_keys();
|
_init_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_Profile(const G13_Profile &other, const std::string &name_arg)
|
Profile(const Profile &other, const std::string &name_arg)
|
||||||
: _keypad(other._keypad),
|
: _keypad(other._keypad),
|
||||||
_name(name_arg),
|
_name(name_arg),
|
||||||
_keys(other._keys) {
|
_keys(other._keys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// search key by G13 keyname
|
// search key by G13 keyname
|
||||||
G13_Key *find_key(const std::string &keyname);
|
Key *find_key(const std::string &keyname);
|
||||||
|
|
||||||
void dump(std::ostream &o) const;
|
void dump(std::ostream &o) const;
|
||||||
|
|
||||||
@ -118,17 +118,17 @@ class G13_Profile {
|
|||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const G13_Manager &manager() const;
|
const Manager &manager() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
G13_Device &_keypad;
|
Device &_keypad;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::vector<G13_Key> _keys;
|
std::vector<Key> _keys;
|
||||||
|
|
||||||
void _init_keys();
|
void _init_keys();
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<G13_Profile> ProfilePtr;
|
typedef std::shared_ptr<Profile> ProfilePtr;
|
||||||
|
|
||||||
} // namespace G13
|
} // namespace G13
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
G13_Stick::G13_Stick(G13_Device &keypad)
|
Stick::Stick(Device &keypad)
|
||||||
: _keypad(keypad),
|
: _keypad(keypad),
|
||||||
_bounds(0, 0, 255, 255),
|
_bounds(0, 0, 255, 255),
|
||||||
_center_pos(127, 127),
|
_center_pos(127, 127),
|
||||||
@ -19,9 +19,9 @@ G13_Stick::G13_Stick(G13_Device &keypad)
|
|||||||
|
|
||||||
auto add_zone = [this, &keypad](const std::string &name, double x1, double y1,
|
auto add_zone = [this, &keypad](const std::string &name, double x1, double y1,
|
||||||
double x2, double y2) {
|
double x2, double y2) {
|
||||||
_zones.push_back(G13_StickZone(
|
_zones.push_back(StickZone(
|
||||||
*this, "STICK_" + name, G13_ZoneBounds(x1, y1, x2, y2),
|
*this, "STICK_" + name, ZoneBounds(x1, y1, x2, y2),
|
||||||
G13_ActionPtr(new G13_Action_Keys(keypad, "KEY_" + name))));
|
ActionPtr(new Action_Keys(keypad, "KEY_" + name))));
|
||||||
};
|
};
|
||||||
|
|
||||||
add_zone("UP", 0.0, 0.1, 1.0, 0.3);
|
add_zone("UP", 0.0, 0.1, 1.0, 0.3);
|
||||||
@ -32,8 +32,8 @@ G13_Stick::G13_Stick(G13_Device &keypad)
|
|||||||
add_zone("PAGEDOWN", 0.0, 0.9, 1.0, 1.0);
|
add_zone("PAGEDOWN", 0.0, 0.9, 1.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_StickZone *G13_Stick::zone(const std::string &name, bool create) {
|
StickZone *Stick::zone(const std::string &name, bool create) {
|
||||||
BOOST_FOREACH (G13_StickZone &zone, _zones) {
|
BOOST_FOREACH (StickZone &zone, _zones) {
|
||||||
if (zone.name() == name) {
|
if (zone.name() == name) {
|
||||||
return &zone;
|
return &zone;
|
||||||
}
|
}
|
||||||
@ -41,14 +41,14 @@ G13_StickZone *G13_Stick::zone(const std::string &name, bool create) {
|
|||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
_zones.push_back(
|
_zones.push_back(
|
||||||
G13_StickZone(*this, name, G13_ZoneBounds(0.0, 0.0, 0.0, 0.0)));
|
StickZone(*this, name, ZoneBounds(0.0, 0.0, 0.0, 0.0)));
|
||||||
return zone(name);
|
return zone(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Stick::set_mode(stick_mode_t m) {
|
void Stick::set_mode(stick_mode_t m) {
|
||||||
if (m == _stick_mode) {
|
if (m == _stick_mode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -61,27 +61,27 @@ void G13_Stick::set_mode(stick_mode_t m) {
|
|||||||
_stick_mode = m;
|
_stick_mode = m;
|
||||||
|
|
||||||
if (_stick_mode == STICK_CALBOUNDS) {
|
if (_stick_mode == STICK_CALBOUNDS) {
|
||||||
_bounds.tl = G13_StickCoord(255, 255);
|
_bounds.tl = StickCoord(255, 255);
|
||||||
_bounds.br = G13_StickCoord(0, 0);
|
_bounds.br = StickCoord(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Stick::_recalc_calibrated() {
|
void Stick::_recalc_calibrated() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Stick::remove_zone(const G13_StickZone &zone) {
|
void Stick::remove_zone(const StickZone &zone) {
|
||||||
G13_StickZone target(zone);
|
StickZone target(zone);
|
||||||
_zones.erase(std::remove(_zones.begin(), _zones.end(), target), _zones.end());
|
_zones.erase(std::remove(_zones.begin(), _zones.end(), target), _zones.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Stick::dump(std::ostream &out) const {
|
void Stick::dump(std::ostream &out) const {
|
||||||
BOOST_FOREACH (const G13_StickZone &zone, _zones) {
|
BOOST_FOREACH (const StickZone &zone, _zones) {
|
||||||
zone.dump(out);
|
zone.dump(out);
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_StickZone::dump(std::ostream &out) const {
|
void StickZone::dump(std::ostream &out) const {
|
||||||
out << " " << std::setw(20) << name() << " " << _bounds << " ";
|
out << " " << std::setw(20) << name() << " " << _bounds << " ";
|
||||||
|
|
||||||
if (action()) {
|
if (action()) {
|
||||||
@ -91,7 +91,7 @@ void G13_StickZone::dump(std::ostream &out) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_StickZone::test(const G13_ZoneCoord &loc) {
|
void StickZone::test(const ZoneCoord &loc) {
|
||||||
if (!_action) return;
|
if (!_action) return;
|
||||||
|
|
||||||
bool prior_active = _active;
|
bool prior_active = _active;
|
||||||
@ -104,15 +104,15 @@ void G13_StickZone::test(const G13_ZoneCoord &loc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
G13_StickZone::G13_StickZone(G13_Stick &stick, const std::string &name,
|
StickZone::StickZone(Stick &stick, const std::string &name,
|
||||||
const G13_ZoneBounds &b, G13_ActionPtr action)
|
const ZoneBounds &b, ActionPtr action)
|
||||||
: G13_Actionable<G13_Stick>(stick, name),
|
: Actionable<Stick>(stick, name),
|
||||||
_active(false),
|
_active(false),
|
||||||
_bounds(b) {
|
_bounds(b) {
|
||||||
set_action(action);
|
set_action(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
void G13_Stick::parse_joystick(unsigned char *buf) {
|
void Stick::parse_joystick(unsigned char *buf) {
|
||||||
_current_pos.x = buf[1];
|
_current_pos.x = buf[1];
|
||||||
_current_pos.y = buf[2];
|
_current_pos.y = buf[2];
|
||||||
|
|
||||||
@ -158,12 +158,12 @@ void G13_Stick::parse_joystick(unsigned char *buf) {
|
|||||||
G13_LOG(trace, "x=" << _current_pos.x << " y=" << _current_pos.y
|
G13_LOG(trace, "x=" << _current_pos.x << " y=" << _current_pos.y
|
||||||
<< " dx=" << dx << " dy=" << dy);
|
<< " dx=" << dx << " dy=" << dy);
|
||||||
|
|
||||||
G13_ZoneCoord jpos(dx, dy);
|
ZoneCoord jpos(dx, dy);
|
||||||
if (_stick_mode == STICK_ABSOLUTE) {
|
if (_stick_mode == STICK_ABSOLUTE) {
|
||||||
_keypad.send_event(EV_ABS, ABS_X, _current_pos.x);
|
_keypad.send_event(EV_ABS, ABS_X, _current_pos.x);
|
||||||
_keypad.send_event(EV_ABS, ABS_Y, _current_pos.y);
|
_keypad.send_event(EV_ABS, ABS_Y, _current_pos.y);
|
||||||
} else if (_stick_mode == STICK_KEYS) {
|
} else if (_stick_mode == STICK_KEYS) {
|
||||||
BOOST_FOREACH (G13_StickZone &zone, _zones) { zone.test(jpos); }
|
BOOST_FOREACH (StickZone &zone, _zones) { zone.test(jpos); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
50
g13d/stick.h
50
g13d/stick.h
@ -7,48 +7,48 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
class G13_Stick;
|
class Stick;
|
||||||
|
|
||||||
typedef Coord<int> G13_StickCoord;
|
typedef Coord<int> StickCoord;
|
||||||
typedef Bounds<int> G13_StickBounds;
|
typedef Bounds<int> StickBounds;
|
||||||
typedef Coord<double> G13_ZoneCoord;
|
typedef Coord<double> ZoneCoord;
|
||||||
typedef Bounds<double> G13_ZoneBounds;
|
typedef Bounds<double> ZoneBounds;
|
||||||
|
|
||||||
class G13_StickZone : public G13_Actionable<G13_Stick> {
|
class StickZone : public Actionable<Stick> {
|
||||||
public:
|
public:
|
||||||
G13_StickZone(G13_Stick &, const std::string &name, const G13_ZoneBounds &,
|
StickZone(Stick &, const std::string &name, const ZoneBounds &,
|
||||||
G13_ActionPtr = 0);
|
ActionPtr = 0);
|
||||||
|
|
||||||
bool operator==(const G13_StickZone &other) const {
|
bool operator==(const StickZone &other) const {
|
||||||
return _name == other._name;
|
return _name == other._name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump(std::ostream &) const;
|
void dump(std::ostream &) const;
|
||||||
|
|
||||||
void parse_key(unsigned char *byte, G13_Device *g13);
|
void parse_key(unsigned char *byte, Device *g13);
|
||||||
void test(const G13_ZoneCoord &loc);
|
void test(const ZoneCoord &loc);
|
||||||
void set_bounds(const G13_ZoneBounds &bounds) {
|
void set_bounds(const ZoneBounds &bounds) {
|
||||||
_bounds = bounds;
|
_bounds = bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _active;
|
bool _active;
|
||||||
G13_ZoneBounds _bounds;
|
ZoneBounds _bounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::shared_ptr<G13_StickZone> G13_StickZonePtr;
|
typedef boost::shared_ptr<StickZone> StickZonePtr;
|
||||||
|
|
||||||
class G13_Stick {
|
class Stick {
|
||||||
public:
|
public:
|
||||||
G13_Stick(G13_Device &keypad);
|
Stick(Device &keypad);
|
||||||
|
|
||||||
void parse_joystick(unsigned char *buf);
|
void parse_joystick(unsigned char *buf);
|
||||||
|
|
||||||
void set_mode(stick_mode_t);
|
void set_mode(stick_mode_t);
|
||||||
G13_StickZone *zone(const std::string &, bool create = false);
|
StickZone *zone(const std::string &, bool create = false);
|
||||||
void remove_zone(const G13_StickZone &zone);
|
void remove_zone(const StickZone &zone);
|
||||||
|
|
||||||
const std::vector<G13_StickZone> &zones() const {
|
const std::vector<StickZone> &zones() const {
|
||||||
return _zones;
|
return _zones;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,14 +57,14 @@ class G13_Stick {
|
|||||||
protected:
|
protected:
|
||||||
void _recalc_calibrated();
|
void _recalc_calibrated();
|
||||||
|
|
||||||
G13_Device &_keypad;
|
Device &_keypad;
|
||||||
std::vector<G13_StickZone> _zones;
|
std::vector<StickZone> _zones;
|
||||||
|
|
||||||
G13_StickBounds _bounds;
|
StickBounds _bounds;
|
||||||
G13_StickCoord _center_pos;
|
StickCoord _center_pos;
|
||||||
G13_StickCoord _north_pos;
|
StickCoord _north_pos;
|
||||||
|
|
||||||
G13_StickCoord _current_pos;
|
StickCoord _current_pos;
|
||||||
|
|
||||||
stick_mode_t _stick_mode;
|
stick_mode_t _stick_mode;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user