Skip to content

Commit 9a8f5c2

Browse files
committed
Fix read_stupid.php to match usbscale.c
1 parent d271eae commit 9a8f5c2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

example/read_stupid.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
file_put_contents("$dataHex.bin", $binary);
4040
}
4141

42+
$unitAbbr = ['unknown', 'mg', 'g', 'kg', 'cd', 'taels', 'gr', 'dwt', 'tonnes', 'tons', 'ozt', 'oz', 'lbs'];
43+
4244
$data = (object) unpack('Creport/Cstatus/Cunit/cexponent/vweight', $binary);
4345

4446
if ($data->report === 0x03 && $data->status === 0x04) {
@@ -50,9 +52,5 @@
5052
$data->unit = 0x02;
5153
}
5254

53-
if ($data->unit === 0x02) {
54-
fprintf(STDOUT, "%.2f g\n", $data->weight);
55-
} else {
56-
fprintf(STDOUT, "%.2f in other unit\n", $data->weight);
57-
}
55+
fprintf(STDOUT, "%.2f %s\n", $data->weight, $unitAbbr[$data->unit]);
5856
}

0 commit comments

Comments
 (0)