Git Product home page Git Product logo

masterkeys-linux's Introduction

MasterKeys Linux SDK

Build Status License: GPL v3 PyPI version Documentation

Cooler Master provides an SDK for its MasterKeys series of keyboards for use under Windows, but not for Linux. The SDK communicates with an OUT-endpoint in the USB HID-device of the keyboard. This library aims to make this communication accessible from Linux by using libusb.

This is the first time I have written such a large project in C, let alone an actual shared library, so you may spot things that are bad practice, bugs or other issues. Please let me know in the issues section if you spot anything!

Disclaimer

This library is not endorsed or supported by Cooler Master Inc. or any of its affiliates. They have explicitly refused to help in the development of this library. There is no official support for this library from Cooler Master Inc. Any and all questions should be posted on the issues page.

Device support

As Cooler Master Inc. has not provided any support, this library can only support a limited amount of devices, specifically, it can only support devices for which the record executable target has been executed. This program uses the library to register an offset for each key, which is required for the library to be able to control individual keys. Effects and full lighting colors can be set regardless of these offsets.

The current list of supported devices includes:

  • MasterKeys Pro L RGB ANSI
  • MasterKeys Pro S RGB ANSI (untested)
  • MasterKeys Pro L RGB ISO (untested)

If you would like for your device to be supported as well, please run the record executable. Enter the row and column coordinates of each key according to the Cooler Master reference each time for the key that lights up in red. The shared layout.c can be attached to an issue, and then your device is added in no-time!

Keyboards with only monochrome lighting may use a different protocol and thus they would probably require more modifications than just adding a key layout matrix. Do not hesitate to open an issue if you have a monochrome keyboard, would like to see support and are willing to do some USB packet sniffing.

Compiling and installing

To be able to compile and install any of the targets in this library, cmake and its dependencies are required. Depending on your specific distribution, the name of the packages (if they are provided) may differ from the ones given here. The reference commands are for Ubuntu.

# libx11-dev is for the AmbiLight and notifications examples
# python3-gtk2.0 is for the notifications example
sudo apt-get install cmake libusb-1.0.0-dev libx11-dev
cd Source/masterkeys-linux  # Or wherever you have cloned the repo

# Builds library, utilities and C examples
# Exclude them from the file if you don't want them to be built
cmake .
make
sudo make install

# For the Python library (system-wide install) and Python examples
sudo python -m pip install scikit-build  # Needed for building
sudo python -m pip install PyGObject dbus-python # Notifications example
sudo python setup.py build install  # Python examples not installed

# Or if you would rather install from PyPI, still requires dependencies
sudo python -m pip install masterkeys

Wheels are not provided at this time because building manylinux wheels requires a different environment. It is considered as a possibility though. Until that time, it is possible to use the normal linux_x86_64 wheels provided on the releases-page.

Contributing

Pull Requests and contributions in other forms (such as issue reports) as well as tips or possible improvements are very welcome! As mentioned, this is my first C library, and any help is greatly appreciated! If it comes in the form of code, you will be credited for your work in the copyright notice.

If you would like for your device to be supported, please read the Device Support section of this file.

Given the small size of this project, there is no code of conduct or CONTRIBUTING.md with guidelines, but keep things professional. Also, use descriptive commit messages. Force pushing to forks while a PR is open is fine (as long as it does not completely remove the contributions).

License

MasterKeys Linux - C Library to control RGB keyboards
Copyright (C) 2018 RedFantom

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

Credits

Part of the implementation of the libmk library is based on the more extensive protocol description written by chmod222, available under the LGPLv3 license in libcmmk, which has the same goal as this project.

masterkeys-linux's People

Contributors

redfantom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

p1co ed00m dvash1

masterkeys-linux's Issues

