Gets messages form the pc and translates it to I2C and back.

Dependencies:   DevInterfaces I2Cinterfaces MCP4725 mbed

Committer:
katrijnverhasselt
Date:
Wed May 18 11:35:45 2016 +0000
Revision:
1:8ba039abd9b8
Parent:
0:b40341017545
Fixed it!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
katrijnverhasselt 0:b40341017545 1 #pragma once
katrijnverhasselt 0:b40341017545 2
katrijnverhasselt 0:b40341017545 3 #include "mbed.h"
katrijnverhasselt 0:b40341017545 4
katrijnverhasselt 0:b40341017545 5 // Splits a number into a set number of bytes
katrijnverhasselt 0:b40341017545 6 inline void ByteShift(int num, int numBytes, int8_t** bytes, bool lowToHigh =false) {
katrijnverhasselt 0:b40341017545 7 *bytes = new int8_t[numBytes];
katrijnverhasselt 0:b40341017545 8 for (int i = 0; i < numBytes; i++) {
katrijnverhasselt 0:b40341017545 9 (*bytes)[i] = (num >> 8*(lowToHigh ? i : numBytes-i-1)) & 0xFF;
katrijnverhasselt 0:b40341017545 10 }
katrijnverhasselt 0:b40341017545 11 }
katrijnverhasselt 0:b40341017545 12
katrijnverhasselt 0:b40341017545 13 // Unsplits a number of bytes back to a number
katrijnverhasselt 0:b40341017545 14 inline int ByteUnshift(const int8_t* bytes, int numBytes, bool lowToHigh =false) {
katrijnverhasselt 0:b40341017545 15 int result = 0;
katrijnverhasselt 0:b40341017545 16 for (int i = 0; i < numBytes; i++)
katrijnverhasselt 0:b40341017545 17 result += (bytes[i] << 8*(lowToHigh ? i : numBytes-i-1));
katrijnverhasselt 0:b40341017545 18 return result;
katrijnverhasselt 0:b40341017545 19 }
katrijnverhasselt 0:b40341017545 20
katrijnverhasselt 0:b40341017545 21 // Copies an array deeply
katrijnverhasselt 0:b40341017545 22 inline void DeepCopy(const int8_t* source, int size, int8_t* dest) {
katrijnverhasselt 0:b40341017545 23 //*dest = new int8_t[size];
katrijnverhasselt 0:b40341017545 24 for (int i = 0; i < size; i++)
katrijnverhasselt 0:b40341017545 25 dest[i] = source[i];
katrijnverhasselt 0:b40341017545 26 }