Sitelet https://github.com/angeldeejay/IRremoteESP8266/commit/d971825d0bcf3dfe2518af130ea5ce3a7492321f
Skip to content

Commit d971825

Browse files
authored
Improve raw_to_pronto_code.py (crankyoldgit#1122)
* Use lower-case hex code output for pronto codes. * Add option to send the raw code via the repeat section of the Pronto code, rather than the initial section. * Add synonym of `-g` for the gap arg. Fixes crankyoldgit#1103
1 parent 0934cb3 commit d971825

3 files changed

Lines changed: 79 additions & 12 deletions

File tree

‎test/ir_Pronto_test.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,15 @@ TEST(TestSendPronto, Issue1103) {
423423
"f38028d50m20066s20435m15069s30665",
424424
irsend.outputStr());
425425
// Which pretty much matches the `rawData` above.
426+
427+
// Ref:
428+
// https://github.com/crankyoldgit/IRremoteESP8266/issues/1103#issuecomment-628946514
429+
uint16_t pronto_test_using_repeat[12] = {
430+
0x0000, 0x006D, 0x0000, 0x0004, 0x02fb, 0x0309, 0x023d, 0x048e, 0x02fb,
431+
0x0309, 0x023d, 0x0474};
432+
irsend.reset();
433+
irsend.sendPronto(pronto_test_using_repeat, 12);
434+
EXPECT_EQ(
435+
"f38028d50m20066s20435m15069s30665m20066s20435m15069s29982",
436+
irsend.outputStr());
426437
}

‎tools/raw_to_pronto_code.py‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from auto_analyse_raw_data import convert_rawdata, add_rawdata_args, get_rawdata
88

99

10-
def parse_and_report(rawdata_str, hertz, end_usecs, verbose, output=sys.stdout):
10+
# pylint: disable=too-many-arguments
11+
def parse_and_report(rawdata_str, hertz=38000, end_usecs=100000,
12+
use_initial=False, generate_code=False, verbose=False,
13+
output=sys.stdout):
1114
"""Analyse the rawdata c++ definition of a IR message."""
1215

1316
# Parse the input.
@@ -29,15 +32,24 @@ def parse_and_report(rawdata_str, hertz, end_usecs, verbose, output=sys.stdout):
2932
if verbose:
3033
output.write("Pronto period is %f uSecs.\n" % period)
3134
# Add the lengths to the code.
32-
result.append("%04X" % int(len(rawdata) / 2)) # Initial burst
33-
result.append("%04X" % 0) # Repeat (not used by this program)
35+
if use_initial:
36+
result.append("%04x" % int(len(rawdata) / 2)) # Initial burst code length
37+
result.append("%04x" % 0) # No Repeat code length
38+
else:
39+
result.append("%04x" % 0) # No Initial burst code length
40+
result.append("%04x" % int(len(rawdata) / 2)) # Repeat code length
3441

3542
# Add the data.
3643
if verbose:
3744
output.write("Raw data: %s " % rawdata)
3845
for i in rawdata:
39-
result.append("%04X" % int(i / period))
40-
output.write("Pronto code = '%s'\n" % " ".join(result))
46+
result.append("%04x" % int(i / period))
47+
if generate_code:
48+
output.write("uint16_t pronto[%d] = {0x%s};\n" % (len(result),
49+
", 0x".join(result)))
50+
else:
51+
output.write("Pronto code = '%s'\n" % " ".join(result))
52+
# pylint: enable=too-many-arguments
4153

4254

4355
def main():
@@ -54,12 +66,25 @@ def main():
5466
dest="hertz",
5567
required=True)
5668
arg_parser.add_argument(
69+
"-c",
70+
"--code",
71+
action='store_true',
72+
help="Output C/C++ code instead of human-readable.",
73+
dest="generate_code")
74+
arg_parser.add_argument(
75+
"-g",
5776
"--gap",
5877
"--endgap",
5978
type=int,
6079
help="Nr. of uSeconds of gap to add to the end of the message.",
6180
dest="usecs",
6281
default=100000)
82+
arg_parser.add_argument(
83+
"-i",
84+
"--initial_burst",
85+
action='store_true',
86+
help="Send using only the 'inital burst' section of the pronto code.",
87+
dest="use_initial")
6388
arg_parser.add_argument(
6489
"-v",
6590
"--verbose",
@@ -70,7 +95,8 @@ def main():
7095
add_rawdata_args(arg_parser)
7196
arg_options = arg_parser.parse_args()
7297
parse_and_report(get_rawdata(arg_options), arg_options.hertz,
73-
arg_options.usecs, arg_options.verbose)
98+
arg_options.usecs, arg_options.use_initial,
99+
arg_options.generate_code, arg_options.verbose)
74100

