HOWTO: How to customize `blinklib` (advanced)

Let’s say you love blinklib, but just wish that it did one thing differently. You can actually customize blinklib to suit your needs!

For this example, we are are going to pretend that you have created a game that is played on the ceiling and so you want the buttonDown() function to return true normally and false when the button is pressed (the opposite of the normal behavior).

  1. Open the ButtonPress example program in the Arduino IDE

  1. “Save as…” it to something like ButtonPressOverride.

  2. Download this program to a blink and confirm that the LEDs are RED when the button is pressed and GREEN when it is not pressed.

  3. Open the sketch folder using Show Sketch Folder

image

  1. Copy the blinklibb.cpp file into the sketch folder. Note that you will have to find this file yourself since where it lands is dependent on how your computer is set up and how you installed the blinks SDK. On my machine it is in D:\Github\Move38-Arduino-Platform\cores\blinklib. Make sure you copy and not move the file.

  1. Quit out of the Arduino IDE and start it again. You should now see the blinklib tab in the IDE

image

  1. Inside blinklib.cpp, find the buttonDown() function.

  1. Change the buttonDown() function to do the opposite (ceiling-style)

image

  1. Download the program into a blink and confirm that up is now down!

Yeay! You now can very easily customize any blinklib functionality you want!

This is a silly example, more likely you would want to customize things like how the IR set value system updates, or maybe reduce the memory used by some functionality that you don’t need, or change the way that blinks keep each other awake when buttons are pressed.

Some gotchas:

  1. The changes you make to blinklib.cpp only affect the current project. If you want to use these same changes on other projects, you will have to copy the blinklib.cpp to their sketch folders. Having many copies of the same file can be a version control hassle since you will be responsible for keeping all the copies in sync (you could use symbolic links to help here, but they can be problematic when you want to move or share your codebase).

  2. Your version of blinklib.cpp is locked in the moment you copy it so it will not automatically get updates if that file is updates in the main repository. Again this could be a version control hassle since you will have to manually merge in any updates that you want.

If you are looking to really overhaul the API and make it available to others, then there are better ways. You could, for example, fork the blinklib repo and then do whatever you want and push and pull changes to and from the main repo. This would be great if you, say, wanted to create a new actor-model style API. LMK if this is something you’d be interested in and we can help you out!

2 Likes

This is all very good information. I have one specific question about this last part.

I actually sent a pull request for blinklib to “test the waters” but I got no reply. Granted, I will actually recall that push request because the right way to do what I want is to move the relevant stuff to blinklib instead of exposing its guts to callers (this was a naive approach based on me being too lazy to do a deep dive on blinklib. Now I did).

I assume you would be the one dealing with this kind of things, correct? Did you not look at the pull request at all or is it just that it was so bad that you did not even bother to address it? :slight_smile:

I would love to contribute to blinklib and with the code I wrote so far, I think I am getting the hang of it and can actually do something that would be a net positive. :slight_smile: Should I do anythiong other than simply sending the pull request when I have something?

I’m sorry that I am just seeing this pull request. My version of the blinks code lives in my account here…

…where is do all the development work and then send a PR to the Move38 fork, where they test it and pull it into the official distribution. But, of course, there is no way you could know that. Sorry again for that obnoxiousness, I know how frustrating it is to invest time into making improvements only to see your upstream PR languish.

I will try to keep an eye on PRs into the Move38 repo, but best place to send actual platform code PR’s (not documentation or games) is directly to the above.

Thanks!

Thanks.

And don’t worry. As I mentioned, I will withdraw that one anyway. No one looking at it gave me time to think. :slight_smile: