Compare commits

..

No commits in common. "9ed1cb55a2dfd0daeb41548031a49ab756cb9114" and "97e48ded31e0c640c9d9a7038050259ae1f8cb20" have entirely different histories.

3 changed files with 6 additions and 39 deletions

View File

@ -1,17 +0,0 @@
name: Build
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential libusb-1.0-0-dev
- name: Build
run: make

View File

@ -24,9 +24,6 @@ error messages will be sent to `stderr`. An exit code of 0 means that a scale
was found and a weight was successfully read. Any other error code indicates
that a weight reading was unavailable.
Use the `-h`/`--human` flag to format ounce measurements as pounds and
ounces, e.g. `1 lbs 4 oz` instead of `20 oz`.
## Zeroing the scale
There is somewhat-experimental support for sending a tare command to the scale.

View File

@ -73,7 +73,7 @@ static libusb_device* find_nth_scale(libusb_device**, int);
// it, printing out the result to the screen. It also returns a 1 if the
// program should read again (i.e. continue looping).
//
static int print_scale_data(unsigned char*, bool);
static int print_scale_data(unsigned char*);
//
// take device and fetch bEndpointAddress for the first endpoint
@ -107,14 +107,13 @@ const char* UNITS[13] = {
};
// Setup argument parsing
const char *argp_program_version = "usbscale 0.3";
const char *argp_program_version = "usbscale 0.2";
const char *argp_program_bug_address = "<https://www.github.com/erjiang/usbscale/issues>";
static char doc[] = "Read weight from a USB scale\n"
"The `zero' command will request the scale to reset to zero (not supported by all scales).\n";
static char args_doc[] = "[zero]";
static struct argp_option options[] = {
{ "index", 'i', "INDEX", 0, "Index of scale to read (default: 1)" },
{ "human", 'h', 0, 0, "Print weight in lbs and oz when units are oz" },
{ 0 }
};
@ -122,7 +121,6 @@ static struct argp_option options[] = {
struct arguments {
int index;
bool tare;
bool human;
};
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
@ -135,9 +133,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
argp_usage(state);
}
break;
case 'h':
arguments->human = true;
break;
case ARGP_KEY_ARG:
if (strcmp(arg, "zero") == 0) {
arguments->tare = true;
@ -167,7 +162,6 @@ int main(int argc, char **argv)
// By default, get the first scale's weight
arguments.index = 1;
arguments.tare = false;
arguments.human = false;
argp_parse(&argp, argc, argv, 0, 0, &arguments);
libusb_device **devs;
@ -320,7 +314,7 @@ int main(int argc, char **argv)
}
#endif
if (weigh_count < 1) {
scale_result = print_scale_data(data, arguments.human);
scale_result = print_scale_data(data);
if(scale_result != 1)
break;
}
@ -357,15 +351,14 @@ int main(int argc, char **argv)
// ----------------
//
// **print_scale_data** takes the 6 bytes of binary data sent by the scale and
// interprets and prints it out. If `human` is true and the units are ounces,
// it will output the weight as pounds and ounces.
// interprets and prints it out.
//
// **Returns:** `0` if weight data was successfully read, `1` if the data
// indicates that more data needs to be read (i.e. keep looping), and `-1` if
// the scale data indicates that some error occurred and that the program
// should terminate.
//
static int print_scale_data(unsigned char* dat, bool human) {
static int print_scale_data(unsigned char* dat) {
//
// We keep around `lastStatus` so that we're not constantly printing the
@ -421,13 +414,7 @@ static int print_scale_data(unsigned char* dat, bool human) {
// the `UNITS` lookup table for unit names.
//
case 0x04:
if (human && unit == 11) {
int lbs = (int)floor(weight / 16.0);
double oz = weight - (lbs * 16.0);
printf("%d lbs %g oz\n", lbs, oz);
} else {
printf("%g %s\n", weight, UNITS[unit]);
}
printf("%g %s\n", weight, UNITS[unit]);
return 0;
case 0x05:
if(status != lastStatus)