espressif / idf-extra-components

Additional components for ESP-IDF, maintained by Espressif
133 stars 85 forks source link

HSV计算精度不对 (IEC-129) #345

Open WzxKB opened 1 week ago

WzxKB commented 1 week ago

Answers checklist.

Which component are you using? If you choose Other, provide details in More Information.

bdc_motor

ESP-IDF version.

V5.2.1

Development Kit.

esp32s3

Used Component version.

V2.5.4

More Information.

在使用led_strip_set_pixel_hsv()函数的时候,在esp32中,我发现转换的rgb值不对,查阅代码发现是精度问题。

uint32_t rgb_max = value;
uint32_t rgb_min = rgb_max * (255 - saturation) / 255.0f;

需要改成、

uint32_t rgb_max = value * 255 / 100;  // 调整以确保 value 在正确的范围内
uint32_t rgb_min = rgb_max * (100 - saturation) / 100;  // 适用 0-100 范围的 saturation

不然计算结果在我的单片机上是错误的,灯颜色不对

Kainarx commented 5 days ago

@WzxKB You can rescale S and V from 0-1 to 0-255 before calling this function, so that the calculated values will be right.