1
+ /* !
2
+ * @file WipperSnapper_I2C_Driver_MCP9808.h
3
+ *
4
+ * Device driver for the MCP9808 Temperature sensor.
5
+ *
6
+ * Adafruit invests time and resources providing this open source code,
7
+ * please support Adafruit and open-source hardware by purchasing
8
+ * products from Adafruit!
9
+ *
10
+ * Copyright (c) Brent Rubell 2022 for Adafruit Industries.
11
+ *
12
+ * MIT license, all text here must be included in any redistribution.
13
+ *
14
+ */
15
+ #ifndef WipperSnapper_I2C_Driver_MCP9808_H
16
+ #define WipperSnapper_I2C_Driver_MCP9808_H
17
+
18
+ #include " WipperSnapper_I2C_Driver.h"
19
+ #include < Adafruit_MCP9808.h>
20
+
21
+ /* *************************************************************************/
22
+ /* !
23
+ @brief Class that provides a driver interface for a MCP9808 sensor.
24
+ */
25
+ /* *************************************************************************/
26
+ class WipperSnapper_I2C_Driver_MCP9808 : public WipperSnapper_I2C_Driver {
27
+ public:
28
+ /* ******************************************************************************/
29
+ /* !
30
+ @brief Constructor for a MCP9808 sensor.
31
+ @param _i2c
32
+ The I2C interface.
33
+ @param sensorAddress
34
+ The 7-bit I2C address of the sensor.
35
+ */
36
+ /* ******************************************************************************/
37
+ WipperSnapper_I2C_Driver_MCP9808 (TwoWire *_i2c, uint16_t sensorAddress)
38
+ : WipperSnapper_I2C_Driver(_i2c, sensorAddress) {
39
+ // Called when a MCP9808 component is created
40
+ setI2CAddress (sensorAddress); // sets the driver's I2C address
41
+ _mcp9808 = new Adafruit_MCP9808 ();
42
+ _isInitialized = _mcp9808->begin ();
43
+ }
44
+
45
+ /* ******************************************************************************/
46
+ /* !
47
+ @brief Destructor for an MCP9808 sensor.
48
+ */
49
+ /* ******************************************************************************/
50
+ ~WipperSnapper_I2C_Driver_MCP9808 () {
51
+ // Called when a MCP9808 component is deleted.
52
+ delete _mcp9808;
53
+ }
54
+
55
+ /* ******************************************************************************/
56
+ /* !
57
+ @brief Gets the MCP9808's current temperature.
58
+ @param tempEvent
59
+ Pointer to an Adafruit_Sensor event.
60
+ @returns True if the temperature was obtained successfully, False
61
+ otherwise.
62
+ */
63
+ /* ******************************************************************************/
64
+ bool getEventAmbientTemperature (sensors_event_t *tempEvent) {
65
+ tempEvent->temperature = _mcp9808->readTempC ();
66
+ return true ;
67
+ }
68
+
69
+ protected:
70
+ Adafruit_MCP9808 *_mcp9808; // /< Pointer to MCP9808 temperature sensor object
71
+ };
72
+
73
+ #endif // WipperSnapper_I2C_Driver_MCP9808
0 commit comments