Library for the use of the atmospheric pressure sensor SCP1000

Files at this revision

API Documentation at this revision

Comitter:
s_inoue_mbed
Date:
Thu Sep 18 13:09:39 2014 +0000
Parent:
0:a224293d7af4
Commit message:
Bug fix: below-zero temperature is sufficiently treated.

Changed in this revision

SCP1000.cpp Show annotated file Show diff for this revision Revisions of this file
SCP1000.h Show annotated file Show diff for this revision Revisions of this file
--- a/SCP1000.cpp	Tue Sep 16 13:07:04 2014 +0000
+++ b/SCP1000.cpp	Thu Sep 18 13:09:39 2014 +0000
@@ -1,18 +1,18 @@
 /* Copyright (c) 2014 Shigenori Inoue, 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 
+ * 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 
+ * 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, 
+ * 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.
  */
 
@@ -186,6 +186,14 @@
 {
     int temp_raw;
     temp_raw = read16(TEMPOUT);
+
+    /* Check the below-zero temperature */
+    if ((temp_raw | 0x2000) == 1) {
+        temp_raw ^= 0x2000;
+        temp_raw = -temp_raw;
+    }
+
+    /* Return the temperature as float */
     return static_cast<float>(temp_raw) * 0.05;
 }
 
@@ -196,5 +204,7 @@
     int press_raw_l;
     press_raw_h = read8(DATARD8);
     press_raw_l = read16(DATARD16);
+    
+    /* Return the atmospheric pressure as float */
     return static_cast<float>((press_raw_h << 16) + press_raw_l) * 0.0025;
 }
\ No newline at end of file
--- a/SCP1000.h	Tue Sep 16 13:07:04 2014 +0000
+++ b/SCP1000.h	Thu Sep 18 13:09:39 2014 +0000
@@ -78,7 +78,10 @@
      */
     void setMode(int mode);
 
-    /** Trigger the measurement by TRIG wire in Low Power Mode */
+    /** Trigger the measurement by TRIG wire in Low Power Mode
+     * NOTE: IT CURRENTLY SEEMS NOT WORKING.
+     * PLEASE USE triggerSoft() INSTEAD.
+     */
     void triggerHard(void);
 
     /** Trigger the measurement by register writing in Low Power Mode */