Skip to content

Commit

Permalink
small bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
piif committed Nov 1, 2015
1 parent 4bf9ff9 commit b680bef
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions serialInput/serialInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,37 @@ void parseInput(byte *str, const int len, Stream &channel) {
}
channel.println("'.");

int value = 0, b = 10, s = 1;
for (int j = 1; j < len; j++) {
if (j == 1 && (char)str[j] == 'x') {
b = 16;
} else if (j == 1 && (char)str[j] == '-') {
s = -1;
} else {
value = value * b + convChar((char)str[j]);
}
}
value = value * s;

if (items[i].type == 'f' || items[i].type == 'I') {
((destFuncInt)(items[i].destination))(value, channel);
} else if (items[i].type == 'B') {
((destFuncByte)(items[i].destination))((byte)value, channel);
} else if (items[i].type == 'S') {
if (items[i].type == 'S') {
str[len] = '\0';
((destFuncString)(items[i].destination))((const char *)(str + 1), channel);
} else if (items[i].type == 'b') {
*((byte *)(items[i].destination)) = value;
} else if (items[i].type == 'i') {
*((int *)(items[i].destination)) = value;
} else if (items[i].type == 's') {
str[len] = '\0';
for(int j = 1; j <= len; j++) {
((char *)(items[i].destination))[j - 1] = str[j];
}
} else {
int value = 0, b = 10, s = 1;

for (int j = 1; j < len; j++) {
if (j == 1 && (char)str[j] == 'x') {
b = 16;
} else if (j == 1 && (char)str[j] == '-') {
s = -1;
} else {
value = value * b + convChar((char)str[j]);
}
}
value = value * s;

if (items[i].type == 'f' || items[i].type == 'I') {
((destFuncInt)(items[i].destination))(value, channel);
} else if (items[i].type == 'B') {
((destFuncByte)(items[i].destination))((byte)value, channel);
} else if (items[i].type == 'b') {
*((byte *)(items[i].destination)) = value;
} else if (items[i].type == 'i') {
*((int *)(items[i].destination)) = value;
}
}
return;
}
Expand Down

0 comments on commit b680bef

Please sign in to comment.