taiyou komazawa / Alpha_Apper

Dependents:   I2C Alpha_Apper I2C

Files at this revision

API Documentation at this revision

Comitter:
Komazawa_sun
Date:
Fri Sep 08 03:27:32 2017 +0000
Child:
1:8076e33b6ba1
Commit message:
????; ;

Changed in this revision

Alpha_ApprI2C_ID.h Show annotated file Show diff for this revision Revisions of this file
ApprI2CMaster.cpp Show annotated file Show diff for this revision Revisions of this file
ApprI2CMaster.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Alpha_ApprI2C_ID.h	Fri Sep 08 03:27:32 2017 +0000
@@ -0,0 +1,28 @@
+#ifndef ALPHA_APPR_I2C_ID_H
+#define ALPHA_APPR_I2C_ID_H
+
+namespace alpha_a
+{
+    const int s1_addr = 0x0b;
+    const int s2_addr = 0x0c;
+    
+    enum ID
+    {
+        sht_pwr   = 0x00,
+        sht_ang   = 0x01,
+        rld_belt  = 0x02,
+        rld_disk  = 0x03,
+        
+        r_panta   = 0x04,
+        l_panta   = 0x05,
+        
+        rld_t_lim = 0x06
+    };
+    
+    enum f_type
+    {
+        sig,unsig
+    };
+}
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ApprI2CMaster.cpp	Fri Sep 08 03:27:32 2017 +0000
@@ -0,0 +1,47 @@
+#include "ApprI2CMaster.h"
+
+ApprI2CMaster::ApprI2CMaster(alpha_a::ID my_id_, alpha_a::f_type my_type_, int addr_, I2C *master_)
+{
+    _my_id = my_id_;
+    _my_type = my_type_;
+    _master = master_;
+    _addr = addr_;
+}
+
+void ApprI2CMaster::write(uint8_t data)
+{
+    char data_array[3] = {};
+    
+    data_array[0] = _my_id;
+    data_array[1] = _my_type;
+    data_array[2] = (char)data;
+    
+    _master->write(_addr, data_array, 3);
+}
+
+int ApprI2CMaster::read()
+{
+    char buffer[3] = {};
+    int res_data = 0;
+    
+    _master->read(_addr, buffer, 3);
+    
+    if((alpha_a::ID)buffer[0] == _my_id)
+    {
+        switch((alpha_a::f_type)buffer[1])
+        {
+            case alpha_a::sig:
+                res_data = (signed int)buffer[2];
+                break;
+            case alpha_a::unsig:
+                res_data = (unsigned int)buffer[2];
+                break;
+        };
+        
+        return res_data;
+    }
+    else
+    {
+        return res_data;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ApprI2CMaster.h	Fri Sep 08 03:27:32 2017 +0000
@@ -0,0 +1,24 @@
+#ifndef APPR_I2C_MASTER_H
+#define APPR_I2C_MASTER_H
+
+#include "Alpha_ApprI2C_ID.h"
+#include "I2CTransporter.h"
+
+
+class ApprI2CMaster
+{
+    public:
+        ApprI2CMaster(alpha_a::ID my_id_, alpha_a::f_type my_type_, int addr_, I2C *master_);
+        void write(uint8_t data);
+        int read();
+        
+    private:
+        alpha_a::ID _my_id;
+        alpha_a::f_type _my_type;
+        I2C *_master;
+        int _addr; 
+        
+        
+};
+
+#endif
\ No newline at end of file