C code and C++ library, driver software for Maxim Integrated DS1775, DS75 thermometer and thermostat temperature sensor. Code supports continuous or shut-down/standby, hysteresis, alarm limits, comparator or interrupt mode, fault filtering, and active low/high. Compact 5-pin SOT23 packaging

Dependents:   DS1775_Digital_Thermostat_Temperature

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Mon Apr 08 02:36:00 2019 +0000
Parent:
16:1ecfc243d4ef
Commit message:
shorten code for write_cfg_reg

Changed in this revision

ds1775_c.cpp Show annotated file Show diff for this revision Revisions of this file
ds1775_c.h Show annotated file Show diff for this revision Revisions of this file
ds1775_cpp.cpp Show annotated file Show diff for this revision Revisions of this file
ds1775_cpp.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1ecfc243d4ef -r ca86c0b37244 ds1775_c.cpp
--- a/ds1775_c.cpp	Mon Apr 08 00:14:08 2019 +0000
+++ b/ds1775_c.cpp	Mon Apr 08 02:36:00 2019 +0000
@@ -153,33 +153,23 @@
     }
 }
 
-/******************************************************************************/
-int ds1775_write_reg8(uint8_t value, char reg, I2C &i2c_bus) 
+
+int ds1775_write_cfg_reg(uint8_t cfg, I2C &i2c_bus)
 {
     int32_t ret;
     char cmd[2];
 
-    if (reg == DS1775_REG_CONFIGURATION) {
-        cmd[0] = reg;
-        cmd[1] = value;
-        ret = i2c_bus.write(ds1775_write_address, cmd, 2, false);
-        if (ret == 0) {
-            return DS1775_NO_ERROR;
-        } else {
-            printf("%s: I2C write error %d\r\n",__func__, ret);
-            return DS1775_ERROR;
-        }
+    cmd[0] = DS1775_REG_CONFIGURATION;
+    cmd[1] = cfg;
+    ret = i2c_bus.write(ds1775_write_address, cmd, 2, false);
+    if (ret == 0) {
+        return DS1775_NO_ERROR;
     } else {
-        printf("%s: register value invalid %x\r\n",__func__, reg);
+        printf("%s: I2C write error %d\r\n",__func__, ret);
         return DS1775_ERROR;
     }
 }
 
-int ds1775_write_cfg_reg(uint8_t cfg, I2C &i2c_bus)
-{
-    return ds1775_write_reg8(cfg, DS1775_REG_CONFIGURATION, i2c_bus);
-}
-
 
 int ds1775_write_trip_low(float temperature, I2C &i2c_bus)
 {
diff -r 1ecfc243d4ef -r ca86c0b37244 ds1775_c.h
--- a/ds1775_c.h	Mon Apr 08 00:14:08 2019 +0000
+++ b/ds1775_c.h	Mon Apr 08 02:36:00 2019 +0000
@@ -49,8 +49,6 @@
 
 int ds1775_write_reg16(int16_t value, char reg, I2C &i2c_bus);
 
-int ds1775_write_reg8(uint8_t value, char reg, I2C &i2c_bus);
-
 int ds1775_write_cfg_reg(uint8_t cfg, I2C &i2c_bus);
 
 int ds1775_write_trip_low(float temperature, I2C &i2c_bus);
diff -r 1ecfc243d4ef -r ca86c0b37244 ds1775_cpp.cpp
--- a/ds1775_cpp.cpp	Mon Apr 08 00:14:08 2019 +0000
+++ b/ds1775_cpp.cpp	Mon Apr 08 02:36:00 2019 +0000
@@ -155,35 +155,25 @@
     }
 }
 
+
 /******************************************************************************/
-int DS1775::write_reg8(uint8_t value, char reg) 
+int DS1775::write_cfg_reg(uint8_t cfg)
 {
     int32_t ret;
     char cmd[2];
 
-    if (reg == DS1775_REG_CONFIGURATION) {
-        cmd[0] = reg;
-        cmd[1] = value;
-        ret = m_i2c.write(m_write_address, cmd, 2, false);
-        if (ret == 0) {
-            return DS1775_NO_ERROR;
-        } else {
-            printf("%s: I2C write error %d\r\n",__func__, ret);
-            return DS1775_ERROR;
-        }
+    cmd[0] = DS1775_REG_CONFIGURATION;
+    cmd[1] = cfg;
+    ret = m_i2c.write(m_write_address, cmd, 2, false);
+    if (ret == 0) {
+        return DS1775_NO_ERROR;
     } else {
-        printf("%s: register value invalid %x\r\n",__func__, reg);
+        printf("%s: I2C write error %d\r\n",__func__, ret);
         return DS1775_ERROR;
     }
 }
 
 /******************************************************************************/
-int DS1775::write_cfg_reg(uint8_t cfg)
-{
-    return write_reg8(cfg, DS1775_REG_CONFIGURATION);
-}
-
-/******************************************************************************/
 int DS1775::write_trip_low(float temperature)
 {
     ds1775_raw_data raw;
diff -r 1ecfc243d4ef -r ca86c0b37244 ds1775_cpp.h
--- a/ds1775_cpp.h	Mon Apr 08 00:14:08 2019 +0000
+++ b/ds1775_cpp.h	Mon Apr 08 02:36:00 2019 +0000
@@ -166,13 +166,6 @@
      */
     int write_reg16(int16_t value, char reg);
 
-    /** 
-     * @brief Write a value to a register
-     * @param value - value to write to the register
-     * @param reg - register address
-     * @return 0 on success, negative number on failure
-     */
-    int write_reg8(uint8_t value, char reg);
 private:
     /** @var m_i2c
      * @brief I2C object