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.
Diff: DataControl.cpp
- Revision:
- 0:65149aeacbcc
- Child:
- 1:d37d53d33f0d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DataControl.cpp Tue Aug 23 16:59:41 2022 +0000
@@ -0,0 +1,46 @@
+
+#include "DataControl.h"
+
+DataControl::DataControl()
+{
+ separated_data_size = 0;
+ for(int i=0; i<5; i++) dataBuff[i] = 0;
+}
+
+
+//bit cotrol--------------------------------------------------------//
+
+void DataControl::dataSeparate(uint16_t data, char* array)
+{
+ array[0] = data & 0xFF;
+ array[1] = (data & 0xFF00) >> 8;
+}
+
+int DataControl::dataCombine(unsigned char *array, int _data_size){
+ for(int i=0; i<5; i++) dataBuff[i] = 0;
+ for(int i=0; i<_data_size; i++) {
+ dataBuff[i] = array[i];
+ dataBuff[4] |= dataBuff[i] << (i*8);
+ }
+ return dataBuff[4];
+}
+
+//------------------------------------------------------------------//
+
+
+
+//function to return------------------------------------------------//
+void DataControl::dataSet(int data, char *data_array)
+{
+ separated_data_size = sizeof(data); // 4
+ dataSeparate(data & 0xFFFF, data_array);
+ dataSeparate((data & 0xFFFF0000) >> 16, &data_array[2]);
+}
+
+
+void DataControl::dataSet(uint16_t data, char *data_array)
+{
+ separated_data_size = sizeof(data); // 2
+ dataSeparate(data, data_array);
+}
+//------------------------------------------------------------------//