Fixed implicit conversion from float to double in lighting output and color.

This commit is contained in:
Steve Karg
2024-08-06 17:22:27 -05:00
parent 19f276b7f2
commit 350bbe3331
5 changed files with 50 additions and 37 deletions
+20 -16
View File
@@ -1384,7 +1384,8 @@ bool Lighting_Output_Default_Ramp_Rate_Set(
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
if ((percent_per_second >= 0.1) && (percent_per_second <= 100.0)) {
if (isgreaterequal(percent_per_second, 0.1f) &&
islessequal(percent_per_second, 100.0f)) {
pObject->Default_Ramp_Rate = percent_per_second;
status = true;
}
@@ -1417,7 +1418,8 @@ static bool Lighting_Output_Default_Ramp_Rate_Write(
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if ((percent_per_second >= 0.1) && (percent_per_second <= 100.0)) {
if (isgreaterequal(percent_per_second, 0.1f) &&
islessequal(percent_per_second, 100.0f)) {
pObject->Default_Ramp_Rate = percent_per_second;
status = true;
} else {
@@ -1470,7 +1472,8 @@ bool Lighting_Output_Default_Step_Increment_Set(
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
if ((step_increment >= 0.1) && (step_increment <= 100.0)) {
if (isgreaterequal(step_increment, 0.1f) &&
islessequal(step_increment, 100.0f)) {
pObject->Default_Step_Increment = step_increment;
status = true;
}
@@ -1503,7 +1506,8 @@ static bool Lighting_Output_Default_Step_Increment_Write(
pObject = Keylist_Data(Object_List, object_instance);
if (pObject) {
(void)priority;
if ((value >= 0.1) && (value <= 100.0)) {
if (isgreaterequal(value, 0.1f) &&
islessequal(value, 100.0f)) {
pObject->Default_Step_Increment = value;
status = true;
} else {
@@ -2515,7 +2519,7 @@ static void Lighting_Output_Step_Off_Handler(uint32_t object_instance)
if (isgreaterequal(target_value, step_value)) {
target_value -= step_value;
} else {
target_value = 0;
target_value = 0.0f;
}
/* clamp target within max */
if (isgreater(target_value, max_value)) {
@@ -2523,7 +2527,7 @@ static void Lighting_Output_Step_Off_Handler(uint32_t object_instance)
}
/* jump target to OFF if below min */
if (isless(target_value, min_value)) {
target_value = 0.0;
target_value = 0.0f;
}
pObject->Present_Value = target_value;
pObject->Tracking_Value = target_value;
@@ -2623,9 +2627,9 @@ uint32_t Lighting_Output_Create(uint32_t object_instance)
}
pObject->Object_Name = NULL;
pObject->Description = NULL;
pObject->Present_Value = 0.0;
pObject->Tracking_Value = 0.0;
pObject->Physical_Value = 0.0;
pObject->Present_Value = 0.0f;
pObject->Tracking_Value = 0.0f;
pObject->Physical_Value = 0.0f;
pObject->Lighting_Command.operation = BACNET_LIGHTS_NONE;
pObject->Lighting_Command.use_target_level = false;
pObject->Lighting_Command.use_ramp_rate = false;
@@ -2639,18 +2643,18 @@ uint32_t Lighting_Output_Create(uint32_t object_instance)
pObject->Egress_Time = 0;
pObject->Default_Fade_Time = 100;
pObject->Default_Ramp_Rate = 100.0;
pObject->Default_Step_Increment = 1.0;
pObject->Default_Step_Increment = 1.0f;
pObject->Transition = BACNET_LIGHTING_TRANSITION_FADE;
pObject->Feedback_Value = 0.0;
for (p = 0; p < BACNET_MAX_PRIORITY; p++) {
pObject->Priority_Array[p] = 0.0;
pObject->Priority_Array[p] = 0.0f;
BIT_CLEAR(pObject->Priority_Active_Bits, p);
}
pObject->Relinquish_Default = 0.0;
pObject->Power = 0.0;
pObject->Instantaneous_Power = 0.0;
pObject->Min_Actual_Value = 0.0;
pObject->Max_Actual_Value = 100.0;
pObject->Relinquish_Default = 0.0f;
pObject->Power = 0.0f;
pObject->Instantaneous_Power = 0.0f;
pObject->Min_Actual_Value = 0.0f;
pObject->Max_Actual_Value = 100.0f;
pObject->Lighting_Command_Default_Priority = 16;
pObject->Color_Override = false;
pObject->Color_Reference.type = OBJECT_COLOR;
+18 -12
View File
@@ -69,12 +69,15 @@ static void color_rgb_to_xy_gamma_correction(uint8_t r,
This gamma correction is also applied to the screen
of your computer or phone, thus we need this to create
the same color on the light as on screen. */
red = (red > 0.04045f) ? pow((red + 0.055f) / (1.0f + 0.055f), 2.4f)
: (red / 12.92f);
green = (green > 0.04045f) ? pow((green + 0.055f) / (1.0f + 0.055f), 2.4f)
: (green / 12.92f);
blue = (blue > 0.04045f) ? pow((blue + 0.055f) / (1.0f + 0.055f), 2.4f)
: (blue / 12.92f);
red = (red > 0.04045f)
? (float)pow(((double)red + 0.055) / (1.0 + 0.055), 2.4)
: (red / 12.92f);
green = (green > 0.04045f)
? (float)pow(((double)green + 0.055) / (1.0 + 0.055), 2.4)
: (green / 12.92f);
blue = (blue > 0.04045f)
? (float)pow(((double)blue + 0.055) / (1.0 + 0.055), 2.4)
: (blue / 12.92f);
}
/* Convert the RGB values to XYZ using the
@@ -189,12 +192,15 @@ static void color_rgb_from_xy_gamma_correction(uint8_t *red,
if (gamma_correction) {
/* Apply reverse gamma correction */
r = r <= 0.0031308f ? 12.92f * r
: (1.0f + 0.055f) * pow(r, (1.0f / 2.4f)) - 0.055f;
g = g <= 0.0031308f ? 12.92f * g
: (1.0f + 0.055f) * pow(g, (1.0f / 2.4f)) - 0.055f;
b = b <= 0.0031308f ? 12.92f * b
: (1.0f + 0.055f) * pow(b, (1.0f / 2.4f)) - 0.055f;
r = r <= 0.0031308f
? 12.92f * r
: (1.0f + 0.055f) * (float)pow((double)r, (1.0 / 2.4)) - 0.055f;
g = g <= 0.0031308f
? 12.92f * g
: (1.0f + 0.055f) * (float)pow((double)g, (1.0 / 2.4)) - 0.055f;
b = b <= 0.0031308f
? 12.92f * b
: (1.0f + 0.055f) * (float)pow((double)b, (1.0 / 2.4)) - 0.055f;
}
/* Convert the RGB values to your color object