Hardware Reference
In-Depth Information
#define DEV0 0x90
#define DEV1 0x91
#define DEV2 0x92
#define DEV3 0x93
#define DEV4 0x94
#define DEV5 0x95
#define DEV6 0x96
#define DEV7 0x97
class DS1631
{
public:
DS1631(uint8_t _ADDR);
void begin( );
byte getConfig();
void setConfig(uint8_t _ADDR);
float getTemp();
void stopConversion();
void startConversion();
private:
float calcTemp(int msb, int lsb);
uint8_t _addr;
uint8_t _temp[2];
};
#endif
Listing 12-11 defines all the valid device addresses that can be used with the object. It is configured so that
when reading the data sheet, the hexadecimal I2C address can be used as listed. Since the header file only shows the
signature for the functions, we can tell what the class name, constructor, and destructor are for the defined object.
With the aVr gCC, there is not effective memory management. objects will not get deleted, so the constructor
is not used and can be eliminated from the code.
Note
As there is no effective memory management, the destructor is not used and no memory will be deallocated. The
private variables are declared here, and the compiler will enforce them. If you try to directly access _addr , _temp[2] ,
or calcTemp() , the compiler will show an error indicating that you are trying to access private values. By reviewing
this code, you can get a quick idea of the functions and the types of parameters that are defined. This information will
be used to ensure that the implementation corresponds to the values that are represented in the header file.
It is possible to describe more than one object in a single header file, but this can confuse library users, so it is
best to create only one object per header file. If a set of objects will never be used separately from one another, it may
make sense to define more than one object in the same header file.
Listing 12-12. DS1631 I2C temperature sensor implementation DS1631.cpp
#include <Wire.h>
#include "DS1631.h"
 
 
Search WWH ::




Custom Search