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 {
|
||||
|
||||
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)
|
||||
: G13_Action(keypad) {
|
||||
: Action(keypad) {
|
||||
std::vector<std::string> keys;
|
||||
boost::split(keys, keys_string, boost::is_any_of("+"));
|
||||
|
||||
BOOST_FOREACH (std::string const &key, keys) {
|
||||
auto kval = manager().find_input_key_value(key);
|
||||
if (kval == BAD_KEY_VALUE) {
|
||||
throw G13_CommandException("create action unknown key : " + key);
|
||||
throw CommandException("create action unknown key : " + key);
|
||||
}
|
||||
_keys.push_back(kval);
|
||||
}
|
||||
@ -31,17 +31,17 @@ G13_Action_Keys::G13_Action_Keys(G13_Device &keypad,
|
||||
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) {
|
||||
g13.send_event(EV_KEY, key, is_down);
|
||||
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: ";
|
||||
|
||||
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)
|
||||
: G13_Action(keypad),
|
||||
: Action(keypad),
|
||||
_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) {
|
||||
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);
|
||||
}
|
||||
|
||||
G13_Action_Command::G13_Action_Command(G13_Device &keypad,
|
||||
Action_Command::Action_Command(Device &keypad,
|
||||
const std::string &cmd)
|
||||
: G13_Action(keypad),
|
||||
: Action(keypad),
|
||||
_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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -9,49 +9,49 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_Device;
|
||||
class G13_Manager;
|
||||
class Device;
|
||||
class Manager;
|
||||
|
||||
/*! holds potential actions which can be bound to G13 activity
|
||||
*
|
||||
*/
|
||||
class G13_Action {
|
||||
class Action {
|
||||
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;
|
||||
|
||||
void act(bool is_down) {
|
||||
act(keypad(), is_down);
|
||||
}
|
||||
|
||||
G13_Device &keypad() {
|
||||
Device &keypad() {
|
||||
return _keypad;
|
||||
}
|
||||
const G13_Device &keypad() const {
|
||||
const Device &keypad() const {
|
||||
return _keypad;
|
||||
}
|
||||
|
||||
G13_Manager &manager();
|
||||
const G13_Manager &manager() const;
|
||||
Manager &manager();
|
||||
const Manager &manager() const;
|
||||
|
||||
private:
|
||||
G13_Device &_keypad;
|
||||
Device &_keypad;
|
||||
};
|
||||
|
||||
/*!
|
||||
* action to send one or more keystrokes
|
||||
*/
|
||||
class G13_Action_Keys : public G13_Action {
|
||||
class Action_Keys : public Action {
|
||||
public:
|
||||
G13_Action_Keys(G13_Device &keypad, const std::string &keys);
|
||||
virtual ~G13_Action_Keys();
|
||||
Action_Keys(Device &keypad, const std::string &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;
|
||||
|
||||
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
|
||||
*/
|
||||
class G13_Action_PipeOut : public G13_Action {
|
||||
class Action_PipeOut : public Action {
|
||||
public:
|
||||
G13_Action_PipeOut(G13_Device &keypad, const std::string &out);
|
||||
virtual ~G13_Action_PipeOut();
|
||||
Action_PipeOut(Device &keypad, const std::string &out);
|
||||
virtual ~Action_PipeOut();
|
||||
|
||||
virtual void act(G13_Device &, bool is_down);
|
||||
virtual void act(Device &, bool is_down);
|
||||
virtual void dump(std::ostream &) const;
|
||||
|
||||
std::string _out;
|
||||
@ -74,32 +74,32 @@ class G13_Action_PipeOut : public G13_Action {
|
||||
/*!
|
||||
* action to send a command to the g13
|
||||
*/
|
||||
class G13_Action_Command : public G13_Action {
|
||||
class Action_Command : public Action {
|
||||
public:
|
||||
G13_Action_Command(G13_Device &keypad, const std::string &cmd);
|
||||
virtual ~G13_Action_Command();
|
||||
Action_Command(Device &keypad, const std::string &cmd);
|
||||
virtual ~Action_Command();
|
||||
|
||||
virtual void act(G13_Device &, bool is_down);
|
||||
virtual void act(Device &, bool is_down);
|
||||
virtual void dump(std::ostream &) const;
|
||||
|
||||
std::string _cmd;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<G13_Action> G13_ActionPtr;
|
||||
typedef std::shared_ptr<Action> ActionPtr;
|
||||
|
||||
template <class PARENT_T>
|
||||
class G13_Actionable {
|
||||
class Actionable {
|
||||
public:
|
||||
G13_Actionable(PARENT_T &parent_arg, const std::string &name)
|
||||
Actionable(PARENT_T &parent_arg, const std::string &name)
|
||||
: _name(name),
|
||||
_parent_ptr(&parent_arg) {
|
||||
}
|
||||
|
||||
virtual ~G13_Actionable() {
|
||||
virtual ~Actionable() {
|
||||
_parent_ptr = 0;
|
||||
}
|
||||
|
||||
G13_ActionPtr action() const {
|
||||
ActionPtr action() const {
|
||||
return _action;
|
||||
}
|
||||
const std::string &name() const {
|
||||
@ -111,20 +111,20 @@ class G13_Actionable {
|
||||
const PARENT_T &parent() const {
|
||||
return *_parent_ptr;
|
||||
}
|
||||
G13_Manager &manager() {
|
||||
Manager &manager() {
|
||||
return _parent_ptr->manager();
|
||||
}
|
||||
const G13_Manager &manager() const {
|
||||
const Manager &manager() const {
|
||||
return _parent_ptr->manager();
|
||||
}
|
||||
|
||||
virtual void set_action(const G13_ActionPtr &action) {
|
||||
virtual void set_action(const ActionPtr &action) {
|
||||
_action = action;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string _name;
|
||||
G13_ActionPtr _action;
|
||||
ActionPtr _action;
|
||||
|
||||
private:
|
||||
PARENT_T *_parent_ptr;
|
||||
|
@ -104,7 +104,7 @@ int g13_create_uinput(void) {
|
||||
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));
|
||||
gettimeofday(&_event.time, 0);
|
||||
_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
|
||||
auto result = write(_output_pipe_fid, out.c_str(), out.size());
|
||||
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};
|
||||
usb_data[1] = leds;
|
||||
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;
|
||||
unsigned char usb_data[] = {5, 0, 0, 0, 0};
|
||||
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;
|
||||
|
||||
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(_output_pipe_name.c_str());
|
||||
ioctl(_uinput_fid, UI_DEV_DESTROY);
|
||||
@ -195,7 +195,7 @@ void G13_Device::cleanup() {
|
||||
/*! reads and processes key state report from G13
|
||||
*
|
||||
*/
|
||||
int G13_Device::read_keys() {
|
||||
int Device::read_keys() {
|
||||
unsigned char buffer[G13_REPORT_SIZE];
|
||||
int size;
|
||||
int error =
|
||||
@ -217,7 +217,7 @@ int G13_Device::read_keys() {
|
||||
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);
|
||||
|
||||
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_ZERO(&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)
|
||||
: _id_within_manager(_id),
|
||||
handle(handle),
|
||||
@ -290,7 +290,7 @@ G13_Device::G13_Device(G13_Manager &manager, libusb_device_handle *handle,
|
||||
_manager(manager),
|
||||
_lcd(*this),
|
||||
_stick(*this) {
|
||||
_current_profile = ProfilePtr(new G13_Profile(*this, "default"));
|
||||
_current_profile = ProfilePtr(new Profile(*this, "default"));
|
||||
_profiles["default"] = _current_profile;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
FontPtr G13_Device::switch_to_font(const std::string &name) {
|
||||
FontPtr Device::switch_to_font(const std::string &name) {
|
||||
FontPtr rv = _fonts[name];
|
||||
if (rv) {
|
||||
_current_font = rv;
|
||||
@ -311,34 +311,34 @@ FontPtr G13_Device::switch_to_font(const std::string &name) {
|
||||
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);
|
||||
}
|
||||
|
||||
ProfilePtr G13_Device::profile(const std::string &name) {
|
||||
ProfilePtr Device::profile(const std::string &name) {
|
||||
ProfilePtr rv = _profiles[name];
|
||||
if (!rv) {
|
||||
rv = ProfilePtr(new G13_Profile(*_current_profile, name));
|
||||
rv = ProfilePtr(new Profile(*_current_profile, name));
|
||||
_profiles[name] = rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
G13_ActionPtr G13_Device::make_action(const std::string &action) {
|
||||
ActionPtr Device::make_action(const std::string &action) {
|
||||
if (!action.size()) {
|
||||
throw G13_CommandException("empty action string");
|
||||
throw CommandException("empty action string");
|
||||
}
|
||||
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] == '!') {
|
||||
return G13_ActionPtr(new G13_Action_Command(*this, &action[1]));
|
||||
return ActionPtr(new Action_Command(*this, &action[1]));
|
||||
} 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
|
||||
<< " input_pipe_name=" << repr(_input_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 {
|
||||
command_adder(G13_Device::CommandFunctionTable &t, const char *name)
|
||||
command_adder(Device::CommandFunctionTable &t, const char *name)
|
||||
: _t(t),
|
||||
_name(name) {
|
||||
}
|
||||
|
||||
G13_Device::CommandFunctionTable &_t;
|
||||
Device::CommandFunctionTable &_t;
|
||||
std::string _name;
|
||||
command_adder &operator+=(G13_Device::COMMAND_FUNCTION f) {
|
||||
command_adder &operator+=(Device::COMMAND_FUNCTION f) {
|
||||
_t[_name] = f;
|
||||
return *this;
|
||||
};
|
||||
@ -400,7 +400,7 @@ struct command_adder {
|
||||
BOOST_PP_STRINGIZE(name)); \
|
||||
BOOST_PP_CAT(add_, name) += [this](const char *remainder)
|
||||
|
||||
void G13_Device::_init_commands() {
|
||||
void Device::_init_commands() {
|
||||
G13_DEVICE_COMMAND(out) {
|
||||
lcd().write_string(remainder);
|
||||
}
|
||||
@ -477,10 +477,10 @@ void G13_Device::_init_commands() {
|
||||
advance_ws(remainder, zonename);
|
||||
|
||||
if (operation != "add") {
|
||||
G13_StickZone *zone = _stick.zone(zonename);
|
||||
StickZone *zone = _stick.zone(zonename);
|
||||
|
||||
if (!zone) {
|
||||
throw G13_CommandException("unknown stick zone");
|
||||
throw CommandException("unknown stick zone");
|
||||
}
|
||||
|
||||
if (operation == "action") {
|
||||
@ -489,10 +489,10 @@ void G13_Device::_init_commands() {
|
||||
double x1, y1, x2, y2;
|
||||
|
||||
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") {
|
||||
_stick.remove_zone(*zone);
|
||||
} 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;
|
||||
|
||||
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);
|
||||
if (error) {
|
||||
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();
|
||||
if (size != G13_LCD_BUFFER_SIZE) {
|
||||
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");
|
||||
}
|
||||
|
||||
void G13_Device::write_lcd_file(const std::string &filename) {
|
||||
void Device::write_lcd_file(const std::string &filename) {
|
||||
std::filebuf *pbuf;
|
||||
std::ifstream filestr;
|
||||
size_t size;
|
||||
@ -598,7 +598,7 @@ void G13_Device::write_lcd_file(const std::string &filename) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -15,16 +15,16 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_Manager;
|
||||
class Manager;
|
||||
|
||||
class G13_Device {
|
||||
class Device {
|
||||
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;
|
||||
}
|
||||
const G13_Manager &manager() const {
|
||||
const Manager &manager() const {
|
||||
return _manager;
|
||||
}
|
||||
|
||||
@ -34,10 +34,10 @@ class G13_Device {
|
||||
const G13_LCD &lcd() const {
|
||||
return _lcd;
|
||||
}
|
||||
G13_Stick &stick() {
|
||||
Stick &stick() {
|
||||
return _stick;
|
||||
}
|
||||
const G13_Stick &stick() const {
|
||||
const Stick &stick() const {
|
||||
return _stick;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ class G13_Device {
|
||||
int read_keys();
|
||||
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_mode_leds(int leds);
|
||||
@ -67,15 +67,15 @@ class G13_Device {
|
||||
bool is_set(int key);
|
||||
bool update(int key, bool v);
|
||||
|
||||
// used by G13_Manager
|
||||
// used by Manager
|
||||
void cleanup();
|
||||
void register_context(libusb_context *ctx);
|
||||
void write_lcd_file(const std::string &filename);
|
||||
|
||||
G13_Font ¤t_font() {
|
||||
Font ¤t_font() {
|
||||
return *_current_font;
|
||||
}
|
||||
G13_Profile ¤t_profile() {
|
||||
Profile ¤t_profile() {
|
||||
return *_current_profile;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ class G13_Device {
|
||||
void init_lcd();
|
||||
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;
|
||||
|
||||
struct timeval _event_time;
|
||||
@ -113,18 +113,18 @@ class G13_Device {
|
||||
std::map<std::string, ProfilePtr> _profiles;
|
||||
ProfilePtr _current_profile;
|
||||
|
||||
G13_Manager &_manager;
|
||||
Manager &_manager;
|
||||
G13_LCD _lcd;
|
||||
G13_Stick _stick;
|
||||
Stick _stick;
|
||||
|
||||
bool keys[G13_NUM_KEYS];
|
||||
};
|
||||
|
||||
inline bool G13_Device::is_set(int key) {
|
||||
inline bool Device::is_set(int 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];
|
||||
keys[key] = v;
|
||||
return old != v;
|
||||
|
16
g13d/font.cc
16
g13d/font.cc
@ -8,15 +8,15 @@ namespace G13 {
|
||||
|
||||
#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),
|
||||
_width(width) {
|
||||
}
|
||||
|
||||
void G13_FontChar::set_character(unsigned char *data, int width,
|
||||
void FontChar::set_character(unsigned char *data, int width,
|
||||
unsigned flags) {
|
||||
unsigned char *dest = bits_regular;
|
||||
memset(dest, 0, CHAR_BUF_SIZE);
|
||||
@ -45,19 +45,19 @@ int GetFontCharacterCount(T (&)[size]) {
|
||||
}
|
||||
|
||||
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++) {
|
||||
_chars[i + first].set_character(&data[i][0], _width, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void G13_Device::_init_fonts() {
|
||||
_current_font = FontPtr(new G13_Font("8x8", 8));
|
||||
void Device::_init_fonts() {
|
||||
_current_font = FontPtr(new Font("8x8", 8));
|
||||
_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);
|
||||
_fonts[fiveXeight->name()] = fiveXeight;
|
||||
}
|
||||
|
16
g13d/font.h
16
g13d/font.h
@ -7,12 +7,12 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_FontChar {
|
||||
class FontChar {
|
||||
public:
|
||||
static const int CHAR_BUF_SIZE = 8;
|
||||
enum FONT_FLAGS { FF_ROTATE = 0x01 };
|
||||
|
||||
G13_FontChar() {
|
||||
FontChar() {
|
||||
memset(bits_regular, 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];
|
||||
};
|
||||
|
||||
class G13_Font {
|
||||
class Font {
|
||||
public:
|
||||
G13_Font();
|
||||
G13_Font(const std::string &name, unsigned int width = 8);
|
||||
Font();
|
||||
Font(const std::string &name, unsigned int width = 8);
|
||||
|
||||
void set_character(unsigned int c, unsigned char *data);
|
||||
|
||||
@ -39,7 +39,7 @@ class G13_Font {
|
||||
return _width;
|
||||
}
|
||||
|
||||
const G13_FontChar &char_data(unsigned int x) {
|
||||
const FontChar &char_data(unsigned int x) {
|
||||
return _chars[x];
|
||||
}
|
||||
|
||||
@ -47,10 +47,10 @@ class G13_Font {
|
||||
std::string _name;
|
||||
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
|
||||
|
||||
|
@ -40,11 +40,11 @@ const LINUX_KEY_VALUE BAD_KEY_VALUE = -1;
|
||||
|
||||
typedef int G13_KEY_INDEX;
|
||||
|
||||
class G13_CommandException : public std::exception {
|
||||
class CommandException : public std::exception {
|
||||
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() {
|
||||
return _reason.c_str();
|
||||
|
@ -31,7 +31,7 @@ void G13_LCD::image(unsigned char *data, int 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_row = 0;
|
||||
text_mode = 0;
|
||||
|
@ -7,13 +7,13 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_Device;
|
||||
class Device;
|
||||
|
||||
class G13_LCD {
|
||||
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 cursor_row;
|
||||
unsigned cursor_col;
|
||||
|
@ -10,7 +10,7 @@ namespace po = boost::program_options;
|
||||
extern "C" {
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
G13::G13_Manager manager;
|
||||
G13::Manager manager;
|
||||
manager.set_log_level("info");
|
||||
|
||||
// Declare the supported options.
|
||||
|
@ -25,8 +25,8 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
void G13_Manager::discover_g13s(libusb_device **devs, ssize_t count,
|
||||
std::vector<G13_Device *> &g13s) {
|
||||
void Manager::discover_g13s(libusb_device **devs, ssize_t count,
|
||||
std::vector<Device *> &g13s) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
libusb_device_descriptor 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");
|
||||
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);
|
||||
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) \
|
||||
if (level == BOOST_PP_STRINGIZE(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);
|
||||
}
|
||||
|
||||
void G13_Manager::cleanup() {
|
||||
void Manager::cleanup() {
|
||||
G13_LOG(info, "cleaning up");
|
||||
|
||||
for (auto device : g13s) {
|
||||
@ -88,15 +88,15 @@ void G13_Manager::cleanup() {
|
||||
libusb_exit(ctx);
|
||||
}
|
||||
|
||||
G13_Manager::G13_Manager() : devs(0), ctx(0) {
|
||||
Manager::Manager() : devs(0), ctx(0) {
|
||||
}
|
||||
|
||||
bool G13_Manager::running = true;
|
||||
void G13_Manager::set_stop(int) {
|
||||
bool Manager::running = true;
|
||||
void Manager::set_stop(int) {
|
||||
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 {
|
||||
return find_or_throw(_string_config_values, name);
|
||||
} 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) {
|
||||
G13_LOG(info, "set_string_config_value " << name << " = " << repr(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/")
|
||||
|
||||
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) {
|
||||
std::string config_base = string_config_value("pipe_in");
|
||||
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();
|
||||
display_keys();
|
||||
|
||||
@ -222,7 +222,7 @@ int G13_Manager::run() {
|
||||
input_name_to_key[name] = keyval; \
|
||||
}
|
||||
|
||||
void G13_Manager::init_keynames() {
|
||||
void Manager::init_keynames() {
|
||||
int key_index = 0;
|
||||
|
||||
BOOST_PP_SEQ_FOR_EACH(ADD_G13_KEY_MAPPING, _, G13_KEY_SEQ);
|
||||
@ -230,7 +230,7 @@ void G13_Manager::init_keynames() {
|
||||
}
|
||||
|
||||
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);
|
||||
if (i == g13_name_to_key.end()) {
|
||||
return BAD_KEY_VALUE;
|
||||
@ -239,7 +239,7 @@ G13_Manager::find_g13_key_value(const std::string &keyname) const {
|
||||
}
|
||||
|
||||
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 (!strncmp(keyname.c_str(), "KEY_", 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;
|
||||
}
|
||||
|
||||
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 {
|
||||
return find_or_throw(input_key_to_name, v);
|
||||
} 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 {
|
||||
return find_or_throw(g13_key_to_name, v);
|
||||
} 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(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
|
||||
*/
|
||||
class G13_Manager {
|
||||
class Manager {
|
||||
public:
|
||||
G13_Manager();
|
||||
Manager();
|
||||
|
||||
G13_KEY_INDEX find_g13_key_value(const std::string &keyname) 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;
|
||||
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(const std::string &);
|
||||
@ -40,14 +40,14 @@ class G13_Manager {
|
||||
void init_keynames();
|
||||
void display_keys();
|
||||
void discover_g13s(libusb_device **devs, ssize_t count,
|
||||
std::vector<G13_Device *> &g13s);
|
||||
std::vector<Device *> &g13s);
|
||||
void cleanup();
|
||||
|
||||
std::string logo_filename;
|
||||
libusb_device **devs;
|
||||
|
||||
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<std::string, G13_KEY_INDEX> g13_name_to_key;
|
||||
@ -64,15 +64,15 @@ class G13_Manager {
|
||||
|
||||
// inlines
|
||||
|
||||
inline G13_Manager &G13_Action::manager() {
|
||||
inline Manager &Action::manager() {
|
||||
return _keypad.manager();
|
||||
}
|
||||
|
||||
inline const G13_Manager &G13_Action::manager() const {
|
||||
inline const Manager &Action::manager() const {
|
||||
return _keypad.manager();
|
||||
}
|
||||
|
||||
inline const G13_Manager &G13_Profile::manager() const {
|
||||
inline const Manager &Profile::manager() const {
|
||||
return _keypad.manager();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
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() << ") : ";
|
||||
|
||||
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_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;
|
||||
|
||||
// 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) \
|
||||
{ \
|
||||
G13_Key key(*this, BOOST_PP_STRINGIZE(elem), key_index++); \
|
||||
Key key(*this, BOOST_PP_STRINGIZE(elem), key_index++); \
|
||||
_keys.push_back(key); \
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ void G13_Profile::_init_keys() {
|
||||
// now disable testing for keys in G13_NONPARSED_KEY_SEQ
|
||||
#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); \
|
||||
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)
|
||||
}
|
||||
|
||||
void G13_Profile::dump(std::ostream &o) const {
|
||||
void Profile::dump(std::ostream &o) const {
|
||||
o << "Profile " << repr(name()) << std::endl;
|
||||
BOOST_FOREACH (const G13_Key &key, _keys) {
|
||||
BOOST_FOREACH (const Key &key, _keys) {
|
||||
if (key.action()) {
|
||||
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;
|
||||
for (size_t i = 0; i < _keys.size(); i++) {
|
||||
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);
|
||||
|
||||
// TODO(jtgans): Check this is the proper type
|
||||
|
@ -42,21 +42,21 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_Device;
|
||||
class G13_Key;
|
||||
class G13_Profile;
|
||||
class Device;
|
||||
class Key;
|
||||
class Profile;
|
||||
|
||||
/*! manages the bindings for a G13 key
|
||||
*
|
||||
*/
|
||||
class G13_Key : public G13_Actionable<G13_Profile> {
|
||||
class Key : public Actionable<Profile> {
|
||||
public:
|
||||
void dump(std::ostream &o) const;
|
||||
G13_KEY_INDEX index() const {
|
||||
return _index.index;
|
||||
}
|
||||
|
||||
void parse_key(unsigned char *byte, G13_Device *g13);
|
||||
void parse_key(unsigned char *byte, Device *g13);
|
||||
|
||||
protected:
|
||||
struct KeyIndex {
|
||||
@ -68,17 +68,17 @@ class G13_Key : public G13_Actionable<G13_Profile> {
|
||||
unsigned char mask;
|
||||
};
|
||||
|
||||
// G13_Profile is the only class able to instantiate G13_Keys
|
||||
friend class G13_Profile;
|
||||
// Profile is the only class able to instantiate Keys
|
||||
friend class Profile;
|
||||
|
||||
G13_Key(G13_Profile &mode, const std::string &name, int index)
|
||||
: G13_Actionable<G13_Profile>(mode, name),
|
||||
Key(Profile &mode, const std::string &name, int index)
|
||||
: Actionable<Profile>(mode, name),
|
||||
_index(index),
|
||||
_should_parse(true) {
|
||||
}
|
||||
|
||||
G13_Key(G13_Profile &mode, const G13_Key &key)
|
||||
: G13_Actionable<G13_Profile>(mode, key.name()),
|
||||
Key(Profile &mode, const Key &key)
|
||||
: Actionable<Profile>(mode, key.name()),
|
||||
_index(key._index),
|
||||
_should_parse(key._should_parse) {
|
||||
set_action(key.action());
|
||||
@ -94,22 +94,22 @@ class G13_Key : public G13_Actionable<G13_Profile> {
|
||||
* This allows a keypad to have multiple configured
|
||||
* profiles and switch between them easily
|
||||
*/
|
||||
class G13_Profile {
|
||||
class Profile {
|
||||
public:
|
||||
G13_Profile(G13_Device &keypad, const std::string &name_arg)
|
||||
Profile(Device &keypad, const std::string &name_arg)
|
||||
: _keypad(keypad),
|
||||
_name(name_arg) {
|
||||
_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),
|
||||
_name(name_arg),
|
||||
_keys(other._keys) {
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
@ -118,17 +118,17 @@ class G13_Profile {
|
||||
return _name;
|
||||
}
|
||||
|
||||
const G13_Manager &manager() const;
|
||||
const Manager &manager() const;
|
||||
|
||||
protected:
|
||||
G13_Device &_keypad;
|
||||
Device &_keypad;
|
||||
std::string _name;
|
||||
std::vector<G13_Key> _keys;
|
||||
std::vector<Key> _keys;
|
||||
|
||||
void _init_keys();
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<G13_Profile> ProfilePtr;
|
||||
typedef std::shared_ptr<Profile> ProfilePtr;
|
||||
|
||||
} // namespace G13
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
G13_Stick::G13_Stick(G13_Device &keypad)
|
||||
Stick::Stick(Device &keypad)
|
||||
: _keypad(keypad),
|
||||
_bounds(0, 0, 255, 255),
|
||||
_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,
|
||||
double x2, double y2) {
|
||||
_zones.push_back(G13_StickZone(
|
||||
*this, "STICK_" + name, G13_ZoneBounds(x1, y1, x2, y2),
|
||||
G13_ActionPtr(new G13_Action_Keys(keypad, "KEY_" + name))));
|
||||
_zones.push_back(StickZone(
|
||||
*this, "STICK_" + name, ZoneBounds(x1, y1, x2, y2),
|
||||
ActionPtr(new Action_Keys(keypad, "KEY_" + name))));
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
G13_StickZone *G13_Stick::zone(const std::string &name, bool create) {
|
||||
BOOST_FOREACH (G13_StickZone &zone, _zones) {
|
||||
StickZone *Stick::zone(const std::string &name, bool create) {
|
||||
BOOST_FOREACH (StickZone &zone, _zones) {
|
||||
if (zone.name() == name) {
|
||||
return &zone;
|
||||
}
|
||||
@ -41,14 +41,14 @@ G13_StickZone *G13_Stick::zone(const std::string &name, bool create) {
|
||||
|
||||
if (create) {
|
||||
_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 0;
|
||||
}
|
||||
|
||||
void G13_Stick::set_mode(stick_mode_t m) {
|
||||
void Stick::set_mode(stick_mode_t m) {
|
||||
if (m == _stick_mode) {
|
||||
return;
|
||||
}
|
||||
@ -61,27 +61,27 @@ void G13_Stick::set_mode(stick_mode_t m) {
|
||||
_stick_mode = m;
|
||||
|
||||
if (_stick_mode == STICK_CALBOUNDS) {
|
||||
_bounds.tl = G13_StickCoord(255, 255);
|
||||
_bounds.br = G13_StickCoord(0, 0);
|
||||
_bounds.tl = StickCoord(255, 255);
|
||||
_bounds.br = StickCoord(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void G13_Stick::_recalc_calibrated() {
|
||||
void Stick::_recalc_calibrated() {
|
||||
}
|
||||
|
||||
void G13_Stick::remove_zone(const G13_StickZone &zone) {
|
||||
G13_StickZone target(zone);
|
||||
void Stick::remove_zone(const StickZone &zone) {
|
||||
StickZone target(zone);
|
||||
_zones.erase(std::remove(_zones.begin(), _zones.end(), target), _zones.end());
|
||||
}
|
||||
|
||||
void G13_Stick::dump(std::ostream &out) const {
|
||||
BOOST_FOREACH (const G13_StickZone &zone, _zones) {
|
||||
void Stick::dump(std::ostream &out) const {
|
||||
BOOST_FOREACH (const StickZone &zone, _zones) {
|
||||
zone.dump(out);
|
||||
out << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void G13_StickZone::dump(std::ostream &out) const {
|
||||
void StickZone::dump(std::ostream &out) const {
|
||||
out << " " << std::setw(20) << name() << " " << _bounds << " ";
|
||||
|
||||
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;
|
||||
|
||||
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,
|
||||
const G13_ZoneBounds &b, G13_ActionPtr action)
|
||||
: G13_Actionable<G13_Stick>(stick, name),
|
||||
StickZone::StickZone(Stick &stick, const std::string &name,
|
||||
const ZoneBounds &b, ActionPtr action)
|
||||
: Actionable<Stick>(stick, name),
|
||||
_active(false),
|
||||
_bounds(b) {
|
||||
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.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
|
||||
<< " dx=" << dx << " dy=" << dy);
|
||||
|
||||
G13_ZoneCoord jpos(dx, dy);
|
||||
ZoneCoord jpos(dx, dy);
|
||||
if (_stick_mode == STICK_ABSOLUTE) {
|
||||
_keypad.send_event(EV_ABS, ABS_X, _current_pos.x);
|
||||
_keypad.send_event(EV_ABS, ABS_Y, _current_pos.y);
|
||||
} else if (_stick_mode == STICK_KEYS) {
|
||||
BOOST_FOREACH (G13_StickZone &zone, _zones) { zone.test(jpos); }
|
||||
BOOST_FOREACH (StickZone &zone, _zones) { zone.test(jpos); }
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
50
g13d/stick.h
50
g13d/stick.h
@ -7,48 +7,48 @@
|
||||
|
||||
namespace G13 {
|
||||
|
||||
class G13_Stick;
|
||||
class Stick;
|
||||
|
||||
typedef Coord<int> G13_StickCoord;
|
||||
typedef Bounds<int> G13_StickBounds;
|
||||
typedef Coord<double> G13_ZoneCoord;
|
||||
typedef Bounds<double> G13_ZoneBounds;
|
||||
typedef Coord<int> StickCoord;
|
||||
typedef Bounds<int> StickBounds;
|
||||
typedef Coord<double> ZoneCoord;
|
||||
typedef Bounds<double> ZoneBounds;
|
||||
|
||||
class G13_StickZone : public G13_Actionable<G13_Stick> {
|
||||
class StickZone : public Actionable<Stick> {
|
||||
public:
|
||||
G13_StickZone(G13_Stick &, const std::string &name, const G13_ZoneBounds &,
|
||||
G13_ActionPtr = 0);
|
||||
StickZone(Stick &, const std::string &name, const ZoneBounds &,
|
||||
ActionPtr = 0);
|
||||
|
||||
bool operator==(const G13_StickZone &other) const {
|
||||
bool operator==(const StickZone &other) const {
|
||||
return _name == other._name;
|
||||
}
|
||||
|
||||
void dump(std::ostream &) const;
|
||||
|
||||
void parse_key(unsigned char *byte, G13_Device *g13);
|
||||
void test(const G13_ZoneCoord &loc);
|
||||
void set_bounds(const G13_ZoneBounds &bounds) {
|
||||
void parse_key(unsigned char *byte, Device *g13);
|
||||
void test(const ZoneCoord &loc);
|
||||
void set_bounds(const ZoneBounds &bounds) {
|
||||
_bounds = bounds;
|
||||
}
|
||||
|
||||
protected:
|
||||
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:
|
||||
G13_Stick(G13_Device &keypad);
|
||||
Stick(Device &keypad);
|
||||
|
||||
void parse_joystick(unsigned char *buf);
|
||||
|
||||
void set_mode(stick_mode_t);
|
||||
G13_StickZone *zone(const std::string &, bool create = false);
|
||||
void remove_zone(const G13_StickZone &zone);
|
||||
StickZone *zone(const std::string &, bool create = false);
|
||||
void remove_zone(const StickZone &zone);
|
||||
|
||||
const std::vector<G13_StickZone> &zones() const {
|
||||
const std::vector<StickZone> &zones() const {
|
||||
return _zones;
|
||||
}
|
||||
|
||||
@ -57,14 +57,14 @@ class G13_Stick {
|
||||
protected:
|
||||
void _recalc_calibrated();
|
||||
|
||||
G13_Device &_keypad;
|
||||
std::vector<G13_StickZone> _zones;
|
||||
Device &_keypad;
|
||||
std::vector<StickZone> _zones;
|
||||
|
||||
G13_StickBounds _bounds;
|
||||
G13_StickCoord _center_pos;
|
||||
G13_StickCoord _north_pos;
|
||||
StickBounds _bounds;
|
||||
StickCoord _center_pos;
|
||||
StickCoord _north_pos;
|
||||
|
||||
G13_StickCoord _current_pos;
|
||||
StickCoord _current_pos;
|
||||
|
||||
stick_mode_t _stick_mode;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user