round
This commit is contained in:
parent
ed03619da3
commit
163c788a45
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include "mySpi.h"
|
#include "mySpi.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ void dispSetFloat(uint8_t unit, float value) {
|
|||||||
bool neg = value < 0;
|
bool neg = value < 0;
|
||||||
value = (value < 0) ? -1 * value : 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 = round16((value - (float)preComma) * 10);
|
||||||
if (postComma == 10) {
|
if (postComma == 10) {
|
||||||
postComma = 0;
|
postComma = 0;
|
||||||
preComma += 1;
|
preComma += 1;
|
||||||
@ -74,32 +75,32 @@ void dispSetFloat(uint8_t unit, float value) {
|
|||||||
neg = false;
|
neg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t digit4 = postComma;
|
uint8_t digit1 = postComma;
|
||||||
|
|
||||||
uint8_t digit3 = preComma / 100;
|
uint8_t digit4 = preComma / 100;
|
||||||
uint8_t remVal = preComma - (digit3 * 100);
|
uint8_t remVal = preComma - (digit4 * 100);
|
||||||
uint8_t digit2 = remVal / 10;
|
uint8_t digit3 = remVal / 10;
|
||||||
remVal = remVal - (digit2 * 10);
|
remVal = remVal - (digit3 * 10);
|
||||||
uint8_t digit1 = remVal;
|
uint8_t digit2 = remVal;
|
||||||
|
|
||||||
if (digit3 == 0) {
|
if (digit4 == 0) {
|
||||||
|
if (neg) {
|
||||||
|
digit4 = 0x0a;
|
||||||
|
} else {
|
||||||
|
digit4 = 0x0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (digit4 > 0x09 && digit3 == 0) {
|
||||||
if (neg) {
|
if (neg) {
|
||||||
digit3 = 0x0a;
|
digit3 = 0x0a;
|
||||||
|
digit4 = 0x0f;
|
||||||
} else {
|
} else {
|
||||||
digit3 = 0x0f;
|
digit3 = 0x0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (digit3 > 0x09 && digit2 == 0) {
|
digit2 |= 0x80;
|
||||||
if (neg) {
|
|
||||||
digit2 = 0x0a;
|
|
||||||
digit3 = 0x0f;
|
|
||||||
} else {
|
|
||||||
digit2 = 0x0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// digit3 |= 0x80;
|
|
||||||
|
|
||||||
if (unit == 0) {
|
if (unit == 0) {
|
||||||
spiXfer16(0x0100 | digit1);
|
spiXfer16(0x0100 | digit1);
|
||||||
|
@ -35,7 +35,7 @@ int main() {
|
|||||||
spiInit();
|
spiInit();
|
||||||
dispInit();
|
dispInit();
|
||||||
|
|
||||||
dispSet(0, -12);
|
dispSetFloat(0, -12.0);
|
||||||
dispSet(1, -990);
|
dispSet(1, -990);
|
||||||
|
|
||||||
__enable_interrupt();
|
__enable_interrupt();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@ -31,3 +32,9 @@ int32_t minmax(int32_t lowerBound, int32_t value, int32_t upperBound){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int16_t round16(float x) {
|
||||||
|
if (x < 0.0)
|
||||||
|
return (int16_t)(x - 0.5);
|
||||||
|
else
|
||||||
|
return (int16_t)(x + 0.5);
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
int32_t max(int32_t a, int32_t b);
|
int32_t max(int32_t a, int32_t b);
|
||||||
int32_t min(int32_t a, int32_t b);
|
int32_t min(int32_t a, int32_t b);
|
||||||
int32_t minmax(int32_t lowerBound, int32_t value, int32_t upperBound);
|
int32_t minmax(int32_t lowerBound, int32_t value, int32_t upperBound);
|
||||||
|
int16_t round16(float x);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user