Skip to content

Commit

Permalink
Fixed non MSYS2/gcc builds by including proper header & using wrapper…
Browse files Browse the repository at this point in the history
… function macro for sleep function. Lowered sleep duration during waiting for an ACK report from device. This makes software to finish a bit faster.
  • Loading branch information
N-Storm committed May 20, 2024
1 parent 351c0bb commit 6f5e95e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions software/src/digilivolo.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#ifdef _WIN32
#include <windows.h>
#define dl_sleep_ms(ms) Sleep(ms)
#else
#include <unistd.h>
#define dl_sleep_ms(ms) usleep(ms * 1000)
#endif

#include "defs.h"
#include "args.h"
Expand Down Expand Up @@ -154,20 +161,24 @@ int main(int argc, char* argv[])
res = 0;

while (res == 0) {
sleep(1);
dl_sleep_ms(300);
res = dlusb_read(&packet, handle);
if (res == -1) { // one more try
printf("WARN: (%d) Unable to get a feature report: %ls\n", res, hid_error(handle));
sleep(1);
if (res == -1) { // This error usually means that the hardware didn't finished processing yet, give it one more try after delay
if (arguments.verbose) {
printf("WARN: (%d) Unable to get ACK feature report: %ls.\n", res, hid_error(handle));
dl_sleep_ms(10);
printf(" Retrying...\n");
}
dl_sleep_ms(300);
res = dlusb_read(&packet, handle);
}
if (res < 0) {
printf("WARN: (%d) Unable to get a feature report: %ls\n", res, hid_error(handle));
printf("WARN: (%d) Unable to get ACK feature report: %ls\n", res, hid_error(handle));
continue;
}
else if (res > 0) {
if (packet.cmd_id == ((arguments.old_alg == true) ? CMD_SWITCH_OLD : CMD_SWITCH) && \
packet.remote_id == arguments.remote_id && packet.btn_id == arguments.btn_id) {
packet.remote_id == arguments.remote_id && packet.btn_id == arguments.btn_id) {
printf("Device acks codes correctly.\n");
}
else {
Expand Down

0 comments on commit 6f5e95e

Please sign in to comment.