Added port from C++ code
Merge https://github.com/Naronco/EncoXD