ToniA / arduino-heatpumpir

An Arduino library to control split-unit heatpumps over Infrared
GNU General Public License v2.0
389 stars 141 forks source link

Min and Max Temperature coding error #170

Open Nateonas opened 4 months ago

Nateonas commented 4 months ago

Today I set my Mishubishi Heavy Heatpump to cooling at 17C. In stead of cooling it started heating to 30C. What happened!?

I did a code-review on MitsubishiHeavyHeatpumpIR.cpp and found:

uint8_t temperature = 23; ... if ( temperatureCmd > 17 && temperatureCmd < 31) { temperature = (~((temperatureCmd - 17) << 4)) & 0xF0; }

I believe this is incorrect: temperature is binary operated, but ONLY if it meets the conditions >17 and <31. Otherwise it just remains 23 (B00010111 in stead of B01100000)! Later on, when operating byte 9, the (unadjusted) temperature is controlling operatingMode and powerMode: ... MitsubishiHeavyZJTemplate[9] |= operatingMode | powerMode | temperature; ...

This should be corrected, for example:

uint8_t temperature = ( ~ ((23 - 17) << 4)) & 0xF0; // default for 23C = B01100000 ... // temperature must be between 18 and 30 degrees if ( temperatureCmd < 18) { temperatureCmd = 18; } if (temperatureCmd > 30) { temperatureCmd = 30; } temperature = (~((temperatureCmd - 17) << 4)) & 0xF0;

I see this error not only with Mitsubishi heavy and also in other xxx-heatpumpIR sources! I currently don't have a development environment set up, so I log the error here for reference. The workaround is to prevent sending temperature-commands below 18C or over 30C.