Pinephone and BlackMagic are a thing

(or how to control a Pocket Cinema Camera 4K with graphics)

There now is Bluetooth communication between the PinePhone and the Black Magic Pocket Cinema Camera 4K. Time to take the last hurdle: the graphical user interface of the application. After lots of late nights finding out how the hell it all works, I now figured it out. And as with a lot of things: it is very easy once you know how to do it. But the crux is in the once.

The technical stuff

I started a new C project in GNOME builder. And that new project is a Hello, World. My third one during this project! I threw away the Hello, World label and realized I could use Glade for designing the graphical user interface. I found a very old, but very useful tutorial which gave me an insight in this new world.

Once I designed a very crude gui, consisting of an icon, a button and a label, I had to connect the signal from the button to the C code. Again, I had no idea how to do that. The code from the libhandy sample program I used before ( was a source of inspiration. And after some fooling around I managed to connect the button to the code. Now I had a program that did absolutely nothing, but I was happy.

Now it was time to add the two projects together. The Bluetooth scripts for starting and stopping the camera should be triggered by the switch. Easy right?

The code for doing that is very basic. Just import de stdlib.h library and call the system() function. The argument is a string with the system call, which in my case is the name of one of the scripts. The code is embarrassingly easy:

#include <stdlib.h>
void BMPCC4K_start_recording(void)
void BMPCC4K_stop_recording(void)

It depends on the scripts being placed at a fixed location. That's not very elegant. You could even argue that it is very wrong! And you are right. But for the purpose of this experiment I did it anyway.

I compiled the whole program for the aarch64 architecture and flatpaked it. I transferred it to the PinePhone and installed it with:

flatpak install nl.meezenest.RemoteControlBMPCC4K

Unfortunately, it did not work. The app started and I could toggle the switch, but nothing happened. When I started the program from the command line, I could see what was going on: Flatpak keeps the program in a sandbox. Therefore it has no access to the scripts. That is a very good practice, but not very handy for development. So I had to start the app with an additional command, giving it access to the home directory, where the scripts were located. I also copied the bluetoothctl program to the same directory as the scripts are in. That is because the /bin/ directory is off limits for Flatpak applications:

flatpak --filesystem=host run nl.meezenest.RemoteControlBMPCC4K

Still no cigar. The bluetoothctl program can not access the Bluetooth hardware (or socket to that hardware). I had to get rid of the sandbox as much as possible. Not a good practice, but for development purposes I think it is okay to do:

flatpak --filesystem=host --device=all --socket=system-bus run nl.meezenest.RemoteControlBMPCC4K

Finally success: I could start and stop the camera with the app!

A magic bond

It is not a very good program: it is a mismatch of C code and bash scripts. It also relies on the user to connect manually to the camera before trying to start and stop the camera. I made absolutely no effort to catch all the possible errors that could occur. I removed the sandbox around the program. The scripts have to be in the right spot. The bluetoothctl program has to be available on the machine and the camera has to be paired manually. And there are undoubtedly many more things I could have done better. But as this is only version 0.0.1, I can get away with it, I hope...