Errors in LaLa code

While reading recent changes in the documentation, I spotted some (non-critical) errors in the code for the LaLa board:
http://devwiki.electricimp.com/doku.php?id=lala

In the functions erasePlayBlocks() and eraseRecBlocks() 64k is represented as 65535, but it should actually be 65536. In these functions, this could theoretically result in the erasure of the wrong block. In reality it won’t happen, because only the most significant portion of the wrongly calculated address is used in the SPI flash chip to identify the block to be erased, and this chip only contains 64 blocks of 64k, so no real harm is done. Still, it would be better for the understanding of the code to fix the error.

The same mistake is made in the function checkBattery(), where a scaling factor of 65535.0 is used to get the most significant bits of an analog read. The resulting error is negligible, but again, for clarity of code, the number should be 65536.0 (or do a >>16 instead of a floating point divide).

I assume (but did not check) that the same code is also posted on Github.

The eraseblock ones are indeed incorrect (and there was another off-by-one bug in there somewhere too, not sure if the very latest code is up yet)…

However, the analog read divisor is correct - the max ADC reading is 65535, which you want to come out as 1.0 in this calculation - to then be multiplied by the scale factor. Doing >>16 is going to just give you zero, as it’s an integer returned from the ADC, so it being a floating point divide is correct for this line.

You’re right about the analog read, my bad :wink: