C++ preprocessor, pin assigments and building a library.

20 Oct 2010

Trying to convert some old code to a library for release.

I am using 2 digital IO's to bit bash a particular interface so i need to instantiate a clss and pass the name of 2 pins in the class creator. something like

device xyz(p8,p9);

should pass pins p8 and p9 to the library and my library code should then assign p8 and p9 to two signals.

Internally all my old code uses CLOCK and DATA as the two lines and I need to do things like  set CLOCK high, read DATA etc with the effect that where my code says set CLOCK high I am setting say p8 high and where I say read DATA i am reading p9.

i have looked at the example on building a library which conveniently uses a digital IO to toggel an LED but the preprocessor stuff has me confussed!

Would appreciate a pointer to a tutorial or documentation on the preprocessor or just a plain old hand in getting my library converted.

20 Oct 2010

Try something like this:

class MyDevice
{
public:
  MyDevice(PinName pclock, PinName pdata): _clock(pclock), _data(pdata) {};
  void doStuff2();
private:
  DigitalOut _clock;
  DitigalInOut _data;
}

void MyDevice::doStuff()
{
  _data.input();
  _clock = 1;
  int d1 = _data;
  _clock = 0;
  _clock = 1;
  int d2 = _data;
  [...]
}
If you get stuck, post some snippets of the original code.

20 Oct 2010

Thanks igor. I'll get back to you on.

20 Oct 2010 . Edited: 20 Oct 2010

Thanks again Igor. A very rusty brain gets a good going over!

I will be publishing a library to read the Sensiron SHT75 temperature and humidity device later today!