├── COPYING.txt ├── FAQandHistory.txt ├── Makefile ├── README.md ├── debian ├── changelog ├── compat ├── control ├── copyright ├── files ├── g500-control.dirs ├── rules └── source │ └── format ├── g500-control.c └── g500-control.h /COPYING.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /FAQandHistory.txt: -------------------------------------------------------------------------------- 1 | g500_control - configure Logitech G500's internal profile under Linux 2 | Copyright (C) 2011 Vladyslav Shtabovenko 3 | 4 | This project does not have any affiliation with Logitech or lomoco 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 | 20 | 21 | Why and how I created g500_control 22 | ======================================================================== 23 | I'm a loyal Logitech customer since 2005 and I really like Logitech's 24 | devices. Although not a gamer myself I enjoy using their gaming mice 25 | like MX510, G5 or G500. SetPoint is a great software which allows you to 26 | configure a lot of things, but unfortunately it's not available for 27 | Linux. Whether you can live with it or not depends on the particular 28 | mouse model you have. While using MX510 and G5 I didn't miss SetPoint 29 | much because for changing MX510's dpi there is lomoco and G5 even has 30 | dedicated dpi buttons. But G500 is different. This mouse has so many cool 31 | features like angle snapping, customizable USB report rate, dpi 32 | resolution adjustable in 100 dpi steps or persistent memory that I was 33 | seriously troubled about the fact that until now there was no Linux 34 | software able to modify those settings. Of course, you can boot into 35 | Windows, flash the necessary profile using SetPoint and then keep using 36 | it under Linux, but due to the fact that I rarely use Windows, this 37 | workaround proved to be too cumbersome for me. While googling about this 38 | issue I stumbled upon Andreas Schneider's blog 39 | (http://blog.cryptomilk.org/2011/02/22/logitech-linux-mouse-support/) 40 | where he presented a proof of concept code g_hack.c for changing 41 | resoultions of different Logitech's G series models. I tried it out on 42 | my G500 but it didn't work. Reading user comments on that post I found 43 | a comment by Marian Kyral where he described his efforts to get the 44 | battery status of his MX Anywhere by tracing USB communication via 45 | SnoopyPro (http://sourceforge.net/projects/usbsnoop/files/SnoopyPro/). 46 | I downloaded this tool and managed to get it working with my G500 under 47 | Windows 7 while using SetPoint 6.20. This allowed me to understand how 48 | SetPoint communicates with a G500 and what must be done to change G500's 49 | internal memory. Here I'd like to make clear that I DID NOT hack, crack 50 | or disassemble SetPoint or G500's firmware. In fact, I don't even know 51 | to use a disassembler or how to reverse engineer a firmware. The USB 52 | communication between SetPoint and a G500 is not encrypted and is quite 53 | easy to understand if you change only one setting per time and then 54 | compare the logs to find out which bytes have been changed. All you need 55 | is time and some basic HEX math knowledge. Subsequently, I modified 56 | Andreas Schneider's code to make it compatible with my G500 57 | (e.g. adding 20 byte buffers). Originally, I only wanted to have a quick 58 | and dirty dpi switcher for my personal needs but as I discovered how to 59 | enable angle snapping or change USB report rate, I realized that it 60 | would be good to share the modified code with the Linux community. 61 | Which I'm hereby doing. 62 | 63 | g500_control's current status 64 | ======================================================================== 65 | Please don't forget that g500_control is highly experimental in a sense 66 | that so far it has been tested only on a single G500: my own. As far as 67 | my G500 is concerned, g500_control works really great and allows me to 68 | change much of the settings otherwise available only via SetPoint. If 69 | you decide to test it on your G500, you must understand that you're 70 | doing it on your own risk. I bear absolutely no responsibility for 71 | anything that may happen to your G500 while using g500_control. On the 72 | other hand, I really tried hard to make the code safe concerning user 73 | input and to test everything I could test very thoroughly. What you 74 | could do to be on the safe side is to use SnoopyPro to examine the 75 | communication between the SetPoint on your machine and your G500. Check 76 | the source code for the initialization sequence and compare it with the 77 | initialization sequence in your logs. If they match, then g500_control 78 | probably should work with your G500 too. But once again, I can't give 79 | you any guaranty and everything you're doing is on your own risk. 80 | 81 | Any particular tips on installing g500_control? 82 | ======================================================================== 83 | Not really. Just compile it with "gcc -o g500_control g500_control.c" 84 | And use it with sudo. If you want the program to work without password 85 | prompt, you might copy it to /usr/bin "sudo cp g500_control /usr/bin" 86 | and apply "sudo chmod ug+s /usr/bin/g500_control". Be aware that making 87 | a program SUID is generally a dangerous and not really 88 | appreciated thing in the Linux world. 89 | 90 | How to use 91 | ======================================================================== 92 | To display help, simply run g500_control without any arguments. The help 93 | is actually pretty self explanatory. I also included some examples to 94 | help you customizing your settings. At the end of this file you'll find 95 | the help normally displayed by g500_control 96 | 97 | Are the changes made by g500_control persistent? 98 | ======================================================================== 99 | g500_control writes desired settings directly into G500's internal 100 | memory just as SetPoint does. Those settings are persistent and are not 101 | lost if you reboot your PC or unplug the mouse. Nevertheless you should 102 | remember that when using G500 on a Windows systems with SetPoint 103 | installed, SetPoint will always flash its own settings without asking 104 | your permission. Thus, if you dual boot Linux and Windows and use 105 | different profiles for each OS, you may consider running g500_control 106 | automatically when starting Linux, for it to load your desired settings. 107 | 108 | How can I check my current USB report rate? 109 | ======================================================================== 110 | Google for evhz.c (currently available here http://hlds.pl/Evhz.c) 111 | compile it and run evhz as root. Now move your G500. The "average hz" 112 | value should correspond to your current USB report rate 113 | 114 | How I can check whether angle snapping is working? 115 | ======================================================================== 116 | Open your favorite graphics editor, choose a pencil/brush tool and try 117 | to draw a straight vertical or horizontal line. Compared to angle 118 | snapping disabled, your line should be almost ideally straight. 119 | 120 | What about buttons mapping and macros like in SetPoint? 121 | ======================================================================== 122 | Currently the only button mapping implemented is the ability to map dpi 123 | buttons to +/- or forwards/backwards when using more than one dpi 124 | resolution. When using only one dpi resolution, +/- buttons become 125 | visible to X11 and thus can be mapped via xbindkeys or similar tools 126 | to something useful. Making an arbitrary button to act as dpi increase/ 127 | decrease button is not difficult, but making an arbitrary button perform 128 | an arbitrary action is. The problem is that SetPoint uses a mixed 129 | strategy to map certain actions to certain buttons. For some actions, 130 | the buttons really do send appropriate keycodes but for others SetPoint 131 | simply detects the pressed button and performs the defined action 132 | itself. Moreover, under Linux you don't really need to map buttons to 133 | actions on the hardware level. There are tools like xbindkeys around 134 | which allow you to map any button to anything you want. Thus, I might 135 | look into allowing more buttons act like dpi buttons but I'm definitely 136 | not going to waste my time for figuring out which actions can be mapped 137 | to certain buttons on the hardware level and which not. 138 | 139 | What about acceleration/sensitivity settings? 140 | ======================================================================= 141 | I tried really hard to find out where these settings are saved but in 142 | the meantime I tend to believe that these are provided only by the 143 | SetPoint software, i.e. not by G500's hardware. There is a simple 144 | experiment to check this out. In SetPoint, turn off OS sensitivity 145 | control and set both sensitivity and acceleration to 0. This will make 146 | your G500 extremely slow. If you, however, reboot to Linux, you'll notice 147 | that the G500 works as usual and isn't slow at all. The same holds 148 | also for vertical and horizontal scrolling speed. Of course, I can't know 149 | for sure, but at the moment I consider all those to be software emulated 150 | and not something you can change on the hardware level. 151 | 152 | Do you plan a GUI version of g500_control? 153 | ======================================================================== 154 | Unfortunately, I know very little about GUI programming and it probably 155 | would take me too much time to create a more or less working GUI. May be 156 | someone kind enough will provide us a GUI/frontend someday ;) 157 | 158 | Why it's always necessary input all profile settings? 159 | ======================================================================== 160 | The thing is that you can't simply change one particular parameter in 161 | G500's internal profile without reflashing the whole profile. SetPoint 162 | basically does the same, but since it keeps your complete profile(s) in 163 | registry, you don't notice that each time you change a single setting and 164 | click apply, the whole profile gets reflashed. 165 | 166 | I tried playing with the source code and now my G500 doesn't work at all 167 | ======================================================================== 168 | This actually happened to me several times while coding g500_control. 169 | In my case, however, the mouse started working again after I rebooted 170 | into Windows with SetPoint. My theory is that every time SetPoint 171 | detects a G500, it flashes the mouse with the predefined profile which 172 | literally brings it back to life. I, however, in no way claim that it's 173 | impossible to brick a G500 completely by flashing it with junk data. 174 | So, be careful! 175 | 176 | Do you plan to actively develop g500_control? 177 | ======================================================================== 178 | Frankly speaking, I regard g500_control to be rather a proof of concept 179 | than a standalone utility worth developing. On one hand, I'm a 180 | very poor programmer and chronically lack free time. On the other hand, 181 | I use g500_control myself, so as long as I'll be using my G500 under 182 | Linux you can expect to more or less maintain the code. 183 | 184 | g500_control internal help 185 | ======================================================================== 186 | WARNING! HIGHLY EXPERIMENTAL! THIS MAY POTENTIALLY BRICK YOUR LOGITECH G500 MOUSE, 187 | SO USE IT ON YOUR OWN RISK! NO LIABILITY FOR ANY DIRECT OR INDIRECT DAMAGE CAUSED 188 | BY USING THIS PROGRAM IS ACCEPTED! 189 | 190 | g500_control 0.0.1 is based on Andreas Schneider's g_hack.c and 191 | allows you to change Logitech G500's internal profile under Linux 192 | 193 | Usage: g500_control HIDDEVICE URR AS DPI_MODE OPTIONS 194 | 195 | Please note that all arguments are necessary! 196 | The number of parameters in OPTIONS depends on the DPI_MODE you choose. 197 | The only exception is that when using --dpi_default for DPI_MODE, you don't need OPTIONS at all. 198 | If you get a 'hiddev open: Permission denied' error, run g500_control with sudo. 199 | 200 | HIDDEVICE - probably /dev/usb/hiddev0 or /dev/hidraw0 201 | URR - set G500's USB report rate 202 | --urr_default Set USB report rate equal 500 which is G500's default behavior 203 | --125 Set USB report rate equal 125 204 | --200 Set USB report rate equal 200 205 | --250 Set USB report rate equal 250 206 | --333 Set USB report rate equal 333 207 | --500 Set USB report rate equal 500 208 | --1000 Set USB report rate equal 1000 209 | AS - enable or disable angle snapping for drawing perfectly straight lines 210 | --as_default Disable angle snapping which is G500's default behavior 211 | --as_on Enable angle snapping 212 | --as_off Disable angle snapping 213 | DPI_MODE - choose the DPI mode 214 | --dpi_default Use three different dpi resolutions: 400, 800 and 2000 dpi. 215 | Use dpi buttons to switch between different dpi values 216 | which is G500's default behavior 217 | --dpi_1 Use one dpi resolution and allow dpi buttons to be used as 218 | normal buttons. They become visible in xev and can be mapped 219 | to something useful via xbindkeys or other X-Window tools 220 | --dpi_2 Use two different dpi resolutions. Use dpi buttons to 221 | switch between different dpi values 222 | --dpi_3 Use three different dpi resolutions. Use dpi buttons to 223 | switch between different dpi values 224 | --dpi_4 Use four different dpi resolutions. Use dpi buttons to 225 | switch between different dpi values 226 | --dpi_5 Use five different dpi resolutions. Use dpi buttons to 227 | switch between different dpi values 228 | OPTIONS - set options according to the chosen DPI mode 229 | For dpi_default no additional options are needed 230 | For dpi_1 following options must be set 231 | dpi_x specify dpi resolution for the x axis. Valid values range from 232 | 200 to 5700 in 100 dpi steps, e.g. 200, 300, 400, 500, 600 etc. 233 | dpi_y specify dpi resolution for the y axis. Valid values range from 234 | 200 to 5700 in 100 dpi steps, e.g. 200, 300, 400, 500, 600 etc. 235 | For dpi_2 following options must be set 236 | dpi_1_x specify 1st dpi resolution for the x axis. 237 | dpi_1_y specify 1st dpi resolution for the y axis. 238 | dpi_2_x specify 2nd dpi resolution for the x axis. 239 | dpi_2_y specify 2nd dpi resolution for the y axis. 240 | dpi_btn specify whether +/- (on the upper side of the mouse) or 241 | forwards/backwards (on the left side of the mouse) buttons act as dpi 242 | buttons. Valid values are dpi_btn_up and dpi_btn_side. 243 | For dpi_3 following options must be set 244 | dpi_1_x specify 1st dpi resolution for the x axis. 245 | dpi_1_y specify 1st dpi resolution for the y axis. 246 | dpi_2_x specify 2nd dpi resolution for the x axis. 247 | dpi_2_y specify 2nd dpi resolution for the y axis. 248 | dpi_3_x specify 3rd dpi resolution for the x axis. 249 | dpi_3_y specify 3rd dpi resolution for the y axis. 250 | dpi_btn specify whether +/- (on the upper side of the mouse) or 251 | forwards/backwars (on the left side of the mouse) buttons act as dpi 252 | buttons. Valid values are dpi_btn_up and dpi_btn_side. 253 | For dpi_4 following options must be set 254 | dpi_1_x specify 1st dpi resolution for the x axis. 255 | dpi_1_y specify 1st dpi resolution for the y axis. 256 | dpi_2_x specify 2nd dpi resolution for the x axis. 257 | dpi_2_y specify 2nd dpi resolution for the y axis. 258 | dpi_3_x specify 3rd dpi resolution for the x axis. 259 | dpi_3_y specify 3rd dpi resolution for the y axis. 260 | dpi_4_x specify 4th dpi resolution for the x axis. 261 | dpi_4_y specify 4th dpi resolution for the y axis. 262 | dpi_btn specify whether +/- (on the upper side of the mouse) or 263 | forwards/backwars (on the left side of the mouse) buttons act as dpi 264 | buttons. Valid values are dpi_btn_up and dpi_btn_side. 265 | For dpi_5 following options must be set 266 | dpi_1_x specify 1st dpi resolution for the x axis. 267 | dpi_1_y specify 1st dpi resolution for the y axis. 268 | dpi_2_x specify 2nd dpi resolution for the x axis. 269 | dpi_2_y specify 2nd dpi resolution for the y axis. 270 | dpi_3_x specify 3rd dpi resolution for the x axis. 271 | dpi_3_y specify 3rd dpi resolution for the y axis. 272 | dpi_4_x specify 4th dpi resolution for the x axis. 273 | dpi_4_y specify 4th dpi resolution for the y axis. 274 | dpi_5_x specify 5th dpi resolution for the x axis. 275 | dpi_5_y specify 5th dpi resolution for the y axis. 276 | 277 | dpi_btn specify whether +/- (on the upper side of the mouse) or 278 | forwards/backwars (on the left side of the mouse) buttons act as dpi 279 | buttons. Valid values are dpi_btn_up and dpi_btn_side. 280 | Examples: 281 | ./g500_control /dev/usb/hiddev0 --urr_default --as_default --dpi_default 282 | this corresponds to G500's factory settings with 500 USB report rate, 283 | angle snapping disabled and 3 dpi resolutions (400, 800 and 2000). 284 | dpi buttons are used to switch between the 3 dpi values. 285 | ./g500_control /dev/usb/hiddev0 --urr_default --as_default --dpi_1 1600 1600 286 | here, only one dpi resolution (1600 dpi for both axes) is set. dpi buttons 287 | can be mapped to anything you want via xbindkeys or similar tools. 288 | ./g500_control /dev/usb/hiddev0 --1000 --as_on --dpi_1 1600 1600 289 | same as above, but now we increase USB report rate from 500 to 1000 and 290 | enable angle snapping. 291 | ./g500_control /dev/usb/hiddev0 --1000 --as_on --dpi_1 3200 4000 292 | same as above, but now we use different dpi resolutions for each axis. 293 | for the x axis it's 3200 and for the y axis it's 4000. 294 | ./g500_control /dev/usb/hiddev0 --500 --as_off --dpi_3 800 800 1600 1600 5700 5700 dpi_btn_up 295 | here, we set 3 different dpi resolutions: 800, 1600 and 5700 (equal for both axes). 296 | The dpi buttons (+/-) are used to switch between these. Moreover, we explicitly set USB 297 | repeat rate to 500 and disable angle snapping 298 | ./g500_control /dev/usb/hiddev0 --500 --as_off --dpi_3 800 800 1600 1600 5700 5700 dpi_btn_side 299 | same as above but here we use (<-/->) as dpi buttons. 300 | ./g500_control /dev/usb/hiddev0 --333 --as_on --dpi_5 800 800 1600 1600 3200 3200 4800 4800 5700 5700 dpi_btn_up 301 | here, we set 5 different dpi resolutions: 800, 1600, 3200, 4800 and 5700 302 | (equal for both axes). The dpi buttons (+/-) are used to switch between these. 303 | Moreover, we explicitly set USB repeat rate to 333 and enable angle snapping 304 | ./g500_control /dev/usb/hiddev0 --333 --as_on --dpi_5 800 800 1600 1000 3200 3200 4800 4800 5700 5700 dpi_btn_up 305 | similar to the above, but the second resolution has now different values for the axes: 306 | 1600 dpi for the x axis and 1000 dpi for the y axis. 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DESTDIR=/ 2 | 3 | all: 4 | gcc -std=c99 -ansi -pedantic -fstack-protector-all -g -Wall -o g500-control g500-control.c 5 | install: 6 | install -m 755 g500-control $(DESTDIR)/usr/sbin/ 7 | uninstall: 8 | rm -f $(DESTDIR)/usr/sbin/g500-control 9 | clean: 10 | rm -f g500-control 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | g500-control 2 | ==== 3 | 4 | Tweak Logitech G500 gaming mouse under Linux 5 | 6 | g500-control allows you to configure the hardware settings of the G500 7 | gaming mouse, e.g. dpi resolution, USB report rate or angle snapping 8 | without the need to boot Windows and run the SetPoint software. 9 | The settings are flashed directly into the G500's internal profile. 10 | 11 | Install: 12 | 13 | make 14 | 15 | make install 16 | 17 | Run: 18 | 19 | sudo g500-control 20 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | g500-control (0.0.2-1) UNRELEASED; urgency=low 2 | 3 | * Initial release. 4 | 5 | -- Vladyslav Shtabovenko Sun, 13 Apr 2014 20:59:10 +0200 6 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: g500-control 2 | Section: admin 3 | Priority: optional 4 | Maintainer: Vladyslav Shtabovenko 5 | Build-Depends: debhelper (>= 9), gcc (>=4.6) 6 | Standards-Version: 3.9.4 7 | Homepage: https://github.com/vsht/g500-control 8 | 9 | Package: g500-control 10 | Architecture: any 11 | Depends: ${shlibs:Depends}, ${misc:Depends} 12 | Section: admin 13 | Priority: optional 14 | Description: Tweak Logitech G500 gaming mouse under Linux 15 | g500-control allows you to configure the hardware settings of the G500 16 | gaming mouse, e.g. dpi resolution, USB report rate or angle snapping 17 | without the need to boot Windows and run the SetPoint software. 18 | The settings are flashed directly into the G500's internal profile. 19 | Homepage: https://github.com/vsht/g500-control 20 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Vladyslav Shtabovenko on 2 | Sunday, 13 Apr 2014 21:15:00 +0200. 3 | 4 | It was downloaded from https://github.com/vsht/g500-control 5 | 6 | Upstream Author: 7 | 8 | Vladyslav Shtabovenko 9 | 10 | Copyright: 11 | 12 | Copyright (C) 2011-2014 Vladyslav Shtabovenko 13 | 14 | License: 15 | 16 | Copyright (C) 2011-2014 Vladyslav Shtabovenko 17 | 18 | This program is free software: you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation, either version 3 of the License, or 21 | (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License 29 | along with this program. If not, see . 30 | 31 | 32 | The Debian packaging is (C) 2014, Vladyslav Shtabovenko and 33 | is licensed under the GPL, see `/usr/share/common-licenses/GPL'. 34 | 35 | 36 | -------------------------------------------------------------------------------- /debian/files: -------------------------------------------------------------------------------- 1 | g500-control_0.0.2-1_i386.deb admin optional 2 | -------------------------------------------------------------------------------- /debian/g500-control.dirs: -------------------------------------------------------------------------------- 1 | usr/sbin 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | 15 | override_dh_auto_install: 16 | $(MAKE) DESTDIR=$$(pwd)/debian/g500-control prefix=/usr/sbin install 17 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /g500-control.c: -------------------------------------------------------------------------------- 1 | /* 2 | * g500_control - configure Logitech G500's internal profile under Linux 3 | * Copyright (C) 2011 Vladyslav Shtabovenko 4 | * License: GPLv2 5 | * based on Andreas Schneider's g_hack.c posted on http://blog.cryptomilk.org/2011/02/22/logitech-linux-mouse-support/ 6 | * HIGHLY EXPERIMENTAL! USE AT YOUR OWN RISK! 7 | * 8 | * Big thanks to Andreas Schneider and Marian Kyral 9 | * this program contains code from http://www.lomoco.org/vx_hack.c 10 | * thanks to the usbsnoop (http://sourceforge.net/projects/usbsnoop/) developers for providing a free, simple and reliable tool 11 | * for sniffing G500's communication with SetPoint. 12 | * This project does not have any affiliation with Logitech. 13 | */ 14 | 15 | /* 16 | * gcc -o g_hack g_hack.c 17 | * ./g_hack /dev/hidraw0 18 | * 19 | * g_hack - proof of conecpt code 20 | * 21 | * 22 | * Copyright (c) 2006-2009 Andreas Schneider 23 | * Copyright (c) 2006-2007 Peter Feuerer 24 | * 25 | * License: GPLv2 or later 26 | * 27 | * Additional Info: 28 | * 29 | * the G-series has two modes: 30 | * 31 | * 1. mode: no driver 32 | * in this mode there is a list of resolutions implemented in the mouse 33 | * and you can switch between them using the buttons 34 | * 35 | * 2. mode is: windows driver 36 | * in this mode the buttons talk to the driver 37 | * they have absolute no effect on the hardware in first place 38 | * the driver gets the button event looks in its table, which resolution to use 39 | * sends it to the mouse sets the leds and the resolution 40 | */ 41 | 42 | #define _POSIX_C_SOURCE 199309L 43 | 44 | #ifndef G500_CONTROL_C 45 | #define G500_CONTROL_C 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include "g500-control.h" 56 | 57 | 58 | 59 | /*modified send_report since G500 also uses a 20 byte long buffer*/ 60 | static int send_report20(int fd, const unsigned char *buf, size_t size) { 61 | struct hiddev_report_info rinfo; 62 | struct hiddev_usage_ref uref; 63 | int i, err; 64 | 65 | for (i = 0; i < size; i++) { 66 | memset(&uref, 0, sizeof(uref)); 67 | uref.report_type = HID_REPORT_TYPE_OUTPUT; 68 | uref.report_id = 0x11; 69 | uref.field_index = 0; 70 | uref.usage_index = i; 71 | uref.usage_code = 0xff000001; 72 | uref.value = buf[i]; 73 | 74 | err = ioctl(fd, HIDIOCSUSAGE, &uref); 75 | if (err < 0) 76 | return err; 77 | } 78 | 79 | memset(&rinfo, 0, sizeof(rinfo)); 80 | rinfo.report_type = HID_REPORT_TYPE_OUTPUT; 81 | rinfo.report_id = 0x11; 82 | rinfo.num_fields = 1; 83 | err = ioctl(fd, HIDIOCSREPORT, &rinfo); 84 | 85 | return err; 86 | } 87 | 88 | static int send_report(int fd, const unsigned char *buf, size_t size) { 89 | struct hiddev_report_info rinfo; 90 | struct hiddev_usage_ref uref; 91 | int i, err; 92 | 93 | for (i = 0; i < size; i++) { 94 | memset(&uref, 0, sizeof(uref)); 95 | uref.report_type = HID_REPORT_TYPE_OUTPUT; 96 | uref.report_id = 0x10; 97 | uref.field_index = 0; 98 | uref.usage_index = i; 99 | uref.usage_code = 0xff000001; 100 | uref.value = buf[i]; 101 | 102 | err = ioctl(fd, HIDIOCSUSAGE, &uref); 103 | if (err < 0) 104 | return err; 105 | } 106 | 107 | memset(&rinfo, 0, sizeof(rinfo)); 108 | rinfo.report_type = HID_REPORT_TYPE_OUTPUT; 109 | rinfo.report_id = 0x10; 110 | rinfo.num_fields = 1; 111 | err = ioctl(fd, HIDIOCSREPORT, &rinfo); 112 | 113 | return err; 114 | } 115 | 116 | void send_msg(int fd, const unsigned char c0, 117 | const unsigned char c1, 118 | const unsigned char c2, 119 | const unsigned char c3, 120 | const unsigned char c4, 121 | const unsigned char c5) 122 | { 123 | unsigned char b[6]; 124 | b[0]=c0; 125 | b[1]=c1; 126 | b[2]=c2; 127 | b[3]=c3; 128 | b[4]=c4; 129 | b[5]=c5; 130 | if(send_report(fd,b,6)<0) 131 | { 132 | perror("error sending to device"); 133 | close(fd); 134 | exit(1); 135 | } 136 | } 137 | /*modified send_msg since G500 also uses a 20 byte long buffer*/ 138 | void send_msg20(int fd, const unsigned char c0, 139 | const unsigned char c1, 140 | const unsigned char c2, 141 | const unsigned char c3, 142 | const unsigned char c4, 143 | const unsigned char c5, 144 | const unsigned char c6, 145 | const unsigned char c7, 146 | const unsigned char c8, 147 | const unsigned char c9, 148 | const unsigned char c10, 149 | const unsigned char c11, 150 | const unsigned char c12, 151 | const unsigned char c13, 152 | const unsigned char c14, 153 | const unsigned char c15, 154 | const unsigned char c16, 155 | const unsigned char c17, 156 | const unsigned char c18 ) 157 | { 158 | unsigned char b[19]; 159 | b[0]=c0; 160 | b[1]=c1; 161 | b[2]=c2; 162 | b[3]=c3; 163 | b[4]=c4; 164 | b[5]=c5; 165 | b[6]=c6; 166 | b[7]=c7; 167 | b[8]=c8; 168 | b[9]=c9; 169 | b[10]=c10; 170 | b[11]=c11; 171 | b[12]=c12; 172 | b[13]=c13; 173 | b[14]=c14; 174 | b[15]=c15; 175 | b[16]=c16; 176 | b[17]=c17; 177 | b[18]=c18; 178 | if(send_report20(fd,b,19)<0) 179 | { 180 | perror("error sending to device"); 181 | close(fd); 182 | exit(1); 183 | } 184 | } 185 | 186 | /* function borrowed from http://www.lomoco.org/vx_hack.c */ 187 | static int query_report(int fd, int id, unsigned int *buf, size_t size) { 188 | struct hiddev_usage_ref_multi uref; 189 | struct hiddev_report_info rinfo; 190 | int i = 0, rc = -1; 191 | 192 | rinfo.report_type = HID_REPORT_TYPE_INPUT; 193 | rinfo.report_id = id; 194 | rinfo.num_fields = 1; 195 | rc = ioctl(fd, HIDIOCGREPORT, &rinfo); 196 | if (rc < 0) { 197 | perror("HIDIOCGREPORT"); 198 | return rc; 199 | } 200 | 201 | uref.uref.report_type = HID_REPORT_TYPE_INPUT; 202 | uref.uref.report_id = id; 203 | uref.uref.field_index = 0; 204 | uref.uref.usage_index = 0; 205 | uref.num_values = size; 206 | rc = ioctl(fd, HIDIOCGUSAGES, &uref); 207 | if (rc < 0) { 208 | perror("HIDIOCGUSAGES"); 209 | return rc; 210 | } 211 | 212 | for (i = 0; i < size; i++) { 213 | buf[i] = uref.values[i]; 214 | } 215 | 216 | return rc; 217 | } 218 | 219 | /* new function hid_reply to check G500's replies. Contains code from vx_hack.c*/ 220 | void hid_reply(int fd) { 221 | unsigned int buf[6] = {0}; 222 | int i; 223 | if (query_report(fd, 0x10, buf, 6) < 0) { 224 | perror("query failed"); 225 | close(fd); 226 | exit(1); 227 | } 228 | printf("query result: "); 229 | for (i = 0; i < 6; i++) { 230 | printf(" %02x", buf[i]); 231 | } 232 | printf("\n"); 233 | } 234 | 235 | void g500_reply (int fd, const int debug_infos) { 236 | /* g500_reply(0) simply gives the mouse enough time to proceed the recieved information 237 | g500_reply(1) displays G500's reply to the recieved information */ 238 | struct timespec req = {0,0}; 239 | req.tv_sec = 0; 240 | req.tv_nsec = 100000000L; 241 | nanosleep(&req, (struct timespec *)NULL); 242 | if (debug_infos!=0) 243 | hid_reply(fd); 244 | 245 | } 246 | 247 | int dpi_convert (const int dpi_value) { 248 | int dpi_hex=0; 249 | if ((dpi_value!=0) && (200 <=dpi_value) && (dpi_value <= 5700) && (dpi_value % 100 == 0) ) { 250 | int rest = dpi_value % 400; 251 | int add_value=0; 252 | switch (rest){ 253 | case 0: 254 | add_value=0; 255 | break; 256 | case 100: 257 | add_value=4; 258 | break; 259 | case 200: 260 | add_value=9; 261 | break; 262 | case 300: 263 | add_value=13; 264 | break; 265 | default: 266 | printf("%i is not a valid DPI value",dpi_value); 267 | exit(1); 268 | } 269 | dpi_hex = (dpi_value/400)*17+add_value; 270 | } 271 | else { 272 | printf("%i is not a valid DPI value",dpi_value); 273 | exit(1); 274 | } 275 | return dpi_hex; 276 | } 277 | void display_help() { 278 | printf("Usage: g500_control HIDDEVICE URR AS DPI_MODE OPTIONS\n\n"); 279 | printf("Please note that all arguments are necessary!\n"); 280 | printf("The number of parameters in OPTIONS depends on the DPI_MODE you choose.\n"); 281 | printf("The only exception is that when using --dpi_default for DPI_MODE, you don't need OPTIONS at all.\n"); 282 | printf("If you get a 'hiddev open: Permission denied' error, run g500_control with sudo.\n\n"); 283 | printf("HIDDEVICE - probably /dev/usb/hiddev0 or /dev/hidraw0\n"); 284 | printf("URR - set G500's USB report rate\n"); 285 | printf(" --urr_default Set USB report rate equal 500 which is G500's default behavior\n"); 286 | printf(" --125 Set USB report rate equal 125\n"); 287 | printf(" --200 Set USB report rate equal 200\n"); 288 | printf(" --250 Set USB report rate equal 250\n"); 289 | printf(" --333 Set USB report rate equal 333\n"); 290 | printf(" --500 Set USB report rate equal 500\n"); 291 | printf(" --1000 Set USB report rate equal 1000\n"); 292 | printf("AS - enable or disable angle snapping for drawing perfectly straight lines\n"); 293 | printf(" --as_default Disable angle snapping which is G500's default behavior\n"); 294 | printf(" --as_on Enable angle snapping\n"); 295 | printf(" --as_off Disable angle snapping\n"); 296 | printf("DPI_MODE - choose the DPI mode\n"); 297 | printf(" --dpi_default Use three different dpi resolutions: 400, 800 and 2000 dpi.\n"); 298 | printf(" Use dpi buttons to switch between different dpi values\n"); 299 | printf(" which is G500's default behavior\n"); 300 | printf(" --dpi_1 Use one dpi resolution and allow dpi buttons to be used as\n"); 301 | printf(" normal buttons. They become visible in xev and can be mapped\n"); 302 | printf(" to something useful via xbindkeys or other X-Window tools\n"); 303 | printf(" --dpi_2 Use two different dpi resolutions. Use dpi buttons to\n"); 304 | printf(" switch between different dpi values\n"); 305 | printf(" --dpi_3 Use three different dpi resolutions. Use dpi buttons to\n"); 306 | printf(" switch between different dpi values\n"); 307 | printf(" --dpi_4 Use four different dpi resolutions. Use dpi buttons to\n"); 308 | printf(" switch between different dpi values\n"); 309 | printf(" --dpi_5 Use five different dpi resolutions. Use dpi buttons to\n"); 310 | printf(" switch between different dpi values\n"); 311 | printf("OPTIONS - set options according to the chosen DPI mode\n"); 312 | printf(" For dpi_default no additional options are needed\n"); 313 | printf(" For dpi_1 following options must be set\n"); 314 | printf(" dpi_x specify dpi resolution for the x axis. Valid values range from \n"); 315 | printf(" 200 to 5700 in 100 dpi steps, e.g. 200, 300, 400, 500, 600 etc.\n"); 316 | printf(" dpi_y specify dpi resolution for the y axis. Valid values range from\n"); 317 | printf(" 200 to 5700 in 100 dpi steps, e.g. 200, 300, 400, 500, 600 etc.\n"); 318 | printf(" For dpi_2 following options must be set\n"); 319 | printf(" dpi_1_x specify 1st dpi resolution for the x axis.\n"); 320 | printf(" dpi_1_y specify 1st dpi resolution for the y axis.\n"); 321 | printf(" dpi_2_x specify 2nd dpi resolution for the x axis.\n"); 322 | printf(" dpi_2_y specify 2nd dpi resolution for the y axis.\n"); 323 | printf(" dpi_btn specify whether +/- (on the upper side of the mouse) or \n"); 324 | printf(" forwards/backwards (on the left side of the mouse) buttons act as dpi\n"); 325 | printf(" buttons. Valid values are dpi_btn_up and dpi_btn_side.\n"); 326 | printf(" For dpi_3 following options must be set\n"); 327 | printf(" dpi_1_x specify 1st dpi resolution for the x axis.\n"); 328 | printf(" dpi_1_y specify 1st dpi resolution for the y axis.\n"); 329 | printf(" dpi_2_x specify 2nd dpi resolution for the x axis.\n"); 330 | printf(" dpi_2_y specify 2nd dpi resolution for the y axis.\n"); 331 | printf(" dpi_3_x specify 3rd dpi resolution for the x axis.\n"); 332 | printf(" dpi_3_y specify 3rd dpi resolution for the y axis.\n"); 333 | printf(" dpi_btn specify whether +/- (on the upper side of the mouse) or \n"); 334 | printf(" forwards/backwards (on the left side of the mouse) buttons act as dpi\n"); 335 | printf(" buttons. Valid values are dpi_btn_up and dpi_btn_side.\n"); 336 | printf(" For dpi_4 following options must be set\n"); 337 | printf(" dpi_1_x specify 1st dpi resolution for the x axis.\n"); 338 | printf(" dpi_1_y specify 1st dpi resolution for the y axis.\n"); 339 | printf(" dpi_2_x specify 2nd dpi resolution for the x axis.\n"); 340 | printf(" dpi_2_y specify 2nd dpi resolution for the y axis.\n"); 341 | printf(" dpi_3_x specify 3rd dpi resolution for the x axis.\n"); 342 | printf(" dpi_3_y specify 3rd dpi resolution for the y axis.\n"); 343 | printf(" dpi_4_x specify 4th dpi resolution for the x axis.\n"); 344 | printf(" dpi_4_y specify 4th dpi resolution for the y axis.\n"); 345 | printf(" dpi_btn specify whether +/- (on the upper side of the mouse) or \n"); 346 | printf(" forwards/backwards (on the left side of the mouse) buttons act as dpi\n"); 347 | printf(" buttons. Valid values are dpi_btn_up and dpi_btn_side.\n"); 348 | printf(" For dpi_5 following options must be set\n"); 349 | printf(" dpi_1_x specify 1st dpi resolution for the x axis.\n"); 350 | printf(" dpi_1_y specify 1st dpi resolution for the y axis.\n"); 351 | printf(" dpi_2_x specify 2nd dpi resolution for the x axis.\n"); 352 | printf(" dpi_2_y specify 2nd dpi resolution for the y axis.\n"); 353 | printf(" dpi_3_x specify 3rd dpi resolution for the x axis.\n"); 354 | printf(" dpi_3_y specify 3rd dpi resolution for the y axis.\n"); 355 | printf(" dpi_4_x specify 4th dpi resolution for the x axis.\n"); 356 | printf(" dpi_4_y specify 4th dpi resolution for the y axis.\n"); 357 | printf(" dpi_5_x specify 5th dpi resolution for the x axis.\n"); 358 | printf(" dpi_5_y specify 5th dpi resolution for the y axis.\n\n"); 359 | printf(" dpi_btn specify whether +/- (on the upper side of the mouse) or \n"); 360 | printf(" forwards/backwards (on the left side of the mouse) buttons act as dpi\n"); 361 | printf(" buttons. Valid values are dpi_btn_up and dpi_btn_side.\n"); 362 | printf("Examples:\n"); 363 | printf(" ./g500_control /dev/usb/hiddev0 --urr_default --as_default --dpi_default\n"); 364 | printf(" this corresponds to G500's factory settings with 500 USB report rate,\n"); 365 | printf(" angle snapping disabled and 3 dpi resolutions (400, 800 and 2000).\n"); 366 | printf(" dpi buttons are used to switch between the 3 dpi values.\n"); 367 | printf(" ./g500_control /dev/usb/hiddev0 --urr_default --as_default --dpi_1 1600 1600\n"); 368 | printf(" here, only one dpi resolution (1600 dpi for both axes) is set. dpi buttons\n"); 369 | printf(" can be mapped to anything you want via xbindkeys or similar tools.\n"); 370 | printf(" ./g500_control /dev/usb/hiddev0 --1000 --as_on --dpi_1 1600 1600\n"); 371 | printf(" same as above, but now we increase USB report rate from 500 to 1000 and\n"); 372 | printf(" enable angle snapping.\n"); 373 | printf(" ./g500_control /dev/usb/hiddev0 --1000 --as_on --dpi_1 3200 4000\n"); 374 | printf(" same as above, but now we use different dpi resolutions for each axis.\n"); 375 | printf(" for the x axis it's 3200 and for the y axis it's 4000.\n"); 376 | printf(" ./g500_control /dev/usb/hiddev0 --500 --as_off --dpi_3 800 800 1600 1600 5700 5700 dpi_btn_up\n"); 377 | printf(" here, we set 3 different dpi resolutions: 800, 1600 and 5700 (equal for both axes).\n"); 378 | printf(" The dpi buttons (+/-) are used to switch between these. Moreover, we explicitly set USB\n"); 379 | printf(" repeat rate to 500 and disable angle snapping\n"); 380 | printf(" ./g500_control /dev/usb/hiddev0 --500 --as_off --dpi_3 800 800 1600 1600 5700 5700 dpi_btn_side\n"); 381 | printf(" same as above but here we use (<-/->) as dpi buttons.\n"); 382 | printf(" ./g500_control /dev/usb/hiddev0 --333 --as_on --dpi_5 800 800 1600 1600 3200 3200 4800 4800 5700 5700 dpi_btn_up\n"); 383 | printf(" here, we set 5 different dpi resolutions: 800, 1600, 3200, 4800 and 5700\n"); 384 | printf(" (equal for both axes). The dpi buttons (+/-) are used to switch between these. \n"); 385 | printf(" Moreover, we explicitly set USB repeat rate to 333 and enable angle snapping\n"); 386 | printf(" ./g500_control /dev/usb/hiddev0 --333 --as_on --dpi_5 800 800 1600 1000 3200 3200 4800 4800 5700 5700 dpi_btn_up\n"); 387 | printf(" similar to the above, but the second resolution has now different values for the axes:\n"); 388 | printf(" 1600 dpi for the x axis and 1000 dpi for the y axis.\n"); 389 | } 390 | 391 | 392 | 393 | 394 | int main (int argc, char **argv) { 395 | int fd = -1; 396 | int version; 397 | struct hiddev_devinfo device_info; 398 | 399 | int urr=0x02; 400 | int as=0x01; 401 | int dpi_1_x=0; 402 | int dpi_1_y=0; 403 | int dpi_2_x=0; 404 | int dpi_2_y=0; 405 | int dpi_3_x=0; 406 | int dpi_3_y=0; 407 | int dpi_4_x=0; 408 | int dpi_4_y=0; 409 | int dpi_5_x=0; 410 | int dpi_5_y=0; 411 | int dpi_btn_1=0; 412 | int dpi_btn_2=0; 413 | int dpi_btn_3=0; 414 | int dpi_btn_4=0; 415 | int dpi_btn_5=0; 416 | int dpi_btn_6=0; 417 | int dpi_btn_7=0; 418 | int dpi_btn_8=0; 419 | int dpi_btn_9=0; 420 | int md_1=0; 421 | int md_2=0; 422 | int md_3=0; 423 | int md_4=0; 424 | int md_5=0; 425 | int md_7=0; 426 | int md_8=0; 427 | int md_9=0; 428 | int md_10=0; 429 | 430 | 431 | 432 | printf("\n"); 433 | printf("%c[%d;%d;%dmWARNING!", 0x1B, 1,31,40); 434 | printf("THIS MAY POTENTIALLY BRICK YOUR LOGITECH G500 MOUSE,\n"); 435 | printf("SO USE IT ON YOUR OWN RISK! NO LIABILITY FOR ANY DIRECT OR INDIRECT DAMAGE CAUSED\n"); 436 | printf("BY USING THIS PROGRAM IS ACCEPTED!\n"); 437 | printf("%c[%dm\n", 0x1B, 0); 438 | printf("g500_control %s is based on Andreas Schneider's g_hack.c and\n", VERSION); 439 | printf("allows you to change Logitech G500's internal profile under Linux\n\n"); 440 | 441 | if (argc==1) { 442 | display_help(); 443 | exit(1); 444 | } 445 | 446 | else if (((argc>1) && (argc < 5)) || (argc>16)) { 447 | fprintf(stderr,"g500_control error: too many or too little arguments!\n"); 448 | printf("To display help run g500_control without any arguments.\n"); 449 | exit(1); 450 | } 451 | 452 | /* ioctl() requires a file descriptor, so we check we got one, and then open it */ 453 | if ((fd = open(argv[1], O_RDONLY)) < 0) { 454 | perror("hiddev open"); 455 | printf("%s is not a mouse!\n",argv[1]); 456 | exit(1); 457 | } 458 | /* ioctl() accesses the underlying driver */ 459 | ioctl(fd, HIDIOCGVERSION, &version); 460 | 461 | /* the HIDIOCGVERSION ioctl() returns an int so we unpack it and display it we create a patch */ 462 | printf("hiddev driver version is %d.%d.%d\n", version >> 16, (version >> 8) & 0xff, version & 0xff); 463 | 464 | /* suck out some device information */ 465 | ioctl(fd, HIDIOCGDEVINFO, &device_info); 466 | 467 | /* the HIDIOCGDEVINFO ioctl() returns hiddev_devinfo 468 | * structure - see 469 | * So we work through the various elements, displaying 470 | * each of them 471 | */ 472 | printf("vendor 0x%04hx product 0x%04hx version 0x%04hx ", 473 | device_info.vendor, device_info.product, device_info.version); 474 | printf("has %i application%s ", device_info.num_applications, (device_info.num_applications==1?"":"s")); 475 | printf("and is on bus: %d devnum: %d ifnum: %d\n", device_info.busnum, device_info.devnum, device_info.ifnum); 476 | /* We have a G500? */ 477 | if((device_info.vendor == (short)VENDOR) && (device_info.product == (short)MOUSE_G500)) { 478 | printf("Logitech G500 Gaming Mouse detected!\n"); 479 | 480 | if (ioctl(fd, HIDIOCINITREPORT, 0) < 0) { 481 | perror("hid report init failed"); 482 | exit(1); 483 | } 484 | 485 | /* Checking the input parameters and setting the appropriate registers */ 486 | 487 | if ((strcmp(argv[2],"--125") == 0) || (strcmp(argv[2],"--200") == 0) || (strcmp(argv[2],"--250") == 0) || 488 | (strcmp(argv[2],"--333") == 0) || (strcmp(argv[2],"--500") == 0) || (strcmp(argv[2],"--1000") == 0) || 489 | (strcmp(argv[2],"--urr_default") == 0)) { 490 | if (strcmp(argv[2],"--125") == 0) 491 | urr=0x08; 492 | else if (strcmp(argv[2],"--200") == 0) 493 | urr=0x05; 494 | else if (strcmp(argv[2],"--250") == 0) 495 | urr=0x04; 496 | else if (strcmp(argv[2],"--333") == 0) 497 | urr=0x03; 498 | else if ((strcmp(argv[2],"--500") == 0) || (strcmp(argv[2],"--urr_default") == 0)) 499 | urr=0x02; 500 | else if (strcmp(argv[2],"--1000") == 0) 501 | urr=0x01; 502 | } 503 | else { 504 | printf("%s is not a valid URR value!\n",argv[2]); 505 | exit(1); 506 | } 507 | 508 | if ((strcmp(argv[3],"--as_on") == 0) || (strcmp(argv[3],"--as_off") == 0) || (strcmp(argv[3],"--as_default") == 0)) { 509 | if (strcmp(argv[3],"--as_on") == 0) 510 | as=0x02; 511 | else if ((strcmp(argv[3],"--as_off") == 0) || (strcmp(argv[3],"--as_default") == 0)) 512 | as=0x01; 513 | } 514 | else { 515 | printf("%s is not a valid AS value!\n",argv[3]); 516 | exit(1); 517 | } 518 | 519 | if ((strcmp(argv[4],"--dpi_1") == 0) || (strcmp(argv[4],"--dpi_2") == 0) || (strcmp(argv[4],"--dpi_3") == 0) || 520 | (strcmp(argv[4],"--dpi_4") == 0) || (strcmp(argv[4],"--dpi_5") == 0) || (strcmp(argv[4],"--dpi_default") == 0)) { 521 | if (strcmp(argv[4],"--dpi_default") == 0) { 522 | if (argc==5) { 523 | dpi_1_x=dpi_convert(400); 524 | dpi_1_y=dpi_convert(400); 525 | dpi_2_x=dpi_convert(800); 526 | dpi_2_y=dpi_convert(800); 527 | dpi_3_x=dpi_convert(2000); 528 | dpi_3_y=dpi_convert(2000); 529 | md_1=0x22; 530 | md_2=0x12; 531 | md_3=0x22; 532 | md_4=0x22; 533 | md_5=0x01; 534 | md_7=0x80; 535 | 536 | dpi_btn_1=0x83; 537 | dpi_btn_2=0x04; 538 | dpi_btn_3=0x00; 539 | dpi_btn_4=0x83; 540 | dpi_btn_5=0x08; 541 | dpi_btn_6=0x00; 542 | dpi_btn_7=0x81; 543 | dpi_btn_8=0x81; 544 | dpi_btn_9=0x10; 545 | 546 | } 547 | else { 548 | printf("Too much or too little parameters for the %s mode",argv[4]); 549 | exit(1); 550 | } 551 | } 552 | 553 | else if (strcmp(argv[4],"--dpi_1") == 0) { 554 | if (argc==7) { 555 | dpi_1_x=dpi_convert(atoi(argv[5])); 556 | dpi_1_y=dpi_convert(atoi(argv[6])); 557 | dpi_btn_1=0x81; 558 | dpi_btn_2=0x00; 559 | dpi_btn_3=0x01; 560 | dpi_btn_4=0x81; 561 | dpi_btn_5=0x00; 562 | dpi_btn_6=0x02; 563 | dpi_btn_7=0x81; 564 | dpi_btn_8=0x81; 565 | dpi_btn_9=0x10; 566 | } 567 | else { 568 | printf("Too much or too little parameters for the %s mode",argv[4]); 569 | exit(1); 570 | } 571 | } 572 | 573 | else if (strcmp(argv[4],"--dpi_2") == 0) { 574 | if (argc==10) { 575 | dpi_1_x=dpi_convert(atoi(argv[5])); 576 | dpi_1_y=dpi_convert(atoi(argv[6])); 577 | dpi_2_x=dpi_convert(atoi(argv[7])); 578 | dpi_2_y=dpi_convert(atoi(argv[8])); 579 | 580 | if ((strcmp(argv[9],"dpi_btn_up") == 0) || (strcmp(argv[9],"dpi_btn_left") == 0)) { 581 | if (strcmp(argv[9],"dpi_btn_up") == 0) { 582 | dpi_btn_1=0x83; 583 | dpi_btn_2=0x04; 584 | dpi_btn_3=0x00; 585 | dpi_btn_4=0x83; 586 | dpi_btn_5=0x08; 587 | dpi_btn_6=0x00; 588 | dpi_btn_7=0x81; 589 | dpi_btn_8=0x81; 590 | dpi_btn_9=0x10; 591 | } 592 | else if (strcmp(argv[9],"dpi_btn_left") == 0) { 593 | dpi_btn_1=0x81; 594 | dpi_btn_2=0x00; 595 | dpi_btn_3=0x01; 596 | dpi_btn_4=0x81; 597 | dpi_btn_5=0x00; 598 | dpi_btn_6=0x02; 599 | dpi_btn_7=0x83; 600 | dpi_btn_8=0x83; 601 | dpi_btn_9=0x04; 602 | } 603 | } 604 | else { 605 | printf("%s is not a valid dpi button parameter",argv[9]); 606 | exit(1); 607 | } 608 | md_1=0x22; 609 | md_2=0x12; 610 | md_5=0x01; 611 | 612 | } 613 | else { 614 | printf("Too much or too little parameters for the %s mode",argv[4]); 615 | exit(1); 616 | } 617 | } 618 | 619 | else if (strcmp(argv[4],"--dpi_3") == 0) { 620 | if (argc==12) { 621 | dpi_1_x=dpi_convert(atoi(argv[5])); 622 | dpi_1_y=dpi_convert(atoi(argv[6])); 623 | dpi_2_x=dpi_convert(atoi(argv[7])); 624 | dpi_2_y=dpi_convert(atoi(argv[8])); 625 | dpi_3_x=dpi_convert(atoi(argv[9])); 626 | dpi_3_y=dpi_convert(atoi(argv[10])); 627 | 628 | if ((strcmp(argv[11],"dpi_btn_up") == 0) || (strcmp(argv[11],"dpi_btn_left") == 0)) { 629 | if (strcmp(argv[11],"dpi_btn_up") == 0) { 630 | dpi_btn_1=0x83; 631 | dpi_btn_2=0x04; 632 | dpi_btn_3=0x00; 633 | dpi_btn_4=0x83; 634 | dpi_btn_5=0x08; 635 | dpi_btn_6=0x00; 636 | dpi_btn_7=0x81; 637 | dpi_btn_8=0x81; 638 | dpi_btn_9=0x10; 639 | } 640 | else if (strcmp(argv[11],"dpi_btn_left") == 0) { 641 | dpi_btn_1=0x81; 642 | dpi_btn_2=0x00; 643 | dpi_btn_3=0x01; 644 | dpi_btn_4=0x81; 645 | dpi_btn_5=0x00; 646 | dpi_btn_6=0x02; 647 | dpi_btn_7=0x83; 648 | dpi_btn_8=0x83; 649 | dpi_btn_9=0x04; 650 | } 651 | } 652 | else { 653 | printf("%s is not a valid dpi button parameter",argv[11]); 654 | exit(1); 655 | } 656 | md_1=0x22; 657 | md_2=0x12; 658 | md_3=0x22; 659 | md_4=0x22; 660 | md_5=0x01; 661 | md_7=0x80; 662 | } 663 | else { 664 | printf("Too much or too little parameters for the %s mode",argv[4]); 665 | exit(1); 666 | } 667 | } 668 | 669 | else if (strcmp(argv[4],"--dpi_4") == 0) { 670 | if (argc==14) { 671 | dpi_1_x=dpi_convert(atoi(argv[5])); 672 | dpi_1_y=dpi_convert(atoi(argv[6])); 673 | dpi_2_x=dpi_convert(atoi(argv[7])); 674 | dpi_2_y=dpi_convert(atoi(argv[8])); 675 | dpi_3_x=dpi_convert(atoi(argv[9])); 676 | dpi_3_y=dpi_convert(atoi(argv[10])); 677 | dpi_4_x=dpi_convert(atoi(argv[11])); 678 | dpi_4_y=dpi_convert(atoi(argv[12])); 679 | if ((strcmp(argv[13],"dpi_btn_up") == 0) || (strcmp(argv[13],"dpi_btn_left") == 0)) { 680 | if (strcmp(argv[13],"dpi_btn_up") == 0) { 681 | dpi_btn_1=0x83; 682 | dpi_btn_2=0x04; 683 | dpi_btn_3=0x00; 684 | dpi_btn_4=0x83; 685 | dpi_btn_5=0x08; 686 | dpi_btn_6=0x00; 687 | dpi_btn_7=0x81; 688 | dpi_btn_8=0x81; 689 | dpi_btn_9=0x10; 690 | } 691 | else if (strcmp(argv[13],"dpi_btn_left") == 0) { 692 | dpi_btn_1=0x81; 693 | dpi_btn_2=0x00; 694 | dpi_btn_3=0x01; 695 | dpi_btn_4=0x81; 696 | dpi_btn_5=0x00; 697 | dpi_btn_6=0x02; 698 | dpi_btn_7=0x83; 699 | dpi_btn_8=0x83; 700 | dpi_btn_9=0x04; 701 | } 702 | } 703 | else { 704 | printf("%s is not a valid dpi button parameter",argv[13]); 705 | exit(1); 706 | } 707 | md_1=0x22; 708 | md_2=0x12; 709 | md_3=0x22; 710 | md_4=0x22; 711 | md_5=0x01; 712 | md_7=0x12; 713 | md_8=0x22; 714 | } 715 | else { 716 | printf("Too much or too little parameters for the %s mode",argv[4]); 717 | exit(1); 718 | } 719 | } 720 | 721 | else if (strcmp(argv[4],"--dpi_5") == 0) { 722 | if (argc==16) { 723 | dpi_1_x=dpi_convert(atoi(argv[5])); 724 | dpi_1_y=dpi_convert(atoi(argv[6])); 725 | dpi_2_x=dpi_convert(atoi(argv[7])); 726 | dpi_2_y=dpi_convert(atoi(argv[8])); 727 | dpi_3_x=dpi_convert(atoi(argv[9])); 728 | dpi_3_y=dpi_convert(atoi(argv[10])); 729 | dpi_4_x=dpi_convert(atoi(argv[11])); 730 | dpi_4_y=dpi_convert(atoi(argv[12])); 731 | dpi_5_x=dpi_convert(atoi(argv[13])); 732 | dpi_5_y=dpi_convert(atoi(argv[14])); 733 | if ((strcmp(argv[15],"dpi_btn_up") == 0) || (strcmp(argv[15],"dpi_btn_left") == 0)) { 734 | if (strcmp(argv[15],"dpi_btn_up") == 0) { 735 | dpi_btn_1=0x83; 736 | dpi_btn_2=0x04; 737 | dpi_btn_3=0x00; 738 | dpi_btn_4=0x83; 739 | dpi_btn_5=0x08; 740 | dpi_btn_6=0x00; 741 | dpi_btn_7=0x81; 742 | dpi_btn_8=0x81; 743 | dpi_btn_9=0x10; 744 | } 745 | else if (strcmp(argv[15],"dpi_btn_left") == 0) { 746 | dpi_btn_1=0x81; 747 | dpi_btn_2=0x00; 748 | dpi_btn_3=0x01; 749 | dpi_btn_4=0x81; 750 | dpi_btn_5=0x00; 751 | dpi_btn_6=0x02; 752 | dpi_btn_7=0x83; 753 | dpi_btn_8=0x83; 754 | dpi_btn_9=0x04; 755 | } 756 | } 757 | else { 758 | printf("%s is not a valid dpi button parameter",argv[15]); 759 | exit(1); 760 | } 761 | md_1=0x22; 762 | md_2=0x12; 763 | md_3=0x22; 764 | md_4=0x22; 765 | md_5=0x01; 766 | md_7=0x12; 767 | md_8=0x22; 768 | md_9=0x12; 769 | md_10=0x21; 770 | } 771 | else { 772 | printf("Too much or too little parameters for the %s mode",argv[4]); 773 | exit(1); 774 | } 775 | } 776 | } 777 | else { 778 | printf("%s is not a valid DPI_MODE value!\n",argv[4]); 779 | exit(1); 780 | } 781 | 782 | printf("Sending the initialization sequence ... "); 783 | /* This is the initialization sequence SetPoint sends to a G500 when you plug it into USB port. 784 | You can't flash a profile without sending this first. 785 | I'm not sure whether this sequence is universal for all G500's or differs from mouse to mouse. This 786 | is what I get with SetPoint 6.20 and my G500 (P/N 810-001240, M/N M-U0010) */ 787 | send_msg(fd,0x00,0x80,0xa1,0x01,0x00,0x02); 788 | g500_reply(fd,DEBUG_INFOS); 789 | send_msg(fd,0x00,0x83,0xa2,0x01,0x80,0x00); 790 | g500_reply(fd,DEBUG_INFOS); 791 | send_msg(fd,0x00,0x83,0xa2,0x01,0x88,0x00); 792 | g500_reply(fd,DEBUG_INFOS); 793 | send_msg(fd,0x00,0x83,0xa2,0x01,0x80,0x00); 794 | g500_reply(fd,DEBUG_INFOS); 795 | send_msg(fd,0x00,0x83,0xa2,0x01,0x88,0x00); 796 | g500_reply(fd,DEBUG_INFOS); 797 | send_msg(fd,0x00,0x83,0xa2,0x01,0x80,0x00); 798 | g500_reply(fd,DEBUG_INFOS); 799 | send_msg(fd,0x00,0x81,0x0f,0x00,0x00,0x00); 800 | g500_reply(fd,DEBUG_INFOS); 801 | send_msg20(fd,0x00,0x82,0xa0,0x04,0x00,0x01,0x02,0x00,0x00,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); 802 | g500_reply(fd,DEBUG_INFOS); 803 | send_msg(fd,0x00,0x83,0xa2,0x00,0xa1,0x00); 804 | g500_reply(fd,DEBUG_INFOS); 805 | send_msg(fd,0x00,0x83,0xa2,0x00,0xa1,0x00); 806 | g500_reply(fd,DEBUG_INFOS); 807 | send_msg(fd,0x00,0x83,0x63,0x00,0x00,0x00); 808 | g500_reply(fd,DEBUG_INFOS); 809 | send_msg(fd,0x00,0x81,0x0f,0x00,0x00,0x00); 810 | g500_reply(fd,DEBUG_INFOS); 811 | send_msg(fd,0x00,0x80,0x0f,0x00,0x00,0x00); 812 | g500_reply(fd,DEBUG_INFOS); 813 | send_msg20(fd,0x00,0x90,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x4e,0x00,0x00,0xff,0x00,0x00,0x80,0x00,0x22,0x00); 814 | send_msg20(fd,0x00,0x91,0x01,0x22,0x22,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); 815 | send_msg20(fd,0x00,0x91,0x02,0x00,0x00,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x10,0x10,0x02); 816 | send_msg20(fd,0x00,0x91,0x03,0x81,0x01,0x00,0x81,0x02,0x00,0x81,0x04,0x00,0x81,0x08,0x00,0x81,0x10,0x00,0x81); 817 | send_msg20(fd,0x00,0x91,0x04,0x20,0x00,0x81,0x40,0x00,0x81,0x80,0x00,0x81,0x00,0x01,0x81,0x00,0x02,0x8f,0x00); 818 | send_msg20(fd,0x00,0x93,0x05,0x00,0x8f,0x00,0x00,0x8f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); 819 | g500_reply(fd,DEBUG_INFOS); 820 | send_msg(fd,0x00,0x80,0x0f,0x01,0x00,0x00); 821 | g500_reply(fd,DEBUG_INFOS); 822 | printf("done!\n"); 823 | 824 | /* This is the actual profile */ 825 | printf("Flashing new profile ... "); 826 | 827 | /* 1st part of the profile */ 828 | send_msg20(fd,0x00,0x82,0xa0,0x02,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00); 829 | g500_reply(fd,DEBUG_INFOS); 830 | send_msg20(fd,0x00,0x90,0x06,0x01,0x02,0x00,0x00,0x00,0x00,0x4e,0x00,0x00,0xff,0x00,0x00,0x80,0x00,dpi_1_x,0x00); 831 | send_msg20(fd,0x00,0x91,0x07,dpi_1_y,0x22,0x11,0x00,dpi_2_x,0x00,dpi_2_y,md_1,md_2,0x00,dpi_3_x,0x00,dpi_3_y,md_3,md_4,0x00); 832 | send_msg20(fd,0x00,0x91,0x08,dpi_4_x,0x00,dpi_4_y,md_7,md_8,0x00,dpi_5_x,0x00,dpi_5_y,md_9,md_10,as,md_5,0x10,0x10,urr); 833 | send_msg20(fd,0x00,0x91,0x09,0x81,0x01,0x00,0x81,0x02,0x00,0x81,0x04,0x00,dpi_btn_7,0x08,0x00,dpi_btn_8,dpi_btn_9,0x00,0x81); 834 | send_msg20(fd,0x00,0x91,0x0a,0x20,0x00,0x83,0x01,0x00,0x83,0x02,0x00,dpi_btn_1,dpi_btn_2,dpi_btn_3,dpi_btn_4,dpi_btn_5,dpi_btn_6,0x8f,0x00); 835 | send_msg20(fd,0x00,0x93,0x0b,0x00,0x8f,0x00,0x00,0x8f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); 836 | g500_reply(fd,DEBUG_INFOS); 837 | send_msg20(fd,0x00,0x92,0x0c,0x01,0x02,0xff,0x00,0x00,0x00,0x02,0x00,0x00,0x79,0x13,0x00,0x00,0x00,0x00,0x00); 838 | g500_reply(fd,DEBUG_INFOS); 839 | send_msg(fd,0x00,0x83,0x63,0x00,0x00,0x00); 840 | g500_reply(fd,DEBUG_INFOS); 841 | send_msg(fd,0x00,0x80,0x0f,0x00,0x00,0x00); 842 | /* 2nd part of the profile */ 843 | g500_reply(fd,DEBUG_INFOS); 844 | send_msg20(fd,0x00,0x90,0x0d,0x01,0x00,0x00,0x00,0x00,0x00,0x4e,0x00,0x00,0xff,0x00,0x00,0x80,0x00,dpi_1_x,0x00); 845 | send_msg20(fd,0x00,0x91,0x0e,dpi_1_y,0x22,0x11,0x00,dpi_2_x,0x00,dpi_2_y,md_1,md_2,0x00,dpi_3_x,0x00,dpi_3_y,md_3,md_4,0x00); 846 | send_msg20(fd,0x00,0x91,0x0f,dpi_4_x,0x00,dpi_4_y,md_7,md_8,0x00,dpi_5_x,0x00,dpi_5_y,md_9,md_10,as,md_5,0x10,0x10,urr); 847 | send_msg20(fd,0x00,0x91,0x10,0x81,0x01,0x00,0x81,0x02,0x00,0x81,0x04,0x00,dpi_btn_7,0x08,0x00,dpi_btn_8,dpi_btn_9,0x00,0x81); 848 | send_msg20(fd,0x00,0x91,0x11,0x20,0x00,0x81,0x40,0x00,0x81,0x80,0x00,dpi_btn_1,dpi_btn_2,dpi_btn_3,dpi_btn_4,dpi_btn_5,dpi_btn_6,0x8f,0x00); 849 | send_msg20(fd,0x00,0x93,0x12,0x00,0x8f,0x00,0x00,0x8f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00); 850 | g500_reply(fd,DEBUG_INFOS); 851 | send_msg(fd,0x00,0x80,0x0f,0x01,0x00,0x00); 852 | printf ("done!\n"); 853 | } 854 | else 855 | printf("No G500 found! This program works only with Logitech G500!\n"); 856 | close(fd); 857 | exit(0); 858 | } 859 | 860 | #endif /* G500_CONTROL */ 861 | -------------------------------------------------------------------------------- /g500-control.h: -------------------------------------------------------------------------------- 1 | #ifndef G500_CONTROL_H 2 | #define G500_CONTROL_H 3 | 4 | 5 | 6 | #define VERSION "0.0.2" 7 | 8 | #define VENDOR 0x046d 9 | 10 | /* means that we are not interested what G500 replies to the information recieved */ 11 | /* for debugging purposes change this to 1 */ 12 | #define DEBUG_INFOS 0 13 | 14 | /* G500's signature*/ 15 | #define MOUSE_G500 0xc068 16 | 17 | static int send_report20(int fd, const unsigned char *buf, size_t size); 18 | 19 | static int send_report(int fd, const unsigned char *buf, size_t size); 20 | void send_msg(int fd, const unsigned char c0, 21 | const unsigned char c1, 22 | const unsigned char c2, 23 | const unsigned char c3, 24 | const unsigned char c4, 25 | const unsigned char c5); 26 | 27 | void send_msg20(int fd, const unsigned char c0, 28 | const unsigned char c1, 29 | const unsigned char c2, 30 | const unsigned char c3, 31 | const unsigned char c4, 32 | const unsigned char c5, 33 | const unsigned char c6, 34 | const unsigned char c7, 35 | const unsigned char c8, 36 | const unsigned char c9, 37 | const unsigned char c10, 38 | const unsigned char c11, 39 | const unsigned char c12, 40 | const unsigned char c13, 41 | const unsigned char c14, 42 | const unsigned char c15, 43 | const unsigned char c16, 44 | const unsigned char c17, 45 | const unsigned char c18 ); 46 | 47 | static int query_report(int fd, int id, unsigned int *buf, size_t size); 48 | void hid_reply(int fd); 49 | void g500_reply (int fd, const int debug_infos); 50 | int dpi_convert (const int dpi_value); 51 | void display_help(); 52 | 53 | 54 | #endif /* G500_CONTROL */ 55 | --------------------------------------------------------------------------------