version one

Fork of SHTx by Roy van Dam

Files at this revision

API Documentation at this revision

Comitter:
yongqiangwang
Date:
Mon Mar 04 19:11:37 2013 +0000
Parent:
1:8465801be23f
Commit message:
version one; ;

Changed in this revision

i2c.cpp Show annotated file Show diff for this revision Revisions of this file
i2c.hpp Show annotated file Show diff for this revision Revisions of this file
sht15.cpp Show annotated file Show diff for this revision Revisions of this file
sht15.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8465801be23f -r cd8e210049b9 i2c.cpp
--- a/i2c.cpp	Fri Nov 19 16:24:46 2010 +0000
+++ b/i2c.cpp	Mon Mar 04 19:11:37 2013 +0000
@@ -27,127 +27,127 @@
 #include "i2c.hpp"
 
 namespace SHTx {
-	I2C::I2C(PinName sda, PinName scl) :
-	scl_pin(scl), sda_pin(sda), frequency(10) {
-		this->sda_pin.output();
-		this->scl_pin.output();
-	}
+    I2C::I2C(PinName sda, PinName scl) :
+    scl_pin(scl), sda_pin(sda), frequency(10) {
+        this->sda_pin.output();
+        this->scl_pin.output();
+    }
 
-	void
-	I2C::setFrequency(uint32_t hz) {
-		this->frequency = (1000000 / hz);
-	}
+    void
+    I2C::setFrequency(uint32_t hz) {
+        this->frequency = (1000000 / hz);
+    }
 
-	void
-	I2C::start(void) {
-	    this->output();
-		this->sda(1);
-		this->scl(1);
-		this->sda(0);
-		this->scl(0);
-		this->scl(1);
-		this->sda(1);
-		this->scl(0);
-	}
+    void
+    I2C::start(void) {
+        this->output();
+        this->sda(1);
+        this->scl(1);
+        this->sda(0);
+        this->scl(0);
+        this->scl(1);
+        this->sda(1);
+        this->scl(0);
+    }
 
-	void
-	I2C::stop(void) {
-	    this->output();
-		this->sda(0);
-		this->scl(1);
-		this->sda(1);
-	}
+    void
+    I2C::stop(void) {
+        this->output();
+        this->sda(0);
+        this->scl(1);
+        this->sda(1);
+    }
 
-	bool
-	I2C::wait(void) {
-		bool ack = false;
-	
-		this->input();
-		for (uint8_t i = 0; i < 500 && !ack; i++) {
-			wait_ms(1);
-			ack = !this->sda_pin;
-		}
-	
-		return ack;
-	}
-	
-	void
-	I2C::reset(void) {
-		this->output();
-		for (uint8_t i = 9; i; i--) {
-			this->shift_out(1);
-		}
-		this->start();
-		this->scl(1);
-	}
+    bool
+    I2C::wait(void) {
+        bool ack = false;
+    
+        this->input();
+        for (uint8_t i = 0; i < 500 && !ack; i++) {
+            wait_ms(1);
+            ack = !this->sda_pin;
+        }
+    
+        return ack;
+    }
+    
+    void
+    I2C::reset(void) {
+        this->output();
+        for (uint8_t i = 9; i; i--) {
+            this->shift_out(1);
+        }
+        this->start();
+        this->scl(1);
+    }
 
-	bool
-	I2C::write(uint8_t data) {
-	    bool ack;
+    bool
+    I2C::write(uint8_t data) {
+        bool ack;
 
-	    this->output();
-		for (uint8_t i = 8; i; i--) {
-		    this->shift_out(data & 0x80);
-		    data <<= 1;
-		}
+        this->output();
+        for (uint8_t i = 8; i; i--) {
+            this->shift_out(data & 0x80);
+            data <<= 1;
+        }
     
-	    this->input();
-	    ack = !this->shift_in();
+        this->input();
+        ack = !this->shift_in();
     
-		return ack;
-	}
+        return ack;
+    }
 
-	uint8_t
-	I2C::read(bool ack) {
-		uint8_t data = 0;
-	
-	    this->input();
-		for (uint8_t i = 8; i; i--) {
-		    data <<= 1;
-			data  |= this->shift_in();
-		}
-	
-	    this->output();
-		this->shift_out(!ack);
-	
-		return data;
-	}
+    uint8_t
+    I2C::read(bool ack) {
+        uint8_t data = 0;
+    
+        this->input();
+        for (uint8_t i = 8; i; i--) {
+            data <<= 1;
+            data  |= this->shift_in();
+        }
+    
+        this->output();
+        this->shift_out(!ack);
+    
+        return data;
+    }
 
-	void
-	I2C::output(void) {
-		this->sda_pin.output();
-	}
+    void
+    I2C::output(void) {
+        this->sda_pin.output();
+    }
 
-	void
-	I2C::input(void) {
-		this->sda_pin.input();
-	}
+    void
+    I2C::input(void) {
+        this->sda_pin.input();
+    }
 
-	void
-	I2C::sda(bool value) {
-		this->sda_pin = value;
-		wait_us(this->frequency);
-	}
+    void
+    I2C::sda(bool value) {
+        this->sda_pin = value;
+        wait_us(this->frequency);
+    }
 
-	void
-	I2C::scl(bool value) {
-		this->scl_pin = value;
-		wait_us(this->frequency);
-	}
+    void
+    I2C::scl(bool value) {
+        this->scl_pin = value;
+        wait_us(this->frequency);
+    }
 
-	void
-	I2C::shift_out(bool bit) {
-	    this->sda(bit);
-		this->scl(1);
-		this->scl(0);
-	}
+    void
+    I2C::shift_out(bool bit) {
+        this->sda(bit);
+        this->scl(1);
+        this->scl(0);
+    }
 
-	bool
-	I2C::shift_in(void) {
-	    wait_us(this->frequency);
-		this->scl(1);
-		bool bit = this->sda_pin;
-		this->scl(0);
-		return bit;
-	}
+    bool
+    I2C::shift_in(void) {
+        wait_us(this->frequency);
+        this->scl(1);
+        bool bit = this->sda_pin;
+        this->scl(0);
+        return bit;
+    }
 }
