From f4c33e687da7ae977d555e82319c42ca33da2615 Mon Sep 17 00:00:00 2001 From: Eric Jiang Date: Tue, 1 Mar 2011 15:39:48 -0500 Subject: [PATCH] Fixed weight reading to be properly-scaled double --- usbscale.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usbscale.c b/usbscale.c index edf4bbf..5851ecf 100644 --- a/usbscale.c +++ b/usbscale.c @@ -258,7 +258,7 @@ static int print_scale_data(char* dat) { uint8_t status = dat[1]; uint8_t unit = dat[2]; 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) { weight = pow(weight, expt); @@ -295,7 +295,7 @@ static int print_scale_data(char* dat) { // the `UNITS` lookup table for unit names. // case 0x04: - printf("%ld %s\n", weight, UNITS[unit]); + printf("%g %s\n", weight, UNITS[unit]); return 0; case 0x05: if(status != lastStatus)