Refactoring

This commit is contained in:
Lubos Petrovic
2020-11-30 23:27:42 +01:00
parent 0bfac0e76f
commit f3d64e938d
26 changed files with 2137 additions and 2073 deletions

37
LiveData.cpp Normal file
View File

@@ -0,0 +1,37 @@
#ifndef LIVEDATA_CPP
#define LIVEDATA_CPP
#include "LiveData.h"
/**
Hex to dec (1-2 byte values, signed/unsigned)
For 4 byte change int to long and add part for signed numbers
*/
float LiveData::hexToDec(String hexString, byte bytes, bool signedNum) {
unsigned int decValue = 0;
unsigned int nextInt;
for (int i = 0; i < hexString.length(); i++) {
nextInt = int(hexString.charAt(i));
if (nextInt >= 48 && nextInt <= 57) nextInt = map(nextInt, 48, 57, 0, 9);
if (nextInt >= 65 && nextInt <= 70) nextInt = map(nextInt, 65, 70, 10, 15);
if (nextInt >= 97 && nextInt <= 102) nextInt = map(nextInt, 97, 102, 10, 15);
nextInt = constrain(nextInt, 0, 15);
decValue = (decValue * 16) + nextInt;
}
// Unsigned - do nothing
if (!signedNum) {
return decValue;
}
// Signed for 1, 2 bytes
if (bytes == 1) {
return (decValue > 127 ? (float)decValue - 256.0 : decValue);
}
return (decValue > 32767 ? (float)decValue - 65536.0 : decValue);
}
//
#endif // LIVEDATA_CPP