75101

76102
if __name__ == '__main__':

‎tools/raw_to_pronto_code_test.py‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def test_parse_and_report_at_38000(self):
1414
input_str = """
1515
uint16_t rawData[7] = {
1616
20100, 20472, 15092, 30704, 20102, 20472, 15086};"""
17-
pronto.parse_and_report(input_str, 38000, 100000, False, output)
17+
pronto.parse_and_report(input_str, 38000, 100000, True, False, False,
18+
output)
1819
self.assertEqual(
1920
output.getvalue(),
2021
"Pronto code = "
21-
"'0000 006D 0004 0000 02FB 0309 023D 048E 02FB 0309 023D 0ED8'\n")
22+
"'0000 006D 0004 0000 02fb 0309 023d 048e 02fb 0309 023d 0ed8'\n")
2223

2324
def test_parse_and_report_at_36000(self):
2425
"""Tests for the parse_and_report() function @ 36kHz."""
@@ -27,11 +28,12 @@ def test_parse_and_report_at_36000(self):
2728
input_str = """
2829
uint16_t rawData[7] = {
2930
20100, 20472, 15092, 30704, 20102, 20472, 15086};"""
30-
pronto.parse_and_report(input_str, 36000, 100000, False, output)
31+
pronto.parse_and_report(input_str, 36000, 100000, True, False, False,
32+
output)
3133
self.assertEqual(
3234
output.getvalue(),
3335
"Pronto code = "
34-
"'0000 0073 0004 0000 02D3 02E0 021F 0451 02D3 02E0 021F 0E10'\n")
36+
"'0000 0073 0004 0000 02d3 02e0 021f 0451 02d3 02e0 021f 0e10'\n")
3537

3638
def test_parse_and_report_at_57600(self):
3739
"""Tests for the parse_and_report() function @ 57.6kHz."""
@@ -40,11 +42,39 @@ def test_parse_and_report_at_57600(self):
4042
input_str = """
4143
uint16_t rawData[7] = {
4244
20100, 20472, 15092, 30704, 20102, 20472, 15086};"""
43-
pronto.parse_and_report(input_str, 57600, 100000, False, output)
45+
pronto.parse_and_report(input_str, 57600, 100000, True, False, False,
46+
output)
4447
self.assertEqual(
4548
output.getvalue(),
4649
"Pronto code = "
47-
"'0000 0047 0004 0000 0485 049B 0365 06E8 0485 049B 0364 1680'\n")
50+
"'0000 0047 0004 0000 0485 049b 0365 06e8 0485 049b 0364 1680'\n")
51+
52+
def test_using_repeat(self):
53+
"""Tests for the parse_and_report() function @38kHz using repeat section."""
54+
55+
output = StringIO()
56+
input_str = """
57+
uint16_t rawData[7] = {
58+
20100, 20472, 15092, 30704, 20102, 20472, 15086};"""
59+
pronto.parse_and_report(input_str, 38000, 30000, False, False, False,
60+
output)
61+
self.assertEqual(
62+
output.getvalue(),
63+
"Pronto code = "
64+
"'0000 006D 0000 0004 02fb 0309 023d 048e 02fb 0309 023d 0474'\n")
65+
66+
def test_generate_code_output(self):
67+
"""Tests for the parse_and_report() function geneating code output."""
68+
69+
output = StringIO()
70+
input_str = """
71+
uint16_t rawData[7] = {
72+
20100, 20472, 15092, 30704, 20102, 20472, 15086};"""
73+
pronto.parse_and_report(input_str, 38000, 30000, True, True, False, output)
74+
self.assertEqual(
75+
output.getvalue(),
76+
"uint16_t pronto[12] = {0x0000, 0x006D, 0x0004, 0x0000, 0x02fb, "
77+
"0x0309, 0x023d, 0x048e, 0x02fb, 0x0309, 0x023d, 0x0474};\n")
4878

4979

5080
if __name__ == '__main__':

0 commit comments

Comments
 (0)