mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Remove floating point calculation from ac_dimmer ISR (#3770)
This commit is contained in:
		| @@ -121,11 +121,8 @@ void IRAM_ATTR HOT AcDimmerDataStore::gpio_intr() { | |||||||
|       // calculate time until enable in µs: (1.0-value)*cycle_time, but with integer arithmetic |       // calculate time until enable in µs: (1.0-value)*cycle_time, but with integer arithmetic | ||||||
|       // also take into account min_power |       // also take into account min_power | ||||||
|       auto min_us = this->cycle_time_us * this->min_power / 1000; |       auto min_us = this->cycle_time_us * this->min_power / 1000; | ||||||
|       // calculate required value to provide a true RMS voltage output |       this->enable_time_us = std::max((uint32_t) 1, ((65535 - this->value) * (this->cycle_time_us - min_us)) / 65535); | ||||||
|       this->enable_time_us = |  | ||||||
|           std::max((uint32_t) 1, (uint32_t)((65535 - (acos(1 - (2 * this->value / 65535.0)) / 3.14159 * 65535)) * |  | ||||||
|                                             (this->cycle_time_us - min_us)) / |  | ||||||
|                                      65535); |  | ||||||
|       if (this->method == DIM_METHOD_LEADING_PULSE) { |       if (this->method == DIM_METHOD_LEADING_PULSE) { | ||||||
|         // Minimum pulse time should be enough for the triac to trigger when it is close to the ZC zone |         // Minimum pulse time should be enough for the triac to trigger when it is close to the ZC zone | ||||||
|         // this is for brightness near 99% |         // this is for brightness near 99% | ||||||
| @@ -206,6 +203,7 @@ void AcDimmer::setup() { | |||||||
| #endif | #endif | ||||||
| } | } | ||||||
| void AcDimmer::write_state(float state) { | void AcDimmer::write_state(float state) { | ||||||
|  |   state = std::acos(1 - (2 * state)) / 3.14159;  // RMS power compensation | ||||||
|   auto new_value = static_cast<uint16_t>(roundf(state * 65535)); |   auto new_value = static_cast<uint16_t>(roundf(state * 65535)); | ||||||
|   if (new_value != 0 && this->store_.value == 0) |   if (new_value != 0 && this->store_.value == 0) | ||||||
|     this->store_.init_cycle = this->init_with_half_cycle_; |     this->store_.init_cycle = this->init_with_half_cycle_; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user