![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Gets messages form the pc and translates it to I2C and back.
Dependencies: DevInterfaces I2Cinterfaces MCP4725 mbed
Utility.h
- Committer:
- katrijnverhasselt
- Date:
- 2016-05-18
- Revision:
- 0:b40341017545
File content as of revision 0:b40341017545:
#pragma once #include "mbed.h" // Splits a number into a set number of bytes inline void ByteShift(int num, int numBytes, int8_t** bytes, bool lowToHigh =false) { *bytes = new int8_t[numBytes]; for (int i = 0; i < numBytes; i++) { (*bytes)[i] = (num >> 8*(lowToHigh ? i : numBytes-i-1)) & 0xFF; } } // Unsplits a number of bytes back to a number inline int ByteUnshift(const int8_t* bytes, int numBytes, bool lowToHigh =false) { int result = 0; for (int i = 0; i < numBytes; i++) result += (bytes[i] << 8*(lowToHigh ? i : numBytes-i-1)); return result; } // Copies an array deeply inline void DeepCopy(const int8_t* source, int size, int8_t* dest) { //*dest = new int8_t[size]; for (int i = 0; i < size; i++) dest[i] = source[i]; }