This talk is about the process and the difficulty encountered when building an application that uses cgo to bind an existing C library reading messages from a USB keyboard. This application is used to read messages from a custom keyboard firmware, however, due to the performance of cgo and the characteristic of Golang channel, it often gets malformed messages. In this talk, we will discuss how these two factors cause failure and the solution.
I am a passionate advocate for ergonomic keyboards. Such keyboards are equipped with a custom firmware which can fully control keymaps and can send debug messages. Putting frequently used keys to the place where hands are normally stretched highly reduces the need of moving hands. In order to systematically and statistically find frequencies for each key thus design a better keymap, I use the debug message to log information for every key I pressed. In the beginning, I thought it would be easy to use cgo to adopt an existing C library, and it turns out there are messages lost due to too much cgo calls. After solving the cgo call issue, I encounter issues caused by the lock of the Golang channel and even I use a buffered channel, the reading process still freezes due to the slow consuming messages in go code. This talk will share the solution I proposed and some possible applications in the future.
About Sung-Chi (Alan) Li
A software engineer interested in microservices, 3D printing, and microcontrollers. These skills make me a maker, to make things that help me with work, and to improve things that I do not satisfy.