mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Added options to control pulse duration on Climate_IR_LG Component (#1470)
* Added options to control pulse duration on Climate_IR_LG Component. This is usefull as some equipment from LG (Tested in Brazil AC unit) use different pulse durations in their protocol. * Fixed C++ linting issues * Fixed Python linting issues * fixed spaces on parameters linting issue * fixed spacing clint * Removed unused constants * Removed wrong spacing * Changed int to time period in all new fields Changed cv._int to cv.positive_time_period_microseconds in the time definitions for the new options * Fixed the time defaults Time defaults fixed for Climate_IR_LG.
This commit is contained in:
		| @@ -8,11 +8,28 @@ AUTO_LOAD = ['climate_ir'] | ||||
| climate_ir_lg_ns = cg.esphome_ns.namespace('climate_ir_lg') | ||||
| LgIrClimate = climate_ir_lg_ns.class_('LgIrClimate', climate_ir.ClimateIR) | ||||
|  | ||||
| CONF_HEADER_HIGH = 'header_high' | ||||
| CONF_HEADER_LOW = 'header_low' | ||||
| CONF_BIT_HIGH = 'bit_high' | ||||
| CONF_BIT_ONE_LOW = 'bit_one_low' | ||||
| CONF_BIT_ZERO_LOW = 'bit_zero_low' | ||||
|  | ||||
| CONFIG_SCHEMA = climate_ir.CLIMATE_IR_WITH_RECEIVER_SCHEMA.extend({ | ||||
|     cv.GenerateID(): cv.declare_id(LgIrClimate), | ||||
|     cv.Optional(CONF_HEADER_HIGH, default='8000us'): cv.positive_time_period_microseconds, | ||||
|     cv.Optional(CONF_HEADER_LOW, default='4000us'): cv.positive_time_period_microseconds, | ||||
|     cv.Optional(CONF_BIT_HIGH, default='600us'): cv.positive_time_period_microseconds, | ||||
|     cv.Optional(CONF_BIT_ONE_LOW, default='1600us'): cv.positive_time_period_microseconds, | ||||
|     cv.Optional(CONF_BIT_ZERO_LOW, default='550us'): cv.positive_time_period_microseconds, | ||||
| }) | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     var = cg.new_Pvariable(config[CONF_ID]) | ||||
|     yield climate_ir.register_climate_ir(var, config) | ||||
|  | ||||
|     cg.add(var.set_header_high(config[CONF_HEADER_HIGH])) | ||||
|     cg.add(var.set_header_low(config[CONF_HEADER_LOW])) | ||||
|     cg.add(var.set_bit_high(config[CONF_BIT_HIGH])) | ||||
|     cg.add(var.set_bit_one_low(config[CONF_BIT_ONE_LOW])) | ||||
|     cg.add(var.set_bit_zero_low(config[CONF_BIT_ZERO_LOW])) | ||||
|   | ||||
| @@ -28,13 +28,6 @@ const uint8_t TEMP_RANGE = TEMP_MAX - TEMP_MIN + 1; | ||||
| const uint32_t TEMP_MASK = 0XF00; | ||||
| const uint32_t TEMP_SHIFT = 8; | ||||
|  | ||||
| // Constants | ||||
| static const uint32_t HEADER_HIGH_US = 8000; | ||||
| static const uint32_t HEADER_LOW_US = 4000; | ||||
| static const uint32_t BIT_HIGH_US = 600; | ||||
| static const uint32_t BIT_ONE_LOW_US = 1600; | ||||
| static const uint32_t BIT_ZERO_LOW_US = 550; | ||||
|  | ||||
| const uint16_t BITS = 28; | ||||
|  | ||||
| void LgIrClimate::transmit_state() { | ||||
| @@ -108,13 +101,13 @@ bool LgIrClimate::on_receive(remote_base::RemoteReceiveData data) { | ||||
|   uint8_t nbits = 0; | ||||
|   uint32_t remote_state = 0; | ||||
|  | ||||
|   if (!data.expect_item(HEADER_HIGH_US, HEADER_LOW_US)) | ||||
|   if (!data.expect_item(this->header_high_, this->header_low_)) | ||||
|     return false; | ||||
|  | ||||
|   for (nbits = 0; nbits < 32; nbits++) { | ||||
|     if (data.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) { | ||||
|     if (data.expect_item(this->bit_high_, this->bit_one_low_)) { | ||||
|       remote_state = (remote_state << 1) | 1; | ||||
|     } else if (data.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) { | ||||
|     } else if (data.expect_item(this->bit_high_, this->bit_zero_low_)) { | ||||
|       remote_state = (remote_state << 1) | 0; | ||||
|     } else if (nbits == BITS) { | ||||
|       break; | ||||
| @@ -179,15 +172,16 @@ void LgIrClimate::transmit_(uint32_t value) { | ||||
|   data->set_carrier_frequency(38000); | ||||
|   data->reserve(2 + BITS * 2u); | ||||
|  | ||||
|   data->item(HEADER_HIGH_US, HEADER_LOW_US); | ||||
|   data->item(this->header_high_, this->header_low_); | ||||
|  | ||||
|   for (uint32_t mask = 1UL << (BITS - 1); mask != 0; mask >>= 1) { | ||||
|     if (value & mask) | ||||
|       data->item(BIT_HIGH_US, BIT_ONE_LOW_US); | ||||
|     else | ||||
|       data->item(BIT_HIGH_US, BIT_ZERO_LOW_US); | ||||
|     if (value & mask) { | ||||
|       data->item(this->bit_high_, this->bit_one_low_); | ||||
|     } else { | ||||
|       data->item(this->bit_high_, this->bit_zero_low_); | ||||
|     } | ||||
|   data->mark(BIT_HIGH_US); | ||||
|   } | ||||
|   data->mark(this->bit_high_); | ||||
|   transmit.perform(); | ||||
| } | ||||
| void LgIrClimate::calc_checksum_(uint32_t &value) { | ||||
|   | ||||
| @@ -25,6 +25,11 @@ class LgIrClimate : public climate_ir::ClimateIR { | ||||
|       this->swing_mode = climate::CLIMATE_SWING_OFF; | ||||
|     climate_ir::ClimateIR::control(call); | ||||
|   } | ||||
|   void set_header_high(uint32_t header_high) { this->header_high_ = header_high; } | ||||
|   void set_header_low(uint32_t header_low) { this->header_low_ = header_low; } | ||||
|   void set_bit_high(uint32_t bit_high) { this->bit_high_ = bit_high; } | ||||
|   void set_bit_one_low(uint32_t bit_one_low) { this->bit_one_low_ = bit_one_low; } | ||||
|   void set_bit_zero_low(uint32_t bit_zero_low) { this->bit_zero_low_ = bit_zero_low; } | ||||
|  | ||||
|  protected: | ||||
|   /// Transmit via IR the state of this climate controller. | ||||
| @@ -37,6 +42,12 @@ class LgIrClimate : public climate_ir::ClimateIR { | ||||
|   void calc_checksum_(uint32_t &value); | ||||
|   void transmit_(uint32_t value); | ||||
|  | ||||
|   uint32_t header_high_; | ||||
|   uint32_t header_low_; | ||||
|   uint32_t bit_high_; | ||||
|   uint32_t bit_one_low_; | ||||
|   uint32_t bit_zero_low_; | ||||
|  | ||||
|   climate::ClimateMode mode_before_{climate::CLIMATE_MODE_OFF}; | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user