mirror of
https://github.com/erjiang/usbscale.git
synced 2025-06-28 09:00:58 -06:00
Fixed weight reading to be properly-scaled double
This commit is contained in:
parent
0268fa50b0
commit
f4c33e687d
@ -258,7 +258,7 @@ static int print_scale_data(char* dat) {
|
|||||||
uint8_t status = dat[1];
|
uint8_t status = dat[1];
|
||||||
uint8_t unit = dat[2];
|
uint8_t unit = dat[2];
|
||||||
uint8_t expt = dat[3];
|
uint8_t expt = dat[3];
|
||||||
long weight = dat[4] + (dat[5] << 8);
|
double weight = (double)(dat[4] + (dat[5] << 8)) / 10;
|
||||||
|
|
||||||
if(expt != 255 && expt != 0) {
|
if(expt != 255 && expt != 0) {
|
||||||
weight = pow(weight, expt);
|
weight = pow(weight, expt);
|
||||||
@ -295,7 +295,7 @@ static int print_scale_data(char* dat) {
|
|||||||
// the `UNITS` lookup table for unit names.
|
// the `UNITS` lookup table for unit names.
|
||||||
//
|
//
|
||||||
case 0x04:
|
case 0x04:
|
||||||
printf("%ld %s\n", weight, UNITS[unit]);
|
printf("%g %s\n", weight, UNITS[unit]);
|
||||||
return 0;
|
return 0;
|
||||||
case 0x05:
|
case 0x05:
|
||||||
if(status != lastStatus)
|
if(status != lastStatus)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user