-
Notifications
You must be signed in to change notification settings - Fork 915
IRremoteESP8266 in a python library #2067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
90a8328
Set things so that one can generate a stand alone library and access …
frawau 6bafe1f
Some clean-up. Generic include for Python.
frawau 480d133
Select few.
frawau dc95bd2
Add generic include.
frawau f0b3ea8
Simplified includes.
frawau 9b60f9c
cpplint shenanigans
frawau 59ac2e8
more cpplint shenanigans
frawau 777abec
Ooops silly me. Forgot to define VIRTUALMS when UNIT_TEST is not define.
frawau 09fd927
Remove duplicated code from SWIG file. Makefile now download and inst…
frawau 75c2ec4
Let's piggyback on Tool_Tests.
frawau 21e2e07
We need to install swig when using docker. So rearrange make file to …
frawau 182b0e5
Try to use swig without installing it.
frawau 526c88d
Add the test file 🙄. Do not delete the swig directory.
frawau 7ad401c
Changed PYTHONLIB to SWIGLIB in ifdef's. This way, it is no longer Py…
frawau c762f93
Fix cpplint build/include_what_you_use for vector in IRsend.cpp
frawau 77bf16b
Fix SWIG typemap for compatibility with SWIG 4.3+
frawau 76964ac
Cosmetic changes at maintainer's request.
frawau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # SYNOPSIS: | ||
| # | ||
| # make [all] - makes everything. | ||
| # make TARGET - makes the given target. | ||
| # make run_tests - makes everything and runs all test | ||
| # make run-% - run specific test file (exclude .py) | ||
| # replace % with given test file | ||
| # make clean - removes all files generated by make. | ||
|
|
||
| # Please tweak the following variable definitions as needed by your | ||
| # project, except GTEST_HEADERS, which you can use in your own targets | ||
| # but shouldn't modify. | ||
|
|
||
| ifeq (,$(wildcard ./.dockerenv)) | ||
| SWIGTYPE = local | ||
| else | ||
| SWIGTYPE = global | ||
| endif | ||
|
|
||
| # Where to find user code. | ||
| SRC_DIR = ../src | ||
|
|
||
| # Where to find test code. | ||
| TEST_DIR = ../test | ||
|
|
||
| INCLUDES = -I$(SRC_DIR) -I$(TEST_DIR) | ||
| DEFFLAGS = -DUNIT_TEST -DSWIGLIB | ||
| # Flags passed to the preprocessor. | ||
| # Set Google Test's header directory as a system directory, such that | ||
| # the compiler doesn't generate warnings in Google Test headers. | ||
| CPPFLAGS += -D_IR_LOCALE_=en-AU -fPIC $(DEFFLAGS) | ||
|
|
||
| # Flags passed to the C++ compiler. | ||
| CXXFLAGS += -g -Wall -Wextra -pthread -std=gnu++11 | ||
|
|
||
| PYTHONINCL = $(shell python3-config --includes) | ||
|
|
||
| objects = $(patsubst %.cpp,%,$(wildcard *.cpp)) | ||
|
|
||
| all : _irhvac.so | ||
|
|
||
| library : $(objects) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,lib_irhvac.so -o _irhvac.so $(COMMON_OBJ) | ||
|
|
||
| swig : libirhvac_wrap.cxx | ||
| ifneq (,$(wildcard /.dockerenv)) | ||
| SWIG_LIB=$(shell realpath -qe swig-4.2.0/Lib) ./swig-4.2.0/swig $(INCLUDES) $(DEFFLAGS) -c++ -python libirhvac.i | ||
| else | ||
| swig $(INCLUDES) $(DEFFLAGS) -c++ -python libirhvac.i | ||
| endif | ||
|
|
||
| clean : | ||
| rm -f *.o *.pyc *.cxx *.cpp | ||
| rm -rf swig-4.2.0 | ||
| distclean : | ||
| rm -f *.o *.pyc libirhvac_wrap.cxx irhvac.py _irhvac.so | ||
| rm -rf swig-4.2.0 | ||
|
|
||
|
|
||
| test : _irhvac.so | ||
| python test_lib.py | ||
|
|
||
| docker : swig-4.2.0/swig _irhvac.so | ||
|
|
||
| testdocker : swig-4.2.0/swig _irhvac.so | ||
| python test_lib.py | ||
|
|
||
| # Keep all intermediate files. | ||
| .SECONDARY: | ||
|
|
||
| # All the IR protocol object files. | ||
| PROTOCOL_OBJS = $(patsubst %.cpp,%.o,$(wildcard $(SRC_DIR)/ir_*.cpp)) | ||
| PROTOCOLS = $(patsubst $(SRC_DIR)/%,%,$(PROTOCOL_OBJS)) | ||
|
|
||
| # Common object files | ||
| COMMON_OBJ = libirhvac_wrap.o IRutils.o IRtimer.o IRsend.o IRrecv.o IRtext.o IRac.o $(PROTOCOLS) | ||
|
|
||
| # Common dependencies | ||
| COMMON_DEPS = $(SRC_DIR)/IRrecv.h $(SRC_DIR)/IRsend.h $(SRC_DIR)/IRtimer.h \ | ||
| $(SRC_DIR)/IRutils.h $(SRC_DIR)/IRremoteESP8266.h \ | ||
| $(SRC_DIR)/IRtext.h $(SRC_DIR)/i18n.h | ||
| # Common test dependencies | ||
| COMMON_TEST_DEPS = $(COMMON_DEPS) $(TEST_DIR)/IRsend_test.h | ||
|
|
||
| IRtext.o : $(SRC_DIR)/IRtext.cpp $(SRC_DIR)/IRtext.h $(SRC_DIR)/IRremoteESP8266.h $(SRC_DIR)/i18n.h $(SRC_DIR)/locale/*.h | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(SRC_DIR)/IRtext.cpp | ||
|
|
||
| IRutils.o : $(SRC_DIR)/IRutils.cpp $(SRC_DIR)/IRutils.h $(SRC_DIR)/IRremoteESP8266.h | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_DIR)/IRutils.cpp | ||
|
|
||
| IRsend.o : $(SRC_DIR)/IRsend.cpp $(SRC_DIR)/IRsend.h $(SRC_DIR)/IRremoteESP8266.h | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_DIR)/IRsend.cpp | ||
|
|
||
| IRrecv.o : $(SRC_DIR)/IRrecv.cpp $(SRC_DIR)/IRrecv.h $(SRC_DIR)/IRremoteESP8266.h $(GTEST_HEADERS) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_DIR)/IRrecv.cpp | ||
|
|
||
| libirhvac_wrap.o : libirhvac_wrap.cxx | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) $(PYTHONINCL) -c libirhvac_wrap.cxx | ||
|
|
||
| libirhvac_wrap.cxx : | ||
| swig $(INCLUDES) $(DEFFLAGS) -c++ -python libirhvac.i | ||
|
|
||
| _irhvac.so : $(COMMON_OBJ) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -shared -Wl,-soname,lib_irhvac.so -o _irhvac.so $(COMMON_OBJ) | ||
|
|
||
| swig-4.2.0/swig : | ||
| curl -s -L -o - http://downloads.sourceforge.net/project/swig/swig/swig-4.2.0/swig-4.2.0.tar.gz | tar xfz - | ||
| ( cd swig-4.2.0; ./configure ; make ) | ||
| # new specific targets goes above this line | ||
|
|
||
| $(objects) : %: $(COMMON_OBJ) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ | ||
|
|
||
| ir_%.o : $(SRC_DIR)/ir_%.h $(SRC_DIR)/ir_%.cpp $(COMMON_DEPS) $(GTEST_HEADERS) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(SRC_DIR)/ir_$*.cpp | ||
|
|
||
| ir_%.o : $(SRC_DIR)/ir_%.cpp $(GTEST_HEADERS) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(SRC_DIR)/ir_$*.cpp | ||
|
|
||
| %.o : %.cpp $(COMMON_DEPS) $(GTEST_HEADERS) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $*.cpp | ||
|
|
||
| %.o : $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h $(COMMON_DEPS) $(GTEST_HEADERS) | ||
| $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $(SRC_DIR)/$*.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| %module (package="pyhvac") irhvac | ||
| #define SWIGPYTHON_BUILTIN | ||
| %include <std_string.i> | ||
| %include "stdint.i" | ||
| %{ | ||
| #include <vector> | ||
| #include "IRac.h" | ||
| #include "IRremoteESP8266.h" | ||
| #include "IRsend.h" | ||
| %} | ||
| %include <std_vector.i> | ||
| %template(VectorOfInt) std::vector<int>; | ||
| %typemap(out) std::vector<int> (PyObject* _outer) %{ | ||
| // Allocate a PyList object of the requested size. | ||
| _outer = PyList_New($1.size()); | ||
| // Populate the PyList. PyLong_FromLong converts a C++ "long" to a | ||
| // Python PyLong object. | ||
| for(size_t x = 0; x < $1.size(); x++) { | ||
| PyList_SetItem(_outer, x, PyLong_FromLong($1[x])); | ||
| } | ||
| $result = _outer; | ||
| %} | ||
| %include <IRsend.h> | ||
| %include <IRremoteESP8266.h> | ||
| %include <IRac.h> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import irhvac | ||
| ac=irhvac.IRac(4) | ||
|
|
||
| ac.next.protocol = irhvac.COOLIX | ||
| ac.next.mode = irhvac.opmode_t_kAuto | ||
| ac.next.degrees = 24 | ||
| ac.sendAc() | ||
| assert ac.getTiming() == [4692, 4416, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 552, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 5244, 4692, 4416, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 552, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 552, 552, 552, 552, 1656, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 1656, 552, 5244, 100000] | ||
| print("Success!") | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.