L3GD20 & L3G4200D / STMicroelectronics / MEMS motion sensor, three-axis gyroscope library

Dependents:   GR-PEACH_test_wo_rtos GR-PEACH_test_on_rtos_works_well

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Wed Aug 23 09:25:40 2017 +0000
Parent:
6:451811697299
Commit message:
countermeasure for NonCopyable

Changed in this revision

L3GD20.cpp Show annotated file Show diff for this revision Revisions of this file
L3GD20.h Show annotated file Show diff for this revision Revisions of this file
diff -r 451811697299 -r f5c0fe6ed71a L3GD20.cpp
--- a/L3GD20.cpp	Tue Feb 24 12:24:29 2015 +0000
+++ b/L3GD20.cpp	Wed Aug 23 09:25:40 2017 +0000
@@ -7,48 +7,47 @@
  *      http://www.st.com/web/catalog/sense_power/FM89/SC1288
  *          /PF250373?sc=internet/analog/product/250373.jsp
  *
- * Copyright (c) 2014,'15 Kenji Arai / JH1PJL
+ * Copyright (c) 2014,'15,'17 Kenji Arai / JH1PJL
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
- *      Created: July      13th, 2014
- *      Revised: Feburary  24th, 2015
- *
- * 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.
+ *      Created: July       13th, 2014
+ *      Revised: August     23rd, 2017
  */
 
 #include "L3GD20.h"
 
 L3GX_GYRO::L3GX_GYRO (PinName p_sda, PinName p_scl,
-                      uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale) : _i2c(p_sda, p_scl)
+    uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale)
+ : _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
     _i2c.frequency(400000);
     initialize (addr, data_rate, bandwidth, fullscale);
 }
 
-L3GX_GYRO::L3GX_GYRO (PinName p_sda, PinName p_scl, uint8_t addr) : _i2c(p_sda, p_scl)
+L3GX_GYRO::L3GX_GYRO (PinName p_sda, PinName p_scl, uint8_t addr)
+ : _i2c_p(new I2C(p_sda, p_scl)), _i2c(*_i2c_p)
 {
     _i2c.frequency(400000);
     initialize (addr, L3GX_DR_95HZ, L3GX_BW_HI, L3GX_FS_250DPS);
 }
 
 L3GX_GYRO::L3GX_GYRO (I2C& p_i2c,
-                      uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale) : _i2c(p_i2c)
+    uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale)
+ : _i2c(p_i2c)
 {
     _i2c.frequency(400000);
     initialize (addr, data_rate, bandwidth, fullscale);
 }
 
-L3GX_GYRO::L3GX_GYRO (I2C& p_i2c, uint8_t addr) : _i2c(p_i2c)
+L3GX_GYRO::L3GX_GYRO (I2C& p_i2c, uint8_t addr)
+ : _i2c(p_i2c)
 {
     _i2c.frequency(400000);
     initialize (addr, L3GX_DR_95HZ, L3GX_BW_HI, L3GX_FS_250DPS);
 }
 
-void L3GX_GYRO::initialize (uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale)
+void L3GX_GYRO::initialize (uint8_t addr, uint8_t data_rate,
+                     uint8_t bandwidth, uint8_t fullscale)
 {
     // Check gyro is available of not
     gyro_addr = addr;
@@ -177,3 +176,5 @@
         _i2c.write(gyro_addr, dt, 2, false);
     }
 }
+
+
diff -r 451811697299 -r f5c0fe6ed71a L3GD20.h
--- a/L3GD20.h	Tue Feb 24 12:24:29 2015 +0000
+++ b/L3GD20.h	Wed Aug 23 09:25:40 2017 +0000
@@ -7,17 +7,11 @@
  *      http://www.st.com/web/catalog/sense_power/FM89/SC1288
  *          /PF250373?sc=internet/analog/product/250373.jsp
  *
- * Copyright (c) 2014,'15 Kenji Arai / JH1PJL
+ * Copyright (c) 2014,'15,'17 Kenji Arai / JH1PJL
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
- *      Created: July      13th, 2014
- *      Revised: Feburary  24th, 2015
- *
- * 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.
+ *      Created: July       13th, 2014
+ *      Revised: August     23rd, 2017
  */
 
 #ifndef L3GD20_GYRO_H
@@ -219,7 +213,8 @@
 protected:
     void initialize(uint8_t, uint8_t, uint8_t, uint8_t);
 
-    I2C _i2c;
+    I2C *_i2c_p;
+    I2C &_i2c;
 
 private:
     float   fs_factor;  // full scale factor
@@ -230,3 +225,4 @@
 };
 
 #endif      // L3GD20_GYRO_H
+