Praktyki / Mbed 2 deprecated BLE_Accelerometer_najnowsze_NRFUpdate

Dependencies:   BLE_API MMA8452Q mbed nRF51822

Fork of AAAatest_copy by Praktyki

Files at this revision

API Documentation at this revision

Comitter:
Radoj
Date:
Sun Apr 10 17:47:09 2016 +0000
Parent:
1:6199b90c3227
Child:
3:0f080eec3f0c
Commit message:
asdw

Changed in this revision

Service.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Service.h	Thu Apr 07 16:48:47 2016 +0000
+++ b/Service.h	Sun Apr 10 17:47:09 2016 +0000
@@ -34,20 +34,112 @@
     }
 
     void updateXState(float newState) {
-        printf("\n%f\r\n",newState);
-        ble.gattServer().write(xState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
+        
+        int length = sizeof(float);
+        
+        uint8_t bytes[sizeof(float)];
+          for(int i = 0; i < length; i++){
+            bytes[i] = ((uint8_t*)&newState)[i];
+            //printf("%x ",bytes[i]);
+           // printf("%d;",length);
+            }
+
+            
+            
+            int n = sizeof(bytes) / sizeof(bytes[0]);
+            //printf("%d",sizeof(bytes[0]));
+        ble.gattServer().write(xState.getValueHandle(), (uint8_t *)&bytes, n);
+        
+        
+        
+        //uint8_t *p = (uint8_t*)&newState;
+
+        //for (int i = 0; i < sizeof(newState); i++) printf("wwww 0x%02x ", p[i]);
+        //ble.gattServer().write(xState.getValueHandle(), (uint8_t *)&newState, sizeof(newState));
     }
     
     void updateYState(float newState) {
-        ble.gattServer().write(yState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
+        //ble.gattServer().write(yState.getValueHandle(), (uint8_t *)&newState, sizeof(newState));
+        int length = sizeof(float);
+        uint8_t bytes[sizeof(float)];
+          for(int i = 0; i < length; i++){
+            bytes[i] = ((uint8_t*)&newState)[i];
+            //printf("%x ",bytes[i]);
+            }
+            //printf("%d",sizeof(bytes[0]));
+            
+             int n = sizeof(bytes) / sizeof(bytes[0]);
+       ble.gattServer().write(yState.getValueHandle(), (uint8_t *)&bytes, n);
     }
     
     void updateZState(float newState) {
-        ble.gattServer().write(zState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
+        //ble.gattServer().write(zState.getValueHandle(), (uint8_t *)&newState, sizeof(newState));
+        int length = sizeof(float);
+        uint8_t bytes[sizeof(float)];
+          for(int i = 0; i < length; i++){
+            bytes[i] = ((uint8_t*)&newState)[i];
+            //printf("%x ",bytes[i]);
+            }
+            //printf("%d",sizeof(bytes[0]));
+             int n = sizeof(bytes) / sizeof(bytes[0]);
+        ble.gattServer().write(zState.getValueHandle(), (uint8_t *)&bytes, n);
     }
     
-    void updateALLState(float newState) {
-        ble.gattServer().write(allState.getValueHandle(), (uint8_t *)&newState, sizeof(float));
+    void updateALLState(float newState,float newStatey,float newStatez) {
+        
+        int length = 14;
+        uint8_t bytes[14];
+        
+        printf("dane: %f;%f;%f\n",newState, newStatey,newStatez);
+        
+        /*
+          for(int i = 0; i < length; i++){
+            if(i<=3){
+                bytes[i] = ((uint8_t*)&newState)[i];
+                printf("X: %x ",bytes[i]);
+            }
+            else if(i==4){
+                bytes[i] = 0xff;
+                printf("P: %x ",bytes[i]);
+                }
+            else if(i>4&&i<=8){
+                bytes[i] = ((uint8_t*)&newStatey)[i];
+                printf("Y: %x ",bytes[i]);
+                }
+            else if(i==9){
+                bytes[i] = 0xff;
+                printf("P: %x ",bytes[i]);
+                }
+            else if(i>9&&i<14){
+                bytes[i] = ((uint8_t*)&newStatez)[i];
+                printf("Z: %x ",bytes[i]);
+                }
+            }
+            */
+            
+            bytes[0] = ((uint8_t*)&newState)[0];
+            bytes[1] = ((uint8_t*)&newState)[1];
+            bytes[2] = ((uint8_t*)&newState)[2];
+            bytes[3] = ((uint8_t*)&newState)[3];
+            bytes[4] = 0xff;
+            bytes[5] = ((uint8_t*)&newStatey)[0];
+            bytes[6] = ((uint8_t*)&newStatey)[1];
+            bytes[7] = ((uint8_t*)&newStatey)[2];
+            bytes[8] = ((uint8_t*)&newStatey)[3];
+            bytes[9] = 0xff;
+            bytes[10] = ((uint8_t*)&newStatez)[0];
+            bytes[11] = ((uint8_t*)&newStatez)[1];
+            bytes[12] = ((uint8_t*)&newStatez)[2];
+            bytes[13] = ((uint8_t*)&newStatez)[3];
+            
+            for(int i=0;i<length;i++){
+                printf("%x ",bytes[i]);
+                }
+            
+             uint16_t n = sizeof(bytes) / sizeof(bytes[0]);
+             printf("%d",n);
+        
+        ble.gattServer().write(allState.getValueHandle(), (uint8_t *)&bytes, n);
     }
 
 private:
--- a/main.cpp	Thu Apr 07 16:48:47 2016 +0000
+++ b/main.cpp	Sun Apr 10 17:47:09 2016 +0000
@@ -39,7 +39,8 @@
         ServicePtr->updateXState(x);
         ServicePtr->updateYState(y);
         ServicePtr->updateZState(z);
-        printf("%f;%f;%f\r\n",x,y,z);
+        ServicePtr->updateALLState(x,y,z);
+        printf("%f;%f;%f; \r\n",x,y,z);
         }