Skip to content

Commit

Permalink
Add lift threshold and color for G500 profile
Browse files Browse the repository at this point in the history
  • Loading branch information
cvuchener committed Dec 16, 2015
1 parent b12387c commit 69e0786
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
33 changes: 30 additions & 3 deletions src/libhidpp/hidpp10/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

using namespace HIDPP10;

template<typename T>
static T clamp (T value, T min, T max)
{
return std::min (std::max (value, min), max);
}

std::string Profile::Button::specialFunctionToString (SpecialFunction special)
{
switch (special) {
Expand Down Expand Up @@ -269,7 +275,8 @@ G500Profile::G500Profile (const Sensor *sensor):
Profile (13), _sensor (sensor),
_color ({ 255, 0, 0 }),
_angle (0x80),
_lift (0x10), _unk (0x10),
_lift (0),
_unk (0x10),
_poll_interval (8)
{
}
Expand Down Expand Up @@ -315,7 +322,7 @@ void G500Profile::read (ByteArray::const_iterator begin)
}
_angle_snap = *(begin+34) == 0x02;
_default_mode = *(begin+35);
_lift = *(begin+36);
_lift = static_cast<int> (*(begin+36) & 0x1f) - 0x10;
_unk = *(begin+37);
_poll_interval = *(begin+38);
readButtons (begin+39);
Expand Down Expand Up @@ -343,7 +350,7 @@ void G500Profile::write (ByteArray::iterator begin) const
}
*(begin+34) = (_angle_snap ? 0x02 : 0x01);
*(begin+35) = _default_mode;
*(begin+36) = _lift;
*(begin+36) = 0x10 + clamp (_lift, -15, 15);
*(begin+37) = _unk;
*(begin+38) = _poll_interval;
writeButtons (begin+39);
Expand Down Expand Up @@ -382,6 +389,16 @@ void G500Profile::setDefaultMode (unsigned int index)
_default_mode = index;
}

Profile::Color G500Profile::color () const
{
return _color;
}

void G500Profile::setColor (Color color)
{
_color = color;
}

bool G500Profile::angleSnap () const
{
return _angle_snap;
Expand All @@ -392,6 +409,16 @@ void G500Profile::setAngleSnap (bool enabled)
_angle_snap = enabled;
}

int G500Profile::liftThreshold () const
{
return _lift;
}

void G500Profile::setLiftThreshold (int lift)
{
_lift = lift;
}

unsigned int G500Profile::pollInterval () const
{
return _poll_interval;
Expand Down
17 changes: 13 additions & 4 deletions src/libhidpp/hidpp10/Profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ enum ProfileType {
class Profile
{
public:
struct Color {
uint8_t r, g, b;
};

class Button {
public:
enum Type: uint8_t {
Expand Down Expand Up @@ -148,22 +152,27 @@ class G500Profile: public Profile
unsigned int defaultMode () const;
void setDefaultMode (unsigned int index);

Color color () const;
void setColor (Color color);

bool angleSnap () const;
void setAngleSnap (bool enabled);

int liftThreshold () const;
void setLiftThreshold (int lift);

unsigned int pollInterval () const;
void setPollInterval (unsigned int interval);

private:
const Sensor *_sensor;
struct {
uint8_t r, g, b;
} _color;
Color _color;
uint8_t _angle;
std::vector<ResolutionMode> _modes;
bool _angle_snap;
unsigned int _default_mode;
uint8_t _lift, _unk;
int _lift;
uint8_t _unk;
unsigned int _poll_interval;
};

Expand Down
23 changes: 23 additions & 0 deletions src/tools/profile/ProfileXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ void G500ProfileToXML (const Profile *p, const std::vector<Macro> &macros, XMLNo
angle_snap->SetText (profile->angleSnap ());
node->InsertEndChild (angle_snap);

XMLElement *lift = doc->NewElement ("lift");
lift->SetText (profile->liftThreshold ());
node->InsertEndChild (lift);

XMLElement *color = doc->NewElement ("color");
Profile::Color c = profile->color ();
char color_str[7];
sprintf (color_str, "%02hhx%02hhx%02hhx", c.r, c.g, c.b);
color->SetText (color_str);
node->InsertEndChild (color);

XMLElement *buttons = doc->NewElement ("buttons");
ButtonsToXML (profile, macros, buttons);
node->InsertEndChild (buttons);
Expand Down Expand Up @@ -304,6 +315,18 @@ void XMLToG500Profile (const XMLNode *node, Profile *p, std::vector<Macro> &macr
Log::error () << "Invalid angle snap." << std::endl;
profile->setAngleSnap (angle_snap);
}
else if (name == "lift") {
int lift;
if (XML_NO_ERROR != element->QueryIntText (&lift))
Log::error () << "Invalid lift threshold." << std::endl;
profile->setLiftThreshold (lift);
}
else if (name == "color") {
Profile::Color color;
if (3 != sscanf (element->GetText (), "%02hhx%02hhx%02hhx", &color.r, &color.g, &color.b))
Log::error () << "Invalid color value." << std::endl;
profile->setColor (color);
}
else if (name == "buttons") {
XMLToButtons (element, profile, macros);
}
Expand Down

0 comments on commit 69e0786

Please sign in to comment.