![](/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
Diff: Utility.h
- Revision:
- 0:b40341017545
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Utility.h Wed May 18 11:22:41 2016 +0000 @@ -0,0 +1,26 @@ +#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]; +} \ No newline at end of file