NerfUS / NerfUSXbee

Dependents:   NerfUS-Coord NerfUSTarget

Fork of APP3_xbee by Team APP

Revision:
6:b70f32a80d51
Parent:
5:cd3c79853dc8
Child:
7:c65c4c98d237
diff -r cd3c79853dc8 -r b70f32a80d51 xbee.cpp
--- a/xbee.cpp	Sun Feb 12 22:42:45 2017 +0000
+++ b/xbee.cpp	Mon Feb 13 19:13:50 2017 +0000
@@ -200,3 +200,49 @@
     
     return parsed_frame;
 }
+
+void parsed_frame_to_string(const vector<char>& parsed_frame, char* readable_string_output)
+{
+    const char event_type = parsed_frame[1];
+    switch(event_type)
+    {
+        case EVENT_TYPE_BUTTON:
+            parsed_button_event_frame_to_string(parsed_frame, readable_string_output);
+            break;
+            
+        case EVENT_TYPE_ACCELEROMETER:
+            parsed_accelerometer_event_frame_to_string(parsed_frame, readable_string_output);
+            break;
+            
+        default:
+            strcpy(readable_string_output, "Invalid event type");
+            break;
+    }
+}
+
+void parsed_button_event_frame_to_string(const vector<char>& parsed_frame, char* readable_string_output)
+{
+    const char button_state = parsed_frame[2];
+    switch(button_state)
+    {
+        case 0x00:
+            strcpy(readable_string_output, "Button state: released");
+            break;
+            
+        case 0x01:
+            strcpy(readable_string_output, "Button state: pressed");
+            break;
+            
+        default:
+            strcpy(readable_string_output, "Button state: invalid state");
+            break;
+    }
+}
+
+void parsed_accelerometer_event_frame_to_string(const vector<char>& parsed_frame, char* readable_string_output)
+{
+    const uint8_t x = parsed_frame[2];
+    const uint8_t y = parsed_frame[3];
+    const uint8_t z = parsed_frame[4];
+    sprintf(readable_string_output, "Accelerometer state: x=0x%X, y=0x%X, z=0x%X", x, y, z);
+}
\ No newline at end of file