summaryrefslogtreecommitdiffstats
path: root/src/hvac-can-helper.hpp
blob: 3005d6bf9ef4800a338b2fba798f2ec13053a61f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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