Fixed Lighting Output object lighting command decoding and ramp operations

This commit is contained in:
Steve Karg
2024-08-07 11:07:23 -05:00
parent 350bbe3331
commit 18d4b47b2c
2 changed files with 98 additions and 26 deletions
+81 -10
View File
@@ -22,6 +22,8 @@
#include "bacnet/basic/services.h" #include "bacnet/basic/services.h"
#include "bacnet/basic/sys/keylist.h" #include "bacnet/basic/sys/keylist.h"
#include "bacnet/basic/sys/linear.h" #include "bacnet/basic/sys/linear.h"
#include "bacnet/basic/sys/debug.h"
#include "bacnet/bactext.h"
#include "bacnet/proplist.h" #include "bacnet/proplist.h"
/* me! */ /* me! */
#include "bacnet/basic/object/lo.h" #include "bacnet/basic/object/lo.h"
@@ -984,16 +986,27 @@ static bool Lighting_Output_Lighting_Command_Write(
} }
pObject = Keylist_Data(Object_List, object_instance); pObject = Keylist_Data(Object_List, object_instance);
if (pObject) { if (pObject) {
debug_printf("LO[%u]: Lighting-Command@%u: %s\n",
object_instance, priority,
bactext_lighting_operation_name(value->operation));
switch (value->operation) { switch (value->operation) {
case BACNET_LIGHTS_NONE: case BACNET_LIGHTS_NONE:
status = true; status = true;
break; break;
case BACNET_LIGHTS_FADE_TO: case BACNET_LIGHTS_FADE_TO:
debug_printf("LO[%u]: Lighting-Command@%u Fade-To "
"Target=%f Fade=%u\n",
object_instance, priority,
value->target_level, value->fade_time);
Lighting_Command_Fade_To(pObject, priority, Lighting_Command_Fade_To(pObject, priority,
value->target_level, value->fade_time); value->target_level, value->fade_time);
status = true; status = true;
break; break;
case BACNET_LIGHTS_RAMP_TO: case BACNET_LIGHTS_RAMP_TO:
debug_printf("LO[%u]: Lighting-Command@%u Ramp-To "
"Target=%f Ramp-Rate=%f\n",
object_instance, priority,
value->target_level, value->ramp_rate);
Lighting_Command_Ramp_To(pObject, priority, Lighting_Command_Ramp_To(pObject, priority,
value->target_level, value->ramp_rate); value->target_level, value->ramp_rate);
status = true; status = true;
@@ -1002,6 +1015,10 @@ static bool Lighting_Output_Lighting_Command_Write(
case BACNET_LIGHTS_STEP_DOWN: case BACNET_LIGHTS_STEP_DOWN:
case BACNET_LIGHTS_STEP_ON: case BACNET_LIGHTS_STEP_ON:
case BACNET_LIGHTS_STEP_OFF: case BACNET_LIGHTS_STEP_OFF:
debug_printf("LO[%u]: Lighting-Command@%u Step "
"Step-Increment=%f\n",
object_instance, priority,
value->step_increment);
Lighting_Command_Step(pObject,priority, Lighting_Command_Step(pObject,priority,
value->operation,value->step_increment); value->operation,value->step_increment);
status = true; status = true;
@@ -2285,6 +2302,12 @@ Lighting_Output_Fade_Handler(uint32_t object_instance, uint16_t milliseconds)
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Fade Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
@@ -2342,28 +2365,52 @@ Lighting_Output_Ramp_Handler(uint32_t object_instance, uint16_t milliseconds)
} else { } else {
if (isless(old_value, target_value)) { if (isless(old_value, target_value)) {
step_value = old_value + steps; step_value = old_value + steps;
if (isgreater(step_value, target_value)) {
/* stop ramping */
pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP;
}
} else if (isgreater(old_value, target_value)) { } else if (isgreater(old_value, target_value)) {
if (isgreater(steps, old_value)) { debug_printf("LO[%u] Ramp Handler Down steps=%f tracking=%f\n",
object_instance, steps, old_value);
if (isgreater(old_value, steps)) {
step_value = old_value - steps; step_value = old_value - steps;
} else { } else {
step_value = target_value; step_value = target_value;
} }
if (isless(step_value, target_value)) {
/* stop ramping */
pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP;
}
} else { } else {
step_value = target_value; debug_printf("LO[%u] Ramp Handler at target=%f tracking=%f\n",
object_instance, target_value, old_value);
/* stop ramping */
pObject->Lighting_Command.operation = BACNET_LIGHTS_STOP;
} }
/* clamp target within min/max, if needed */ if (pObject->Lighting_Command.operation == BACNET_LIGHTS_STOP) {
if (isgreater(step_value, max_value)) { pObject->Tracking_Value = target_value;
step_value = max_value; pObject->In_Progress = BACNET_LIGHTING_IDLE;
} else {
/* clamp target within min/max, if needed */
if (isgreater(step_value, max_value)) {
step_value = max_value;
}
if (isless(step_value, min_value)) {
step_value = min_value;
}
pObject->Tracking_Value = step_value;
pObject->In_Progress = BACNET_LIGHTING_RAMP_ACTIVE;
} }
if (isless(step_value, min_value)) {
step_value = min_value;
}
pObject->Tracking_Value = step_value;
pObject->In_Progress = BACNET_LIGHTING_RAMP_ACTIVE;
} }
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Ramp Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
@@ -2406,6 +2453,12 @@ static void Lighting_Output_Step_Up_Handler(uint32_t object_instance)
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Step Up Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
} }
@@ -2451,6 +2504,12 @@ static void Lighting_Output_Step_Down_Handler(uint32_t object_instance)
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Step Down Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
@@ -2491,6 +2550,12 @@ static void Lighting_Output_Step_On_Handler(uint32_t object_instance)
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Step On Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
@@ -2536,6 +2601,12 @@ static void Lighting_Output_Step_Off_Handler(uint32_t object_instance)
if (Lighting_Output_Write_Present_Value_Callback) { if (Lighting_Output_Write_Present_Value_Callback) {
Lighting_Output_Write_Present_Value_Callback( Lighting_Output_Write_Present_Value_Callback(
object_instance, old_value, pObject->Tracking_Value); object_instance, old_value, pObject->Tracking_Value);
} else {
debug_printf("LO[%u] Step Off Handler Operation=%s Value=%f\n",
object_instance,
bactext_lighting_operation_name(
pObject->Lighting_Command.operation),
pObject->Tracking_Value);
} }
} }
+2 -1
View File
@@ -172,8 +172,9 @@ int lighting_command_decode(
if (len > 0) { if (len > 0) {
apdu_len += len; apdu_len += len;
if (unsigned_value <= BACNET_LIGHTS_PROPRIETARY_LAST) { if (unsigned_value <= BACNET_LIGHTS_PROPRIETARY_LAST) {
operation = (BACNET_LIGHTING_OPERATION)enum_value;
if (data) { if (data) {
data->operation = (BACNET_LIGHTING_OPERATION)enum_value; data->operation = operation;
} }
} else { } else {
return BACNET_STATUS_ERROR; return BACNET_STATUS_ERROR;