Unable to compile: multiple definition of `LIBMK_MODEL_STRINGS'

Hi @RedFantom,
I'm on Fedora 33 and i got that compile error, both from github sources and pip sources.
This is the full output of setup.py:

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wvfldzt7/masterkeys/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wvfldzt7/masterkeys/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4wfkhqpw/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/masterkeys                                                                                                  
         cwd: /tmp/pip-install-wvfldzt7/masterkeys/                                                                                                                                                                                                                                                                        
    Complete output (112 lines):                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                           
    --------------------------------------------------------------------------------                                                                                                                                                                                                                                       
    -- Trying "Ninja" generator                                                                                                                                                                                                                                                                                            
    --------------------------------                                                                                                                                                                                                                                                                                       
    ---------------------------                                                                                                                                                                                                                                                                                            
    ----------------------                                                                                                                                                                                                                                                                                                 
    -----------------                                                                                                                                                                                                                                                                                                      
    ------------                                                                                                                                                                                                                                                                                                           
    -------                                                                                                                                                                                                                                                                                                                
    --                                                                                                                                                                                                                                                                                                                     
    Not searching for unused variables given on the command line.                                                                                                                                                                                                                                                          
    -- The C compiler identification is GNU 10.2.1                                                                                                                                                                                                                                                                         
    -- Detecting C compiler ABI info                                                                                                                                                                                                                                                                                       
    -- Detecting C compiler ABI info - done                                                                                                                                                                                                                                                                                
    -- Check for working C compiler: /usr/bin/cc - skipped                                                                                                                                                                                                                                                                 
    -- Detecting C compile features                                                                                                                                                                                                                                                                                        
    -- Detecting C compile features - done                                                                                                                                                                                                                                                                                 
    -- The CXX compiler identification is GNU 10.2.1                                                                                                                                                                                                                                                                       
    -- Detecting CXX compiler ABI info                                                                                                                                                                                                                                                                                     
    -- Detecting CXX compiler ABI info - done                                                                                                                                                                                                                                                                              
    -- Check for working CXX compiler: /usr/bin/c++ - skipped                                                                                                                                                                                                                                                              
    -- Detecting CXX compile features                                                                                                                                                                                                                                                                                      
    -- Detecting CXX compile features - done                                                                                                                                                                                                                                                                               
    -- Configuring done                                                                                                                                                                                                                                                                                                    
    -- Generating done                                                                                                                                                                                                                                                                                                     
    -- Build files have been written to: /tmp/pip-install-wvfldzt7/masterkeys/_cmake_test_compile/build                                                                                                                                                                                                                    
    --                                                                                                                                                                                                                                                                                                                     
    -------                                                                                                                                                                                                                                                                                                                
    ------------                                                                                                                                                                                                                                                                                                           
    -----------------                                                                                                                                                                                                                                                                                                      
    ----------------------                                                                                                                                                                                                                                                                                                 
    ---------------------------                                                                                                                                                                                                                                                                                            
    --------------------------------                                                                                                                                                                                                                                                                                       
    -- Trying "Ninja" generator - success                                                                                                                                                                                                                                                                                  
    --------------------------------------------------------------------------------                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                           
    Configuring Project                                                                                                                                                                                                                                                                                                    
      Working directory:                                                                                                                                                                                                                                                                                                   
        /tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-build                                                                                                                                                                                                                                         
      Command:
        cmake /tmp/pip-install-wvfldzt7/masterkeys -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-install -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python -DPYTHON_VERSION_STRING:STRING=3.9.0 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.9 -DPYTHON_LIBRARY:FILEPATH=/usr/lib64/libpython3.9.so -DSKBUILD:BOOL=TRUE -DCMAKE_MODULE_PATH:PATH=/usr/local/lib/python3.9/site-packages/skbuild/resources/cmake -DCMAKE_BUILD_TYPE:STRING=Release
    
    CMake Warning (dev) in CMakeLists.txt:
      No project() command is present.  The top-level CMakeLists.txt file must
      contain a literal, direct call to the project() command.  Add a line of
      code such as
    
        project(ProjectName)
    
      near the top of the file, but after cmake_minimum_required().
    
      CMake is pretending there is a "project(Project)" command on the first
      line.
    This warning is for project developers.  Use -Wno-dev to suppress it.
    
    -- The C compiler identification is GNU 10.2.1
    -- The CXX compiler identification is GNU 10.2.1
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Found PythonInterp: /usr/bin/python (found version "3.9")
    -- Found PythonLibs: /usr/lib64/libpython3.9.so (found version "3.9.0")
    -- Performing Test Weak Link MODULE -> SHARED (gnu_ld_ignore) - Success
    _modinit_prefix:PyInit_
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-build
    [1/7] Building C object CMakeFiles/masterkeys.dir/masterkeys/masterkeys.c.o
    In file included from /usr/include/python3.9/Python.h:85,
                     from ../../../masterkeys/masterkeys.c:14:
    /usr/include/python3.9/pytime.h:153:60: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
      153 | PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts);
          |                                                            ^~~~~~~~
    /usr/include/python3.9/pytime.h:158:56: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
      158 | PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
          |                                                        ^~~~~~~~
    In file included from ../../../masterkeys/masterkeys.c:12:
    ../../../masterkeys/../libmk/libmk.h:147:13: warning: array ‘LIBMK_MODEL_STRINGS’ assumed to have one element
      147 | const char* LIBMK_MODEL_STRINGS[];
          |             ^~~~~~~~~~~~~~~~~~~
    [2/7] Building C object CMakeFiles/masterkeys.dir/libmk/libmk.c.o
    [3/7] Building C object CMakeFiles/mk.dir/libmk/libmk.c.o
    [4/7] Linking C shared library mk.so.0.1.0
    [5/7] Creating library symlink mk.so
    [6/7] Linking C shared module masterkeys.cpython-39-x86_64-linux-gnu.so
    FAILED: masterkeys.cpython-39-x86_64-linux-gnu.so
    : && /usr/bin/cc -fPIC -std=c99 -O2 -DNDEBUG  -Wl,--unresolved-symbols=ignore-all -Wl,--version-script="/tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-build/CMakeFiles/masterkeys-version-script.map" -shared  -o masterkeys.cpython-39-x86_64-linux-gnu.so CMakeFiles/masterkeys.dir/masterkeys/masterkeys.c.o CMakeFiles/masterkeys.dir/libmk/libmk.c.o  -Wl,-rpath,/tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-build:  /usr/lib64/libpython3.9.so  mk.so.0.1.0  -lusb-1.0 && :
    /usr/bin/ld: CMakeFiles/masterkeys.dir/libmk/libmk.c.o:(.data.rel.local+0x0): multiple definition of `LIBMK_MODEL_STRINGS'; CMakeFiles/masterkeys.dir/masterkeys/masterkeys.c.o:(.bss+0x0): first defined here
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/skbuild/setuptools_wrap.py", line 589, in setup
        cmkr.make(make_args, env=env)
      File "/usr/local/lib/python3.9/site-packages/skbuild/cmaker.py", line 496, in make
        raise SKBuildError(
    
    An error occurred while building with CMake.
      Command:
        cmake --build . --target install --config Release --
      Source directory:
        /tmp/pip-install-wvfldzt7/masterkeys
      Working directory:
        /tmp/pip-install-wvfldzt7/masterkeys/_skbuild/linux-x86_64-3.9/cmake-build
    Please see CMake's output for more information.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wvfldzt7/masterkeys/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wvfldzt7/masterkeys/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4wfkhqpw/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/masterkeys Check the logs for full command output.

It says that first definition is in materkeys.c.o, so i presume is the objcect file from masterkeys.c, but actually there isn't that definition in there... no clue...

Unable to compile source (master branch)

Hi @RedFantom, I am trying to compile the tools so that I can get you the mapkeys for my keyboard but I am not able to even pass the first part.

BTW, before this, I was getting another cmake error (unable to find X11) which was solved by adding one extra dependency: libx11-dev. (I've just realized that this is because I was also compiling some examples, I commented that line but the error is still there, even after a clean)

gomera@deathscythe:~/projects/masterkeys-linux$ cmake .
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at libmk/CMakeLists.txt:5 (include):
  include could not find load file:

    FindLibUSB.cmake
Call Stack (most recent call first):
  CMakeLists.txt:6 (include)


-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so
-- Looking for XOpenDisplay in /usr/lib/x86_64-linux-gnu/libX11.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Found X11: /usr/lib/x86_64-linux-gnu/libX11.so
CMake Error at examples/ambilight/CMakeLists.txt:5 (include):
  include could not find load file:

    FindLibUSB.cmake
Call Stack (most recent call first):
  examples/CMakeLists.txt:7 (include)
  CMakeLists.txt:10 (include)


/usr/include
/usr/lib/x86_64-linux-gnu/libX11.so
-- Configuring incomplete, errors occurred!
See also "/home/gomera/projects/masterkeys-linux/CMakeFiles/CMakeOutput.log".

Information exchange regarding keyboard layout

Hey RedFantom,

it appears that we are working towards the same goal. I have mapped out and implemented large parts of the protocol used not only by the official SDK but also the control software itself.

I found your repository while trying to locate all MasterKeys models with their respective USB product IDs so that I may implement automatic layout detection, but this might be a dead end now, as both your ANSI Pro L and my ISO Pro L have the same USB product ID, 003b.

So what I am thinking now is that the layout information is encoded somewhere in the init exchange of the protocol that I have largely been unable to decipher. I know that the very first 01 02 ... exchange returns the firmware version in ASCII, but there's also some 40 20 ... package that I can't make sense of. This is the exchange I recorded during initialization:

>> 40 20 00 00 00 00 00 00   00 00 00 00 00 00 [00...]
<< 40 20 00 00 05 14 04 0c   12 01 20 00 00 00 [00...]

Since you are the only other person I know who has an ANSI Pro L, maybe we could compare these and find out which field, if any, is responsible for carrying the layout information?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.