From 2731d9b48762b15892690b6bdf41ae6509e7fc11 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Mon, 21 Jan 2019 23:31:53 +0100 Subject: [PATCH] add knx.Stop() method --- knxPython/knxmodule.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/knxPython/knxmodule.cpp b/knxPython/knxmodule.cpp index a3de115..f9559fc 100644 --- a/knxPython/knxmodule.cpp +++ b/knxPython/knxmodule.cpp @@ -19,9 +19,11 @@ namespace py = pybind11; LinuxPlatform platform; Bau57B0 bau(platform); +bool running = false; + static void loop() { - while (1) + while (running) { bau.loop(); platform.mdelay(100); @@ -30,13 +32,13 @@ static void loop() static std::thread workerThread; -bool started = false; + static void Start() { - if (started) + if (running) return; - started = true; + running = true; bau.readMemory(); bau.enabled(true); @@ -45,6 +47,18 @@ static void Start() workerThread.detach(); } +static void Stop() +{ + if (!running) + return; + + running = false; + bau.writeMemory(); + bau.enabled(false); + + workerThread.join(); +} + static bool ProgramMode(bool value) { bau.deviceObject().progMode(value); @@ -76,6 +90,7 @@ PYBIND11_MODULE(knx, m) py::bind_vector>(m, "GroupObjectList"); m.def("Start", &Start, "Start knx handling thread."); + m.def("Stop", &Start, "Stop knx handling thread."); m.def("ProgramMode", (bool(*)())&ProgramMode, "get programing mode active."); m.def("ProgramMode", (bool(*)(bool))&ProgramMode, "Activate / deactivate programing mode."); m.def("Configured", (bool(*)())&Configured, "get configured status.");