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