mirror of
https://github.com/erjiang/usbscale.git
synced 2025-06-28 00:50:59 -06:00
Fix endian conversion when reading weight
This commit is contained in:
parent
3ffb1693cb
commit
905e8dd17f
@ -376,8 +376,10 @@ static int print_scale_data(unsigned char* dat) {
|
|||||||
uint8_t unit = dat[2];
|
uint8_t unit = dat[2];
|
||||||
// According to the docs, scaling applied to the data as a base ten exponent
|
// According to the docs, scaling applied to the data as a base ten exponent
|
||||||
int8_t expt = dat[3];
|
int8_t expt = dat[3];
|
||||||
// convert to machine order at all times
|
// combine the little-endian weight bytes without relying on system
|
||||||
double weight = (double) le16toh(dat[5] << 8 | dat[4]);
|
// endianness. dat[4] is the low byte and dat[5] is the high byte.
|
||||||
|
uint16_t raw_weight = (uint16_t)dat[4] | ((uint16_t)dat[5] << 8);
|
||||||
|
double weight = (double)raw_weight;
|
||||||
// since the expt is signed, we do not need no trickery
|
// since the expt is signed, we do not need no trickery
|
||||||
weight = weight * pow(10, expt);
|
weight = weight * pow(10, expt);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user