Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Commit 4193252

Browse files
author
Thomas Preston
committed
fixed set_blocking (issue #2)
1 parent b6e43ad commit 4193252

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

‎CHANGELOG‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Change Log
22
==========
33

4+
v1.2.1
5+
------
6+
- Fixed `set_blocking` bug (issue #2).
7+
- Added nonblocking tests.
8+
- Added python-dev and python3-dev to README.
9+
410
v1.2.0
511
------
612
- Added version file.

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Building and Installing
5959
If you want to install manually then you may also need to install
6060
cython and some dev libraries:
6161

62-
$ sudo aptitude install liblircclient-dev cython gcc
62+
$ sudo aptitude install python{,3}-dev liblircclient-dev cython gcc
6363

6464
Download, compile and install for Python 3 and 2.
6565

‎lirc/lirc.pyx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def nextcode():
187187
free(code)
188188
raise NextCodeError("There was an error reading the next code.")
189189
if code == NULL:
190-
raise NextCodeError("There was no complete code available.")
190+
# raise NextCodeError("There was no complete code available.")
191+
return list()
191192

192193
# get all of the strings associated with this code
193194
strings = list()
@@ -206,12 +207,8 @@ def set_blocking(blocking, lirc_socket):
206207
"""Sets whether the nextcode function blocks"""
207208
fcntl.fcntl(lirc_socket, fcntl.F_SETOWN, unistd.getpid())
208209
flags = fcntl.fcntl(lirc_socket, fcntl.F_GETFL, 0)
209-
if(flags == 0):
210-
fcntl.fcntl(
211-
lirc_socket,
212-
fcntl.F_SETFL,
213-
(flags & ~fcntl.O_NONBLOCK) | (0 if blocking else fcntl.O_NONBLOCK)
214-
)
210+
flags = (flags & ~fcntl.O_NONBLOCK) | (0 if blocking else fcntl.O_NONBLOCK)
211+
fcntl.fcntl(lirc_socket, fcntl.F_SETFL, flags)
215212

216213

217214
def _is_init_or_error():

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name='python-lirc',
15-
version='1.2.0',
15+
version='1.2.1',
1616
description='Python bindings for LIRC.',
1717
author='Thomas Preston',
1818
author_email='thomasmarkpreston@gmail.com',

‎tests/tests.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import os
2+
import sys
3+
import time
14
import unittest
5+
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
6+
sys.path.insert(0, parentdir + "/build/lib.linux-armv6l-3.2/")
27
import lirc
3-
import time
48

59

610
class TestNextCode(unittest.TestCase):
@@ -22,11 +26,20 @@ def setUp(self):
2226
lirc.init("lirctest", "tests/lircrc.test", blocking=False)
2327

2428
def test_nonblocking_nextcode(self):
29+
print("Don't press anything yet...")
30+
start_time = time.time()
31+
end_time = start_time + 1 # 1 second in the future
32+
pressed = False
33+
while not pressed and time.time() < end_time:
34+
if lirc.nextcode() == ["horses"]:
35+
pressed = True
36+
self.assertFalse(pressed)
37+
2538
print("Press 1 on your remote.")
2639
start_time = time.time()
2740
end_time = start_time + 5 # 5 seconds in the future
2841
pressed = False
29-
while not pressed or time.time() < end_time:
42+
while not pressed and time.time() < end_time:
3043
if lirc.nextcode() == ["horses"]:
3144
pressed = True
3245
self.assertTrue(pressed)

0 commit comments

Comments
 (0)