4 namespace fujitsu_general {
8 #define SET_NIBBLE(message, nibble, value) \ 9 ((message)[(nibble) / 2] |= ((value) &0b00001111) << (((nibble) % 2) ? 0 : 4)) 10 #define GET_NIBBLE(message, nibble) (((message)[(nibble) / 2] >> (((nibble) % 2) ? 0 : 4)) & 0b00001111) 12 static const char *
const TAG =
"fujitsu_general.climate";
94 ESP_LOGV(TAG,
"Transmit state");
112 uint8_t temperature_clamped =
115 SET_NIBBLE(remote_state, FUJITSU_GENERAL_TEMPERATURE_NIBBLE, temperature_offset);
119 SET_NIBBLE(remote_state, FUJITSU_GENERAL_POWER_ON_NIBBLE, FUJITSU_GENERAL_POWER_ON);
123 switch (this->
mode) {
125 SET_NIBBLE(remote_state, FUJITSU_GENERAL_MODE_NIBBLE, FUJITSU_GENERAL_MODE_COOL);
128 SET_NIBBLE(remote_state, FUJITSU_GENERAL_MODE_NIBBLE, FUJITSU_GENERAL_MODE_HEAT);
131 SET_NIBBLE(remote_state, FUJITSU_GENERAL_MODE_NIBBLE, FUJITSU_GENERAL_MODE_DRY);
134 SET_NIBBLE(remote_state, FUJITSU_GENERAL_MODE_NIBBLE, FUJITSU_GENERAL_MODE_FAN);
138 SET_NIBBLE(remote_state, FUJITSU_GENERAL_MODE_NIBBLE, FUJITSU_GENERAL_MODE_AUTO);
146 SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_HIGH);
149 SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_MEDIUM);
152 SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_LOW);
155 SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_SILENT);
159 SET_NIBBLE(remote_state, FUJITSU_GENERAL_FAN_NIBBLE, FUJITSU_GENERAL_FAN_AUTO);
166 SET_NIBBLE(remote_state, FUJITSU_GENERAL_SWING_NIBBLE, FUJITSU_GENERAL_SWING_VERTICAL);
169 SET_NIBBLE(remote_state, FUJITSU_GENERAL_SWING_NIBBLE, FUJITSU_GENERAL_SWING_HORIZONTAL);
172 SET_NIBBLE(remote_state, FUJITSU_GENERAL_SWING_NIBBLE, FUJITSU_GENERAL_SWING_BOTH);
176 SET_NIBBLE(remote_state, FUJITSU_GENERAL_SWING_NIBBLE, FUJITSU_GENERAL_SWING_NONE);
183 remote_state[FUJITSU_GENERAL_STATE_MESSAGE_LENGTH - 1] = this->
checksum_state_(remote_state);
185 this->
transmit_(remote_state, FUJITSU_GENERAL_STATE_MESSAGE_LENGTH);
191 ESP_LOGV(TAG,
"Transmit off");
203 this->
transmit_(remote_state, FUJITSU_GENERAL_UTIL_MESSAGE_LENGTH);
209 ESP_LOGV(TAG,
"Transmit message length %d", length);
217 data->mark(FUJITSU_GENERAL_HEADER_MARK);
218 data->space(FUJITSU_GENERAL_HEADER_SPACE);
221 for (uint8_t i = 0; i <
length; ++i) {
222 const uint8_t byte = message[i];
223 for (uint8_t mask = 0b00000001; mask > 0; mask <<= 1) {
224 data->mark(FUJITSU_GENERAL_BIT_MARK);
225 bool bit = byte & mask;
226 data->space(bit ? FUJITSU_GENERAL_ONE_SPACE : FUJITSU_GENERAL_ZERO_SPACE);
231 data->mark(FUJITSU_GENERAL_TRL_MARK);
232 data->space(FUJITSU_GENERAL_TRL_SPACE);
239 for (uint8_t i = 7; i < FUJITSU_GENERAL_STATE_MESSAGE_LENGTH - 1; ++i) {
240 checksum += message[i];
248 ESP_LOGV(TAG,
"Received IR message");
251 if (!data.
expect_item(FUJITSU_GENERAL_HEADER_MARK, FUJITSU_GENERAL_HEADER_SPACE)) {
252 ESP_LOGV(TAG,
"Header fail");
261 for (uint8_t bit = 0; bit < 8; ++bit) {
262 if (data.
expect_item(FUJITSU_GENERAL_BIT_MARK, FUJITSU_GENERAL_ONE_SPACE)) {
263 recv_message[byte] |= 1 << bit;
264 }
else if (!data.
expect_item(FUJITSU_GENERAL_BIT_MARK, FUJITSU_GENERAL_ZERO_SPACE)) {
265 ESP_LOGV(TAG,
"Byte %d bit %d fail", byte, bit);
272 uint8_t recv_message_length;
274 switch (recv_message_type) {
276 ESP_LOGV(TAG,
"Received state message");
282 ESP_LOGV(TAG,
"Received util message");
286 ESP_LOGV(TAG,
"Unknown message type %X", recv_message_type);
291 for (uint8_t byte = FUJITSU_GENERAL_COMMON_LENGTH; byte < recv_message_length; ++byte) {
292 for (uint8_t bit = 0; bit < 8; ++bit) {
293 if (data.
expect_item(FUJITSU_GENERAL_BIT_MARK, FUJITSU_GENERAL_ONE_SPACE)) {
294 recv_message[byte] |= 1 << bit;
295 }
else if (!data.
expect_item(FUJITSU_GENERAL_BIT_MARK, FUJITSU_GENERAL_ZERO_SPACE)) {
296 ESP_LOGV(TAG,
"Byte %d bit %d fail", byte, bit);
302 for (uint8_t byte = 0; byte < recv_message_length; ++byte) {
303 ESP_LOGVV(TAG,
"%02X", recv_message[byte]);
306 const uint8_t recv_checksum = recv_message[recv_message_length - 1];
307 uint8_t calculated_checksum;
308 if (recv_message_type == FUJITSU_GENERAL_MESSAGE_TYPE_STATE) {
314 if (recv_checksum != calculated_checksum) {
315 ESP_LOGV(TAG,
"Checksum fail - expected %X - got %X", calculated_checksum, recv_checksum);
319 if (recv_message_type == FUJITSU_GENERAL_MESSAGE_TYPE_STATE) {
320 const uint8_t recv_tempertature = GET_NIBBLE(recv_message, FUJITSU_GENERAL_TEMPERATURE_NIBBLE);
323 ESP_LOGV(TAG,
"Received temperature %d", offset_temperature);
325 const uint8_t recv_mode = GET_NIBBLE(recv_message, FUJITSU_GENERAL_MODE_NIBBLE);
326 ESP_LOGV(TAG,
"Received mode %X", recv_mode);
347 const uint8_t recv_fan_mode = GET_NIBBLE(recv_message, FUJITSU_GENERAL_FAN_NIBBLE);
348 ESP_LOGV(TAG,
"Received fan mode %X", recv_fan_mode);
349 switch (recv_fan_mode) {
368 const uint8_t recv_swing_mode = GET_NIBBLE(recv_message, FUJITSU_GENERAL_SWING_NIBBLE);
369 ESP_LOGV(TAG,
"Received swing mode %X", recv_swing_mode);
370 switch (recv_swing_mode) {
388 else if (recv_message_type == FUJITSU_GENERAL_MESSAGE_TYPE_OFF) {
389 ESP_LOGV(TAG,
"Received off message");
395 ESP_LOGV(TAG,
"Received unsupprted message type %X", recv_message_type);
The fan mode is set to Low.
value_type const & value() const
The fan mode is set to Quiet.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
const uint8_t FUJITSU_GENERAL_MESSAGE_TYPE_BYTE
bool on_receive(remote_base::RemoteReceiveData data) override
Parse incoming message.
The fan mode is set to Both.
const uint8_t FUJITSU_GENERAL_FAN_LOW
void transmit_(uint8_t const *message, uint8_t length)
Transmit message as IR pulses.
float target_temperature
The target temperature of the climate device.
const uint8_t FUJITSU_GENERAL_SWING_HORIZONTAL
void set_carrier_frequency(uint32_t carrier_frequency)
const uint8_t FUJITSU_GENERAL_MODE_DRY
const uint16_t FUJITSU_GENERAL_TRL_MARK
const uint8_t FUJITSU_GENERAL_FAN_NIBBLE
const uint8_t FUJITSU_GENERAL_COMMON_BYTE1
The climate device is set to heat to reach the target temperature.
const uint8_t FUJITSU_GENERAL_MODE_FAN
ClimateMode mode
The active mode of the climate device.
const uint8_t FUJITSU_GENERAL_FAN_HIGH
const uint16_t FUJITSU_GENERAL_HEADER_MARK
uint8_t checksum_util_(uint8_t const *message)
Calculate cecksum for a util message.
const uint8_t FUJITSU_GENERAL_MESSAGE_TYPE_OFF
The climate device is set to dry/humidity mode.
const uint8_t FUJITSU_GENERAL_SWING_BOTH
const uint8_t FUJITSU_GENERAL_COMMON_BYTE0
const uint16_t FUJITSU_GENERAL_ZERO_SPACE
void transmit_state() override
Transmit via IR the state of this climate controller.
const uint8_t FUJITSU_GENERAL_TEMP_MAX
const uint8_t FUJITSU_GENERAL_SWING_NIBBLE
const uint8_t FUJITSU_GENERAL_STATE_FOOTER_BYTE0
void transmit_off_()
Transmit via IR power off command.
const uint8_t FUJITSU_GENERAL_STATE_HEADER_BYTE1
const uint8_t FUJITSU_GENERAL_COMMON_BYTE3
The fan mode is set to Horizontal.
The climate device is set to cool to reach the target temperature.
const uint8_t FUJITSU_GENERAL_COMMON_LENGTH
The fan mode is set to Auto.
uint8_t checksum_state_(uint8_t const *message)
Calculate checksum for a state message.
const uint8_t FUJITSU_GENERAL_COMMON_BYTE4
const uint8_t FUJITSU_GENERAL_FAN_AUTO
const uint16_t FUJITSU_GENERAL_HEADER_SPACE
RemoteTransmitterBase * transmitter_
const uint8_t FUJITSU_GENERAL_FAN_MEDIUM
const uint8_t FUJITSU_GENERAL_MESSAGE_TYPE_ECONOMY
const uint8_t FUJITSU_GENERAL_MODE_AUTO
const uint8_t FUJITSU_GENERAL_MODE_NIBBLE
The climate device is set to heat/cool to reach the target temperature.
const uint16_t FUJITSU_GENERAL_TRL_SPACE
const uint32_t FUJITSU_GENERAL_CARRIER_FREQUENCY
const uint8_t FUJITSU_GENERAL_POWER_OFF
The fan mode is set to Vertical.
const uint8_t FUJITSU_GENERAL_SWING_NONE
const uint8_t FUJITSU_GENERAL_MESSAGE_TYPE_STATE
const uint8_t FUJITSU_GENERAL_MODE_HEAT
const uint8_t FUJITSU_GENERAL_TEMP_MIN
const uint8_t FUJITSU_GENERAL_SWING_VERTICAL
const uint8_t FUJITSU_GENERAL_MODE_COOL
void publish_state()
Publish the state of the climate device, to be called from integrations.
The fan mode is set to High.
RemoteTransmitData * get_data()
The swing mode is set to Off.
The climate device is off.
const uint16_t FUJITSU_GENERAL_BIT_MARK
const uint8_t FUJITSU_GENERAL_POWER_ON
const uint8_t FUJITSU_GENERAL_POWER_ON_NIBBLE
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
const uint8_t FUJITSU_GENERAL_TEMPERATURE_NIBBLE
const uint8_t FUJITSU_GENERAL_MESSAGE_TYPE_NUDGE
const uint8_t FUJITSU_GENERAL_STATE_MESSAGE_LENGTH
const uint16_t FUJITSU_GENERAL_ONE_SPACE
const uint8_t FUJITSU_GENERAL_FAN_SILENT
const uint8_t FUJITSU_GENERAL_UTIL_MESSAGE_LENGTH
Implementation of SPI Controller mode.
const uint8_t FUJITSU_GENERAL_COMMON_BYTE2
The fan mode is set to Medium.
const uint8_t FUJITSU_GENERAL_STATE_HEADER_BYTE0
bool expect_item(uint32_t mark, uint32_t space)
The climate device only has the fan enabled, no heating or cooling is taking place.