add separate influxdb test and usb test modes

This commit is contained in:
Rob Pearce (via phone) 2021-11-28 20:06:18 +11:00
parent 4e7ae2bb25
commit 26c3dda8ea
1 changed files with 16 additions and 9 deletions

View File

@ -311,37 +311,44 @@ int main(int argc, char *argv[]) {
char retbuf[BUFLEN]; char retbuf[BUFLEN];
int res; int res;
int i; int i;
enum mode_enum { M_PROBE, M_TEST } mode = M_PROBE; enum mode_enum { M_PROBE, M_TEST, M_TESTDB } mode = M_PROBE;
hid_device *dev = NULL; hid_device *dev = NULL;
// handle args // handle args
for (i=1; i<argc;i++) { for (i=1; i<argc;i++) {
if (!strcmp(argv[i], "-t")) { if (!strcmp(argv[i], "-T")) {
mode = M_TESTDB;
} else if (!strcmp(argv[i], "-t")) {
mode = M_TEST; mode = M_TEST;
} }
} }
influx_init("gridbug.nethack.net", "haven", "", ""); influx_init("gridbug.nethack.net", "haven", "", "");
if (mode == M_TEST) { if (mode == M_TESTDB) {
printf("running ping...\n"); printf("running ping...\n");
influx_ping(retbuf); influx_ping(retbuf);
exit(1);
} }
exit(1);
if (hid_init()) { if (hid_init()) {
perror("hid_init()");
err("Failed to initialise hidapi."); err("Failed to initialise hidapi.");
exit(1); exit(1);
} }
dev = hid_open(MIC_VID, MIC_PID, NULL); dev = hid_open(MIC_VID, MIC_PID, NULL);
if (mode == M_TEST) {
if (dev) {
info("Found Benestar USB sound meter (vendor 0x%04hx, product 0x%04hx).", MIC_VID, MIC_PID);
exit(0);
}
}
if (!dev) { if (!dev) {
err("Benestar USB sound meter not found (vendor 0x%04hx, product 0x%04hx).", MIC_VID, MIC_PID); err("Benestar USB sound meter not found (vendor 0x%04hx, product 0x%04hx).", MIC_VID, MIC_PID);
exit(1); exit(1);
} }
if (mode == M_TEST) {
info("Found Benestar USB sound meter (vendor 0x%04hx, product 0x%04hx).", MIC_VID, MIC_PID);
exit(0);
}
// get current reading // get current reading
res = hid_write(dev, capture_cmd, 9); res = hid_write(dev, capture_cmd, 9);