Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Alpha_Apper by
Diff: ApprI2CMaster.cpp
- Revision:
- 0:11209e14c06c
- Child:
- 1:16f3ffabd868
--- /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
