Skip to content

Commit

Permalink
Some refactoring of Infrared4Arduino export. Improves on #476.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Feb 3, 2023
1 parent 6935b2a commit 718a267
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 53 deletions.
32 changes: 28 additions & 4 deletions src/main/config/exportformats.d/C_raw_utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xalan/java"
xmlns:cidentifierfactory="http://xml.apache.org/xalan/java/org.harctoolbox.irscrutinizer.exporter.CIdentifierFactory"
version="1.0">

<xsl:variable name="cIdentifierFactory" select="cidentifierfactory:new()"/>

<xsl:template match="girr:remote" mode="using">
<xsl:apply-templates select="//girr:command" mode="using"/>
<xsl:template name="loop">
<xsl:text><![CDATA[
// A pretty silly main loop; just intended as an example.
void loop() {
Serial.print(F("Enter number of signal to send (1 .. ]]></xsl:text>
<xsl:value-of select="count(//girr:command)"/>
<xsl:text>): "));
long commandno = Serial.parseInt();
Serial.println(commandno);
#ifdef NUMBER_OF_SENDS
unsigned int times = NUMBER_OF_SENDS;
#else // ! NUMBER_OF_SENDS
Serial.println(F("Enter number of times to send it: "));
unsigned int times = (unsigned int) Serial.parseInt();
Serial.println(times);
#endif // ! NUMBER_OF_SENDS
switch (commandno) {
</xsl:text>
<xsl:apply-templates select="//girr:remote" mode="using"/>
<xsl:text> default:
Serial.println(F("Invalid number entered, try again"));
break;
}
}
</xsl:text>
</xsl:template>

<xsl:template match="girr:command" mode="definition">
Expand Down Expand Up @@ -103,8 +127,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</xsl:text>
<xsl:text> sendRaw(</xsl:text>
<xsl:apply-templates select="girr:raw[1]" mode="arg"/>
<xsl:value-of select="girr:raw[1]/@frequency"/>
<xsl:text>UL, times);
<xsl:apply-templates select="girr:raw[1]/@frequency"/>
<xsl:text>, times);
break;
</xsl:text>
</xsl:template>
Expand Down
31 changes: 7 additions & 24 deletions src/main/config/exportformats.d/Infrared4Arduino.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static IrSender *irsend = IrSenderPwm::getInstance(true);
//////////////////// Command data ////////////////////////
]]></xsl:text>
<xsl:apply-templates select="//girr:remote//girr:command" mode="definition"/>
<xsl:apply-templates select="//girr:command" mode="definition"/>
<xsl:apply-templates select="//girr:remote[//girr:parameters[translate(@protocol, $uppercase, $lowercase) = 'nec1']]" mode="definitionNec1"/>
<xsl:text>
</xsl:text>
Expand Down Expand Up @@ -141,30 +141,13 @@ void setup() {
Serial.println(F("Running " __FILE__));
Serial.println(F("using Infrared4Arduino version " VERSION));
}
]]></xsl:text>
<xsl:call-template name="loop"/>
</xsl:template>

// A pretty silly main loop; just intended as an example.
void loop() {
Serial.print(F("Enter number of signal to send (1 .. ]]></xsl:text>
<xsl:value-of select="count(//girr:command)"/>
<xsl:text>): "));
int commandno = (int) Serial.parseInt();
Serial.println(commandno);
#ifdef NUMBER_OF_SENDS
unsigned int times = NUMBER_OF_SENDS;
#else // ! NUMBER_OF_SENDS
Serial.print(F("Enter number of times to send it: "));
unsigned int times = (unsigned int) Serial.parseInt();
Serial.println(times);
#endif // ! NUMBER_OF_SENDS
switch (commandno) {
</xsl:text>
<xsl:apply-templates select="//girr:remote" mode="using"/>
<xsl:text> default:
Serial.println(F("Invalid number entered, try again"));
break;
}
}
</xsl:text>
<xsl:template match="@frequency">
<xsl:value-of select="."/>
<xsl:text>UL</xsl:text>
</xsl:template>

<xsl:template match="girr:remote[//girr:parameters[translate(@protocol, $uppercase, $lowercase) = 'nec1']]" mode="includeNec1">
Expand Down
33 changes: 8 additions & 25 deletions src/main/config/exportformats.d/Infrared4Arduino_raw.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ static IrSender *irsend = IrSenderPwm::getInstance(true);
//////////////////// Command data ////////////////////////
]]></xsl:text>
<xsl:apply-templates select="//girr:command" mode="definition"/>
<xsl:apply-templates select="//girr:command" mode="definition"/>

<xsl:text><![CDATA[
<xsl:text><![CDATA[
static void sendRaw
#if HAS_FLASH_READ
(const microseconds_t intro_P[], size_t lengthIntro, const microseconds_t repeat_P[],
Expand Down Expand Up @@ -125,30 +125,13 @@ void setup() {
Serial.println(F("Running " __FILE__));
Serial.println(F("using Infrared4Arduino version " VERSION));
}
]]></xsl:text>
<xsl:call-template name="loop"/>
</xsl:template>

// A pretty silly main loop; just intended as an example.
void loop() {
Serial.print(F("Enter number of signal to send (1 .. ]]></xsl:text>
<xsl:value-of select="count(//girr:command)"/>
<xsl:text>): "));
long commandno = Serial.parseInt();
Serial.println(commandno);
#ifdef NUMBER_OF_SENDS
unsigned int times = NUMBER_OF_SENDS;
#else // ! NUMBER_OF_SENDS
Serial.print(F("Enter number of times to send it: "));
unsigned int times = (unsigned int) Serial.parseInt();
Serial.println(times);
#endif // ! NUMBER_OF_SENDS
switch (commandno) {
</xsl:text>
<xsl:apply-templates select="//girr:remote" mode="using"/>
<xsl:text> default:
Serial.println(F("Invalid number entered, try again"));
break;
}
}
</xsl:text>
<xsl:template match="@frequency">
<xsl:value-of select="."/>
<xsl:text>UL</xsl:text>
</xsl:template>

</xsl:stylesheet>
Expand Down

0 comments on commit 718a267

Please sign in to comment.