Well, I can see both sides.
Form a programming point of view it would be better starting from 0. Albeit, I know very well that people with no programming background sometimes have problems to get the idea that something is counted starting from 0.
From the datasheet and accountant-way of counting people have to address an unit calling "foo1" by 0 which gives a little twist on the documentation. I think Damien had similar thoughts. It seems somewhere internally, we have already a subtraction by 1. There is an indexing error for -1 if you try to address a LED[0].
I don't think it is to late to change it. There is most likely not a single project out there which is much longer then 100 lines of code.
I would ship the boards as they are now but (if it is decided to do so) make an announcement for a later release that this behavior changes.
Those things happened in similar projects too (Arduino and Co.) and nobody should expect a API written in stone at this stage.
However, as I wrote above, we will hit one or the other problem. Telling people to address a deviceX by X-1 or telling them that a range needs to start by 1 and most likely the need to add +1 here and there in the code. Both ways will leave a group of people complaining in one or the other direction.
One idea would be to start counting from 0 in the same way python does but introduce a general unit initializer-function which will get a string with the same name as it is written on sillk / in the datasheet of a specific board.
Thus,
would be a great way for people following silkscreen or datasheets to get an object of a specific peripheral.
Those strings could be completely different among different boards but there would be a common way to access them among all boards.
I know this is most likely complete the opposite direction of pfalcons approach trying to keep stuff as modular as possible (sorry for that pfalcon
).
I think at the end, we might need something rather modular, but having a thin wrapper around all this for beginners to make it easy accessible in an uniform way. Guess this all goes into the HAL direction.
For the time being, we might help our-self a little by wrapping some try and catch arguments around any peripheral indexing code and create suitable error-messages whenever someone tries to address a peripheral by out of its index boundary. Something like
Code: Select all
print("{0} need to be indexed between {1} and {2}".format(peripheral.name(), peripheral.index.min(), peripheral.index.max()))