[ion] Fix hexNumber().

Change-Id: Ic12e3f17ec5e6508613034c4b259eee2fd103be4
This commit is contained in:
Léa Saviot
2018-04-10 10:14:46 +02:00
parent 0e578fa0e6
commit b7fd109f93
3 changed files with 8 additions and 7 deletions

View File

@@ -30,11 +30,12 @@ bool isHex(char c) {
return hexChar(c) >= 0;
}
uint32_t hexNumber(const char * s) {
uint32_t hexNumber(const char * s, int maxLength) {
uint32_t result = 0;
int8_t digit = 0;
while ((digit = hexChar(*s++)) >= 0) {
result = (result << 4) | digit;
int index = 0;
while ((maxLength < 0 || index < maxLength) && s[index] != NULL) {
result = (result << 4) | hexChar(s[index]);
index++;
}
return result;
}

View File

@@ -31,7 +31,7 @@ extern const char * const sOFF;
void reply(const char * s);
int8_t hexChar(char c);
bool isHex(char c);
uint32_t hexNumber(const char * s);
uint32_t hexNumber(const char * s, int maxLength = -1);
}
}

View File

@@ -15,8 +15,8 @@ void Print(const char * input) {
return;
}
char x = hexNumber(input);
char y = hexNumber(input+3);
char x = hexNumber(input, 2);
char y = hexNumber(input+3, 2);
KDContext * ctx = KDIonContext::sharedContext();
ctx->drawString(input+6, KDPoint(x, y));