Using a Gyroscope to control Smart Lights

TL;DR: I used the gyroscope inside a JoyCon controller, to change the brightness of my smart light bulb.

A few years ago, my sister bought me a set of smart light bulbs as a present. It was very nice of her!

You could use an app to change the color and brightness, all the classic features.

Then I wondered if I could change it from something else, my pc perhaps? After a quick search, I found this nice library for python https://github.com/sbidy/pywizlight. What I found interesting was that it had a command line tool, and oh boy that made me happy ᕙ( •̀ ᗜ •́ )ᕗ

Back then my experience with python was nonexistent, I could read it but not code. So, I came up with a plan:

Since I was using DS4Windows to use my controllers, and that tool had the ability to read gyro signals, I could use CE to find the part of the memory responsible for handling pitch (not really pitch, but a similar axis that I’m calling pitch for simplicity), then use asm to send a specific command to the ip of the bulb.

The results

I was so proud of myself !

Why lua?

Because the tool that I was using to reverse engineer DS4Windows was Cheat Engine, a popular reversing tool often used in games as it offers a great memory scanner, not found in other reverse engineering tools. CE has a built in Lua Engine, which interacts well with our assembly patches, you can register symbols after allocating memory.
At a higher level it’s essentially declaring a variable, but cooler (⌐■_■)

Summary of the plan
# lpCmdLine
# The brightness value will be appended at the end of the line
'wizlight on --ip 192.168.0.16 --k 5000 --brightness '
flowchart TD A["Read pitch value (0-255) (Lua)"] B["Append value as string to lpCmdLine (Asm)"] C["Call kernel32.WinExec (Asm)"] A --> B --> C