| 1 | #ifndef DS1624_H |
|---|
| 2 | #define DS1624_H |
|---|
| 3 | |
|---|
| 4 | #include "../global.h" |
|---|
| 5 | #include "../configs/ds1624/ds1624.h" |
|---|
| 6 | |
|---|
| 7 | #define DS1624_BASE_ADDR B01001000 |
|---|
| 8 | #define DS1624_ADDR DS1624_BASE_ADDR | (DS1624_A0 * B00000001) | (DS1624_A1 * B00000010) | (DS1624_A2 * B00000100) |
|---|
| 9 | |
|---|
| 10 | /** |
|---|
| 11 | * Sampling configurations |
|---|
| 12 | **/ |
|---|
| 13 | #define DS1624_CONFIG_1SHOT B00000001 |
|---|
| 14 | #define DS1624_CONFIG_CONT B00000000 |
|---|
| 15 | |
|---|
| 16 | // Select either 1shot or continous themometer mode |
|---|
| 17 | #define DS1624_CONFIGS DS1624_CONFIG_CONT |
|---|
| 18 | |
|---|
| 19 | // DS1624 Commands |
|---|
| 20 | #define DS1624_CONFIG_ADDR 0xAC |
|---|
| 21 | #define DS1624_READ_TEMP 0xAA |
|---|
| 22 | #define DS1624_SMPL_START 0xEE |
|---|
| 23 | #define DS1624_SMPL_STOP 0x22 |
|---|
| 24 | #define DS1624_ACCESS_MEM 0x17 |
|---|
| 25 | |
|---|
| 26 | // Bit masks |
|---|
| 27 | #define DS1624_CONFIG_DONE B10000000 |
|---|
| 28 | |
|---|
| 29 | // Size of the EEPROM memory in bytes |
|---|
| 30 | #define DS1624_EEPROM_SIZE 255 /* There are actually 256 bytes, but the twi functions only support reading 255 at a time!*/ |
|---|
| 31 | #define DS1624_EEPROM_PAGE 8 |
|---|
| 32 | |
|---|
| 33 | class DS1624 |
|---|
| 34 | { |
|---|
| 35 | public: |
|---|
| 36 | DS1624(); |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * Init: runs the initializationr outine |
|---|
| 40 | **/ |
|---|
| 41 | void Init(void); |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * readTemp: reads the temperature and returns |
|---|
| 45 | * a 16 byte integer in which the 2 highest bytes |
|---|
| 46 | * are used as (int8_t)degrees and the 2 lowest |
|---|
| 47 | * are used (uint8_t)decimals |
|---|
| 48 | **/ |
|---|
| 49 | uint16_t readTemp(void); |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * Start conversion, used at startup in |
|---|
| 53 | * continous mode, or before a read |
|---|
| 54 | * in 1shot mode |
|---|
| 55 | **/ |
|---|
| 56 | void startConversion(void); |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * stopConversion: stops the temperature acquisition |
|---|
| 60 | **/ |
|---|
| 61 | void stopConversion(void); |
|---|
| 62 | /** |
|---|
| 63 | * EEPROM Support functions |
|---|
| 64 | **/ |
|---|
| 65 | #ifdef DS1624_USE_EEPROM |
|---|
| 66 | /** |
|---|
| 67 | * writeData: writes data to the eeprom |
|---|
| 68 | * pass it an array of uint8_t containing the values to write, |
|---|
| 69 | * the start position (must be %8 == 0) and the length. |
|---|
| 70 | * The two last can be omnited. |
|---|
| 71 | **/ |
|---|
| 72 | void writeData(uint8_t *, uint8_t, uint8_t); |
|---|
| 73 | void writeData(uint8_t *, uint8_t); |
|---|
| 74 | void writeData(uint8_t *); |
|---|
| 75 | |
|---|
| 76 | /** |
|---|
| 77 | * writeData: writes data to the eeprom |
|---|
| 78 | * pass it an array of uint8_t to store the result, |
|---|
| 79 | * the start position and the length. The two last can be omnited |
|---|
| 80 | **/ |
|---|
| 81 | void readData(uint8_t *, uint8_t, uint8_t); |
|---|
| 82 | void readData(uint8_t *, uint8_t); |
|---|
| 83 | void readData(uint8_t *); |
|---|
| 84 | #endif |
|---|
| 85 | private: |
|---|
| 86 | #ifdef DS1624_USE_EEPROM |
|---|
| 87 | /** |
|---|
| 88 | * writePage: writes a single page (or less) to the eeprom |
|---|
| 89 | * pass it an array of uint8_t to store the result, |
|---|
| 90 | * the start position and the length. |
|---|
| 91 | **/ |
|---|
| 92 | void writePage(uint8_t *, uint8_t, uint8_t); |
|---|
| 93 | #endif |
|---|
| 94 | |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | extern DS1624 TEMP; |
|---|
| 98 | |
|---|
| 99 | #endif |
|---|