summaryrefslogtreecommitdiffstats
path: root/src/hvac-can-helper.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hvac-can-helper.hpp')
-rw-r--r--src/hvac-can-helper.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/hvac-can-helper.hpp b/src/hvac-can-helper.hpp
new file mode 100644
index 0000000..3005d6b
--- /dev/null
+++ b/src/hvac-can-helper.hpp
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: Apache-2.0
+
+#ifndef _HVAC_CAN_HELPER_HPP
+#define _HVAC_CAN_HELPER_HPP
+
+#include <string>
+#include <linux/can.h>
+
+class HvacCanHelper
+{
+public:
+ HvacCanHelper();
+
+ ~HvacCanHelper();
+
+ void set_left_temperature(uint8_t temp);
+
+ void set_right_temperature(uint8_t temp);
+
+ void set_fan_speed(uint8_t temp);
+
+private:
+ uint8_t convert_temp(uint8_t value) {
+ int result = ((0xF0 - 0x10) / 15) * (value - 15) + 0x10;
+ if (result < 0x10)
+ result = 0x10;
+ if (result > 0xF0)
+ result = 0xF0;
+
+ return (uint8_t) result;
+ }
+
+ void read_config();
+
+ void can_open();
+
+ void can_close();
+
+ void can_update();
+
+ std::string m_port;
+ unsigned m_verbose;
+ bool m_config_valid;
+ bool m_active;
+ int m_can_socket;
+ struct sockaddr_can m_can_addr;
+
+ uint8_t m_temp_left;
+ uint8_t m_temp_right;
+ uint8_t m_fan_speed;
+};
+
+#endif // _HVAC_CAN_HELPER_HPP