1 #pragma once 2 3 4 #include <set> 5 #include "DomoticzHardware.h" 6 #include "../hardware/1Wire/1WireCommon.h" 7 8 class I_1WireSystem; 9 class C1Wire : public CDomoticzHardwareBase 10 { 11 public: 12 explicit C1Wire(const int ID, const int sensorThreadPeriod, const int switchThreadPeriod, const std::string& path); 13 virtual ~C1Wire(); 14 bool WriteToHardware(const char *pdata, const unsigned char length) override; 15 private: 16 void DetectSystem(); 17 bool StartHardware() override; 18 bool StopHardware() override; 19 void SensorThread(); 20 void SwitchThread(); 21 void BuildSensorList(); 22 void BuildSwitchList(); 23 void PollSwitches(); 24 25 // Messages to Domoticz 26 void ReportLightState(const std::string& deviceId, const uint8_t unit, const bool state); 27 void ReportWiper(const std::string& deviceId, const int wiper); 28 void ReportTemperature(const std::string& deviceId, const float temperature); 29 void ReportTemperatureHumidity(const std::string& deviceId, const float temperature, const float humidity); 30 void ReportHumidity(const std::string& deviceId, const float humidity); 31 void ReportPressure(const std::string& deviceId, const float pressure); 32 void ReportCounter(const std::string& deviceId, const int unit, const unsigned long counter); 33 void ReportVoltage(const std::string& deviceId, const int unit, const int voltage); 34 void ReportIlluminance(const std::string& deviceId, const float illuminescence); 35 private: 36 std::shared_ptr<std::thread> m_threadSensors; 37 std::shared_ptr<std::thread> m_threadSwitches; 38 StoppableTask m_TaskSwitches; 39 I_1WireSystem* m_system; 40 std::map<std::string, bool> m_LastSwitchState; 41 std::set<_t1WireDevice> m_sensors; 42 std::set<_t1WireDevice> m_switches; 43 44 int m_sensorThreadPeriod; // milliseconds 45 int m_switchThreadPeriod; // milliseconds 46 const std::string &m_path; 47 bool m_bSensorFirstTime; 48 bool m_bSwitchFirstTime; 49 }; 50