\ No newline at end of file
diff -r 8465801be23f -r cd8e210049b9 i2c.hpp
--- a/i2c.hpp	Fri Nov 19 16:24:46 2010 +0000
+++ b/i2c.hpp	Mon Mar 04 19:11:37 2013 +0000
@@ -86,12 +86,12 @@
          */
         bool wait(void);
 
-		/**
-		 * Function: reset
-		 *  If communication with the device is lost
-		 *  the command will reset the serial interface
-		 */
-		void reset(void);
+        /**
+         * Function: reset
+         *  If communication with the device is lost
+         *  the command will reset the serial interface
+         */
+        void reset(void);
     
         /**
          * Function: write
diff -r 8465801be23f -r cd8e210049b9 sht15.cpp
--- a/sht15.cpp	Fri Nov 19 16:24:46 2010 +0000
+++ b/sht15.cpp	Mon Mar 04 19:11:37 2013 +0000
@@ -68,11 +68,11 @@
         return this->writeRegister();
     }
 
-	bool
-	SHT15::setOTPReload(bool value) {
-		this->setFlag(flag_otp_reload, !value);
-		return this->writeRegister();
-	}
+    bool
+    SHT15::setOTPReload(bool value) {
+        this->setFlag(flag_otp_reload, !value);
+        return this->writeRegister();
+    }
 
     void
     SHT15::setScale(bool value) {
@@ -106,17 +106,17 @@
             this->status_register = 0;
             this->humidity = 0;
             this->temperature = 0;            
-			wait_ms(11);
+            wait_ms(11);
             return true;
         }
     
         return false;
     }
 
-	void
-	SHT15::connectionReset(void) {
-		this->i2c.reset();
-	}
+    void
+    SHT15::connectionReset(void) {
+        this->i2c.reset();
+    }
 
     float
     SHT15::convertTemperature(uint16_t sot, bool res, bool scale) {
diff -r 8465801be23f -r cd8e210049b9 sht15.hpp
--- a/sht15.hpp	Fri Nov 19 16:24:46 2010 +0000
+++ b/sht15.hpp	Mon Mar 04 19:11:37 2013 +0000
@@ -149,17 +149,17 @@
          */
         bool setResolution(bool value);
 
-		/**
+        /**
          * Function: setOTPReload
          *  With this operation the calibration data is 
-		 *  uploaded to the register before each measurement. This 
+         *  uploaded to the register before each measurement. This 
          *  may be deactivated for reducing measurement time by 
          *  about 10ms
          *
          * Values:
          *  value - true->enabled, false->disabled
          */
-		bool setOTPReload(bool value);
+        bool setOTPReload(bool value);
 
         /**
          * Function: setScale
@@ -183,20 +183,20 @@
         /**
          * Function: reset
          *  Resets the interface, clears the 
-		 *  status register to default values.
-		 *  And waits for a minimum of 11ms.
+         *  status register to default values.
+         *  And waits for a minimum of 11ms.
          *
          * Values:
          *  return - operation result
          */
         bool reset(void);
 
-		/**
+        /**
          * Function: connectionReset
          *  If communication with the device is lost
-		 *  the command will reset the serial interface
+         *  the command will reset the serial interface
          */
-		void connectionReset(void);
+        void connectionReset(void);
     
     private: