How can I code my own firmware for the D4v2 Flashlight?

Welcome to BLF.

With code you can do whatever you want, but does the hardware support it? In this case, no, there is no wireless communication IC in the D4v2. This needs to be added, as well as a method to pulse the switch signal pin of the D4v2’s MCU in order to make it change modes and such, if not some other method of control.

There is probably not enough room for the additional hardware in the unmodified light, and the RF signal would have to go through a bunch of aluminum. A smaller battery could be used to create internal space for the added hardware, and just the antenna could be external to the body. Otherwise everything could be external to the light, but you’ll need to tap into the light one way or another to signal the MCU. Through the switch boot is one way, connecting a wire to one leg of the E-switch there, but this is a less than ideal modification, and the light will not be so readily removable from the skateboard. Attaching the requisite hardware to the outside rear of the tailcap, and routing the switch signal through the body up to the driver, would be a way to keep the full sized battery and make the light readily removable from the skateboard, it will just add some length to the host.

Anduril is open source. The code is hosted multiple places such as the flashlight firmware repository. This is the branch where Anduril is located. Here is the user manual.