Akinori Hashimoto / SO1602A

Dependents:   NEW_LineTraceHub NEW_LineTraceHub_2 ColorSensorTest

Files at this revision

API Documentation at this revision

Comitter:
AkinoriHashimoto
Date:
Fri Nov 06 06:23:52 2015 +0000
Parent:
3:eaaedd09fa6b
Commit message:
Adj. Constructer, Refer

Changed in this revision

SO1602A.cpp Show annotated file Show diff for this revision Revisions of this file
SO1602A.h Show annotated file Show diff for this revision Revisions of this file
--- a/SO1602A.cpp	Mon Oct 19 05:44:49 2015 +0000
+++ b/SO1602A.cpp	Fri Nov 06 06:23:52 2015 +0000
@@ -1,15 +1,20 @@
 #include "SO1602A.h"
 
 SO1602A::SO1602A (PinName sda, PinName scl, char address)
-    : i2c(sda, scl), addr(address)
+    : p_i2c(new I2C(sda, scl)), i2c(*p_i2c), addr(address)
 {
     init();
 }
 SO1602A::SO1602A (I2C &_i2c, char address)
-    : i2c(_i2c), addr(address)
+    : p_i2c(NULL), i2c(_i2c), addr(address)
 {
     init();
 }
+SO1602A::~SO1602A()
+{
+    if(p_i2c != NULL)
+    delete p_i2c;
+}
 
 bool SO1602A::cmd(char chr)
 {
--- a/SO1602A.h	Mon Oct 19 05:44:49 2015 +0000
+++ b/SO1602A.h	Fri Nov 06 06:23:52 2015 +0000
@@ -36,7 +36,7 @@
 public:
     SO1602A (PinName sda, PinName scl, char address= 0x78);
     SO1602A (I2C &_i2c, char address= 0x78);
-    
+    ~SO1602A();
 //  ******************** printf() future of C-language. ***************************
 
     /** Initialize
@@ -63,7 +63,8 @@
     void setDispFlag(bool disp= true, bool cursor= true, bool blink= true);
 
 private:    
-    I2C i2c;
+    I2C *p_i2c;
+    I2C &i2c;
     char addr;
     char buf[3];
     int col, row;