Simple wrapper object for LTC2606 1CH 16Bit DAC. Instantiate DacLtc2606 object instance passing reference to mbed.I2C object instance. Call write() method on DacLtc2606 instance passing 16Bit integer (0 [Off] to 32767/-32768 [Half-On] to -1 [Full-On]) to set DAC output.

Files at this revision

API Documentation at this revision

Comitter:
rkimble
Date:
Thu Sep 13 23:10:35 2012 +0000
Parent:
0:896aaf4b80d0
Child:
2:d101ca4ae85e
Commit message:
Initial Release

Changed in this revision

DacLtc2606.cpp Show annotated file Show diff for this revision Revisions of this file
DacLtc2606.h Show annotated file Show diff for this revision Revisions of this file
--- a/DacLtc2606.cpp	Thu Sep 13 23:07:18 2012 +0000
+++ b/DacLtc2606.cpp	Thu Sep 13 23:10:35 2012 +0000
@@ -1,37 +1,54 @@
-
-#include "DacLtc2606.h"
-#include "mbed.h"
-
-DacLtc2606::DacLtc2606(I2C i2c) : _i2c(i2c)
-{
-}
-
-bool DacLtc2606::write(int value)
-{
-    int opR;
-    char args[3];
-    args[0] = _command;
-    args[1] = (value >> 8) & 0xFF;
-    args[2] = value & 0xFF;
-    opR = _i2c.write(_slave, args, 3, false);
-    return (opR == 0) ? true : false;
-}
-
-bool DacLtc2606::write(double percent)
-{
-    if((percent >= 0.0) & (percent <= 1.0))
-    {
-        int value = 0;
-        if(percent < 0.5)
-        {
-            value = 32767.0 * (percent * 2);
-        }
-        else
-        {
-            value = -32768.0 * ((1.0 - percent) * 2);
-            if(value == 0) {value = -1;}
-        }
-        return write(value);
-    }
-    return false;
+/* Copyright (c) 2012 Reed Kimble, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "DacLtc2606.h"
+#include "mbed.h"
+
+DacLtc2606::DacLtc2606(I2C i2c) : _i2c(i2c)
+{
+}
+
+bool DacLtc2606::write(int value)
+{
+    int opR;
+    char args[3];
+    args[0] = _command;
+    args[1] = (value >> 8) & 0xFF;
+    args[2] = value & 0xFF;
+    opR = _i2c.write(_slave, args, 3, false);
+    return (opR == 0) ? true : false;
+}
+
+bool DacLtc2606::write(double percent)
+{
+    if((percent >= 0.0) & (percent <= 1.0))
+    {
+        int value = 0;
+        if(percent < 0.5)
+        {
+            value = 32767.0 * (percent * 2);
+        }
+        else
+        {
+            value = -32768.0 * ((1.0 - percent) * 2);
+            if(value == 0) {value = -1;}
+        }
+        return write(value);
+    }
+    return false;
 }
\ No newline at end of file
--- a/DacLtc2606.h	Thu Sep 13 23:07:18 2012 +0000
+++ b/DacLtc2606.h	Thu Sep 13 23:10:35 2012 +0000
@@ -1,56 +1,53 @@
-/* mbed LTC2606 1CH 16Bit DAC Library
- * Copyright (c) 2012 Reed Kimble
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#ifndef MBED_DACLTC2606_H
-#define MBED_DACLTC2606_H
-
-#include "mbed.h"
-
-/* I2C DAC controller class
- */
-class DacLtc2606 {
-public:
-    /** Create a DacLtc2606 object using to the specified I2C object
-     *
-     * @param i2c The I2C object to communicate with
-     */
-    DacLtc2606(I2C i2c);
-    
-    /** Set the DAC output to the specifed integer value
-     *
-     * @param value The 16 bit integer to write (0 to 32767 to -32768 to -1)
-     */
-    bool write(int value);
-    
-    /** Set the DAC output to the specified percentage of max
-     *
-     * @param percent A double from 0.0 to 1.0 representing the percent of max output power on the DAC
-     */
-    bool write(double percent);
-    
-private:
-    static const char _slave = 0xE4;
-    static const char _command = 0x30;
-    I2C _i2c;
-};
-
+/* mbed LTC2606 1CH 16Bit DAC Library
+ * Copyright (c) 2012 Reed Kimble, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MBED_DACLTC2606_H
+#define MBED_DACLTC2606_H
+
+#include "mbed.h"
+
+/* I2C DAC controller class
+ */
+class DacLtc2606 {
+public:
+    /** Create a DacLtc2606 object using to the specified I2C object
+     *
+     * @param i2c The I2C object to communicate with
+     */
+    DacLtc2606(I2C i2c);
+    
+    /** Set the DAC output to the specifed integer value
+     *
+     * @param value The 16 bit integer to write (0 to 32767 to -32768 to -1)
+     */
+    bool write(int value);
+    
+    /** Set the DAC output to the specified percentage of max
+     *
+     * @param percent A double from 0.0 to 1.0 representing the percent of max output power on the DAC
+     */
+    bool write(double percent);
+    
+private:
+    static const char _slave = 0xE4;
+    static const char _command = 0x30;
+    I2C _i2c;
+};
+
 #endif
\ No newline at end of file