Piicodev - detecting which sensors are attaced

Oh @Murray125532 what a bloody ripper! Thank you for this significant contribution to PiicoDev!
I really like the structure you’ve implemented - it appears to respect the existing PiicoDev_Unified structure and only bring extras to the party. Nice :smiley:
I’d love to discuss how we can get this worked into PiicoDev, for for that we’ll have to…


Let’s get into the weeds, or - the challenges of Unifiying

The unfortunate constraint that PiicoDev_Unified has to navigate is the flash memory size for Micro:bit v2 which is so small that we can just fit a minified version of PiicoDev_Unified and minified versions of one or two device libraries. This means that all changes to Unified have to be well considered to not increase the flash consumption any further. Your contribution is over 400 lines of added code.

OK so why not have multiple versions of Unified?

We knew early on that we wanted to maintain only one version of PiicoDev_Unified.py to streamline development, simplify testing and so Unified actually does what it says on the tin. That means that the same code has to work across multiple boards. To create separate versions for each piece of hardware introduces a lot of project risk and burden in maintaining and testing multiple files.

Then we found we outgrew the flash size of the Micro:bit v2, so we implemented the minifier which takes the original PiicoDev_Unified.py file, strips the comments, whitespace, and shrinks variable names where it can. The smaller “minified” file is generated automatically every time a commit is made and all Micro:bit guids point to this file.

Great. We have sustainable deployment for Unified, where we edit and test one Piicodev_Unified.py file, and a special version gets made for Micro:bit that is functionally identical, just smaller and a bit obfuscated.

The awkward thing now is that Unified is more-or-less stuck at its present size until Micro:bit release a larger flash variant.


Hope is not lost

We’ve done device libraries before that have a set of essential functions, and extended functions in another file. The PiicoDev RFID Module presented this exact problem: essential functions that are non-negotiable (reading NFC tags) and nice extras that fewer users would need (writing complex data to and from the tag). The PiicoDev_RFID.py contains essential functionality, and PiicoDev_RFID_Expansion.py file can be used by larger-memory devices. This obviously isn’t our preferred way to deploy devices since it breaks a lot of patterns, but in this case it was necessary.

Perhaps it’s time we used this idea with PiicoDev_Unified.py + PiicoDev_Unifed_Expansion.py?
What do you think? :smiley:

1 Like