I2C 接続の温度センサ ADT7410 用のライブラリ. Library for temperature sensor ADT7410 connected using I2C interface.
Dependents: Mbed2_ConnectTestAll Demo_ADT7410
Diff: ADT7410.hpp
- Revision:
- 5:bbcd91ba7c6b
- Parent:
- 4:3769397d3803
- Child:
- 6:438204ab1793
diff -r 3769397d3803 -r bbcd91ba7c6b ADT7410.hpp --- a/ADT7410.hpp Fri Sep 01 11:14:31 2017 +0000 +++ b/ADT7410.hpp Sat Oct 28 13:14:53 2017 +0000 @@ -1,7 +1,9 @@ //-------------------------------------------------------------- -// Class for using ADT7410 (Header) +// Class for ADT7410 (Header) // Default: 13-bit resolution -// 2017/09/01, Copyright (c) 2017 MIKAMI, Naoki +// +// このプログラムを作った際の mbed のリビジョン:Rev.154 +// 2017/10/28, Copyright (c) 2017 MIKAMI, Naoki //-------------------------------------------------------------- #ifndef ADT7410_HPP @@ -24,10 +26,12 @@ ADT7410(PinName sda, // SDA PinName scl, // SCL uint8_t addr = 0x90); // I2C bus address -#endif +#endif // Set configuration register - void SetConfig(char val); - + // See Figure 15 in data sheet of ADT7410 + void SetConfig(char val) + { i2c_.write(ADDR_, (char[]){CONFIG_, val}, 2); } + // Get value in configuration register uint8_t GetConfig(); @@ -41,20 +45,21 @@ void Reset(); protected: + // Register addresses + enum Reg { TEMPER_ = 0x00, // Temperature value MSByte + CONFIG_ = 0x03, // Configuration + RESET_ = 0x2F}; // Software reset + // Write single byte // "STOP" を送らずにふたたび "START" を送る,つまりリスタート・コンディションに // する場合は,"repeated" を "true" にする - void WriteSingleByte(char reg, bool repeated = false) - { i2c_.write(ADDR_, ®, 1, repeated); } - + void WriteSingleByte(Reg reg, bool repeated = false) + { i2c_.write(ADDR_, (char *)reg, 1, repeated); } + private: - // Register addresses - static const uint8_t TEMPER_ = 0x00; // Temperature value MSByte - static const uint8_t CONFIG_ = 0x03; // Configuration - static const uint8_t RESET_ = 0x2F; // Software reset - const uint8_t ADDR_; // left-justified 7-bit slave address of ADT7410 I2C i2c_; // Object of I2C }; } #endif // ADT7410_HPP +