Sille Van Landschoot / Mbed 2 deprecated m3Dpi-helloworld

Dependencies:   m3Dpi mbed-rtos mbed MbedJSONValue

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers binaryReporter.cpp Source File

binaryReporter.cpp

00001 #include "binaryReporter.h"
00002 
00003 void BinaryReporter::print(char* data, int size)
00004 {
00005     for(int i = 0; i < size; i++){
00006         out->putc(data[i]);
00007     }
00008 }
00009 
00010 void BinaryReporter::time(time_t seconds)
00011 {
00012 
00013 }
00014 
00015 void BinaryReporter::distance(m3dpi::Distance distance)
00016 {
00017     const int SIZE = 13;
00018     char data[SIZE] = {START,'a', SIZE-1, DISTANCE};
00019     data [4] = distance.front;
00020     data [5] = distance.front_right;
00021     data [6] = distance.right;
00022     data [7] = distance.back_right;
00023     data [8] = distance.back;
00024     data [9] = distance.back_left;
00025     data [10] = distance.left;
00026     data [11] = distance.front_left;
00027     data [12] = 0x00; // checksum
00028     print(data, SIZE);
00029 }
00030 
00031 void BinaryReporter::acceleration(m3dpi::Acceleration acc)
00032 {
00033     const int SIZE = 11;
00034     char data[SIZE] = {START,'a', SIZE-1, ACCELERATION};
00035     data[4] = acc.x / 256;
00036     data[5] = acc.x % 256;
00037     data[6] = acc.y / 256;
00038     data[5] = acc.y % 256;
00039     data[8] = acc.z / 256;
00040     data[9] = acc.z % 256;
00041     data [10] = 0x00; // checksum
00042     print(data, SIZE);
00043 }
00044 
00045 void BinaryReporter::direction(m3dpi::Direction direction)
00046 {
00047     const int SIZE = 11;
00048     char data[SIZE] = {START,'a', SIZE-1, DIRECTION};
00049     data[4] = direction.x / 256;
00050     data[5] = direction.x % 256;
00051     data[6] = direction.y / 256;
00052     data[5] = direction.y % 256;
00053     data[8] = direction.z / 256;
00054     data[9] = direction.z % 256;
00055     data [10] = 0x00; // checksum
00056     print(data, SIZE);
00057 }
00058 
00059 void BinaryReporter::rotation(m3dpi::Rotation rotation)
00060 {
00061     const int SIZE = 11;
00062     char data[SIZE] = {START,'a', SIZE-1, ROTATION};
00063     data[4] = rotation.x / 256;
00064     data[5] = rotation.x % 256;
00065     data[6] = rotation.y / 256;
00066     data[5] = rotation.y % 256;
00067     data[8] = rotation.z / 256;
00068     data[9] = rotation.z % 256;
00069     data [10] = 0x00; // checksum
00070     print(data, SIZE);
00071 }