Skip to content

Instantly share code, notes, and snippets.

@Irdroid
Last active January 19, 2022 13:07
Show Gist options
  • Save Irdroid/df859ae9b7cddd8fccde879804e056da to your computer and use it in GitHub Desktop.
Save Irdroid/df859ae9b7cddd8fccde879804e056da to your computer and use it in GitHub Desktop.
--- ./lirc/plugins/irtoy.c 2022-01-17 13:15:07.827454566 +0200
+++ ./lirc/plugins/irtoy.c 2022-01-17 13:21:01.854548820 +0200
@@ -50,7 +50,14 @@
{0, 0}
};
-const unsigned char IRTOY_COMMAND_TXSTART[] = { 0x24, 0x25, 0x26, 0x03 };
+const unsigned char IRTOY_COMMAND_TXSTART[] = { 0x03 };
+// It is important to send the three commands below only on initialization as if sent in the IRTOY_COMMAND_TXSTART it may render the device in a de-enumerated state
+// For more information see gist https://gist.github.com/Irdroid/384d5144d24cba7c94e58dde75388968
+const unsigned char IRTOY_COMMAND24[] = { 0x24 };
+const unsigned char IRTOY_COMMAND25[] = { 0x25 };
+const unsigned char IRTOY_COMMAND26[] = { 0x26 };
+
+
static const unsigned char cmdIOwrite = 0x30; // Sets the IO pins to ground (0) or +5volt (1).
static const unsigned char cmdIOdirection = 0x31; // Sets the IO pins to input (1) or output (0).
#define IRTOY_COMMAND_RESET 0
@@ -379,7 +386,8 @@
log_error("irtoy_enter_samplemode: couldn't write command");
return 0;
}
-
+ //delay needed before reading the command result from Irtoy / Irdroid
+ usleep(100);
res = read_with_timeout(dev->fd, buf,
IRTOY_LEN_SAMPLEMODEPROTO,
IRTOY_TIMEOUT_SMODE_ENTER);
@@ -387,6 +395,36 @@
log_error("irtoy_enter_samplemode: Can't read command result");
return 0;
}
+ // Send initialization commands once on init, separately from the transmit commands to avoid de-enumerating the device
+ // See gist https://gist.github.com/Irdroid/384d5144d24cba7c94e58dde75388968
+ res = write(dev->fd, IRTOY_COMMAND24, sizeof(IRTOY_COMMAND24));
+
+ if (res != sizeof(IRTOY_COMMAND24)) {
+ log_error("irtoy_send: couldn't write command 24");
+ return 0;
+ }
+ //delay needed before reading the command result from Irtoy / Irdroid
+ usleep(20);
+ // Send initialization commands once on init, separately from the transmit commands to avoid de-enumerating the device
+ // See gist https://gist.github.com/Irdroid/384d5144d24cba7c94e58dde75388968
+ res = write(dev->fd, IRTOY_COMMAND25, sizeof(IRTOY_COMMAND25));
+
+ if (res != sizeof(IRTOY_COMMAND25)) {
+ log_error("irtoy_send: couldn't write command 25");
+ return 0;
+ }
+ //delay needed before reading the command result from Irtoy / Irdroid
+ usleep(20);
+ // Send initialization commands once on init, separately from the transmit commands to avoid de-enumerating the device
+ // See gist https://gist.github.com/Irdroid/384d5144d24cba7c94e58dde75388968
+ res = write(dev->fd, IRTOY_COMMAND26, sizeof(IRTOY_COMMAND26));
+
+ if (res != sizeof(IRTOY_COMMAND26)) {
+ log_error("irtoy_send: couldn't write command 26");
+ return 0;
+ }
+ //delay needed before reading the command result from Irtoy / Irdroid
+ usleep(20);
buf[IRTOY_LEN_SAMPLEMODEPROTO] = 0;
if (buf[0] != IRTOY_REPLY_SAMPLEMODEPROTO) {
@@ -415,7 +453,7 @@
dev->awaitingNewSig = 1;
dev->fd = fd;
dev->pulse = 1;
-
+
irtoy_readflush(dev, IRTOY_TIMEOUT_FLUSH);
if (!irtoy_reset(dev) || !irtoy_getversion(dev) ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment