Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/UnitTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
run: (cd tools; make all)
- name: Run tools unit tests
run: (cd tools; make run_tests)
- name: Build swig extension and run simple test
run: (cd python; make testdocker)

Unit_Tests:
runs-on: ubuntu-latest
Expand Down
124 changes: 124 additions & 0 deletions python/Makefile
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
26 changes: 26 additions & 0 deletions python/libirhvac.i
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>

212 changes: 212 additions & 0 deletions python/test_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
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!")
Loading
Loading