Peripheral: LIS302 Accelerometer

13 Nov 2009

For anyone using (or thinking of using) the LIS302 SPI accelerometer...

... I've just cleaned up the library in the cookbook and provided a simple Hello World!

It should hopefully also act as a good reference example of how to write a re-usable peripheral library class, so feel free to look at the code (released under MIT license).

Simon

13 Nov 2009

Ta - I'll look at it & see if my camera code would make a nice library.

 

Can I actually make libraries with the public compiler, or does that require special magic ?

13 Nov 2009 . Edited: 13 Nov 2009

Richard Sewell
wrote:

Ta - I'll look at it & see if my camera code would make a nice library.

Sounds like a great idea!

Richard Sewell wrote:
Can I actually make libraries with the public compiler, or does that require special magic ?

Yes, you certainly can. It is not as slick as it could be at the moment, but it is just code. To start with, the best thing is simply to organise and structure your code, probably as a class for the peripheral you want to make available. Something like:

MyPeripheralName.h - The header file defining the class named "MyPeripheralName", and hence the interface

MyPeripheralName.cpp - The implementation of the class

If you then include within the program a simple Hello World! for it:

main.cpp - Hello World example using "MyPeripheralName".

then what you can do is publish it and post the link somewhere (e.g. in the forum) for others to play with.

An example of this starting point, and a good reference of how to structure a class, could be:

This program contains 3 files: LIS302.h, LIS302.cpp and main.cpp - So not a library as such, but very easy for someone to import, and then incorporate in to their own project.

The next step is that you can then push just the MyPeripheralName.h/.cpp in to the cookbook svn repository in a directory somewhere. This is again also a good way to look at an example of how to structure a library:

This repository is not properly integrated in to the compiler at the moment so you'd have to push it in via TortoiseSVN or some other svn client, but the upside is it makes a library people can import directly, can update whenever it changes, and will also auto-generate documentation from markup you put in the .h file comments. An example of the same main.cpp project, but this time pulling in the library rather than containing the raw files is:

But as I say, this is a next step once you've made the library, and i'm not in a rush to encourage it as we'd like to improve this part of the compiler/website anyway (to make it slick!). The main thing is to concentrate on making your interface code well structured and usable by others.

Simon

13 Nov 2009

Thanks. I'll have a go at that once the camera is a bit more settled down.

Richard