maybe this float stuff already works

This commit is contained in:
Wolfgang Hottgenroth 2015-03-03 22:21:16 +01:00
parent 32f9365ee3
commit 540ebbab25

View File

@ -59,54 +59,60 @@ void dispSetDigit(uint8_t digit, uint8_t value) {
void dispSetFloat(uint8_t unit, float value) {
// if ((value < -99) || (value > 999)) {
// dispSetError();
// } else {
// uint8_t neg = (value < 0) ? 1 : 0;
// value = abs(value);
// uint16_t preComma = (uint16_t)value;
// uint16_t postComma = round((value - (float)preComma) * 10);
// if (postComma == 10) {
// postComma = 0;
// preComma += 1;
// }
// if ((preComma == 0) && (postComma == 0)) {
// neg = false;
// }
//
// uint8_t digit1 = preComma / 100;
// uint8_t remVal = preComma - (digit1 * 100);
// uint8_t digit2 = remVal / 10;
// remVal = remVal - (digit2 * 10);
// uint8_t digit3 = remVal;
//
// if (digit1 == 0) {
// if (neg) {
// digit1 = 0x0a;
// } else {
// digit1 = 0x0f;
// }
// }
//
// if (digit1 > 0x09 && digit2 == 0) {
// if (neg) {
// digit2 = 0x0a;
// digit1 = 0x0f;
// } else {
// digit2 = 0x0f;
// }
// }
//
if ((value < -99) || (value > 999)) {
dispSetError();
} else {
bool neg = value < 0;
value = (value < 0) ? -1 * value : value;
uint16_t preComma = (uint16_t)value;
uint16_t postComma = round((value - (float)preComma) * 10);
if (postComma == 10) {
postComma = 0;
preComma += 1;
}
if ((preComma == 0) && (postComma == 0)) {
neg = false;
}
uint8_t digit4 = postComma;
uint8_t digit3 = preComma / 100;
uint8_t remVal = preComma - (digit3 * 100);
uint8_t digit2 = remVal / 10;
remVal = remVal - (digit2 * 10);
uint8_t digit1 = remVal;
if (digit3 == 0) {
if (neg) {
digit3 = 0x0a;
} else {
digit3 = 0x0f;
}
}
if (digit3 > 0x09 && digit2 == 0) {
if (neg) {
digit2 = 0x0a;
digit3 = 0x0f;
} else {
digit2 = 0x0f;
}
}
// digit3 |= 0x80;
//
// spiXfer16(0x0100 | digit1);
// spiXfer16(0x0200 | digit2);
// spiXfer16(0x0300 | digit3);
//
// spiXfer16(0x0400 | postComma);
//
//
// }
if (unit == 0) {
spiXfer16(0x0100 | digit1);
spiXfer16(0x0200 | digit2);
spiXfer16(0x0300 | digit3);
spiXfer16(0x0400 | postComma);
} else {
spiXfer16(0x0500 | digit1);
spiXfer16(0x0600 | digit2);
spiXfer16(0x0700 | digit3);
spiXfer16(0x0800 | postComma);
}
}
}
void dispSet(uint8_t unit, int16_t value) {
@ -116,9 +122,8 @@ void dispSet(uint8_t unit, int16_t value) {
if ((value < -999) || (value > 9999)) {
dispSetError();
} else {
uint8_t neg = (value < 0) ? 1 : 0;
bool neg = value < 0;
value = (value < 0) ? -1 * value : value;
// value = abs(value);
uint8_t digit3 = value / 1000;
uint16_t remVal = value - (digit3 * 1000);