Go Down

Topic: Help with template<class T_WIRE_METHOD> class RtcDS3231 (Read 142 times) previous topic - next topic

KennAnderson

Hello, I am a newbie to Arduino. Running 1.8.5, "standard config."  I am coding for a DS3231 RTC and have a question about
template<class T_WIRE_METHOD> class RtcDS3231
I can't find T_WIRE_METHOD in any 1.8.5 library. I know it is two_wire I2C. I want to examine the code describing T_WIRE_METHOD so I can understand what is going on.
Code continues as
    public:
      RtcDS3231(T_WIRE_METHOD& wire) :
        _wire(wire)
      {
      }
      void Begin()
      {
        _wire.begin();
      }
Code works -- I can r/w DS3231 all registers . I just don't understand what T_WIRE_METHOD is doing. Thanks for your help. Kenn

pylon

This is standard C++, it's called template. It's a concept to have a code block being able to be used with different types. You provide the template "parameter" type when instantiating the template class. In this case you probably will use the TwoWire class of the Arduino IDE but there may be special situations where you don't want to use the hardware I2C interface but some software emulation. Then you can supply the corresponding class to the declaration and the rest of the code works as expected.

Go Up