Skip to content

Commit

Permalink
Fix CC SWITCH_COLOR Duration param
Browse files Browse the repository at this point in the history
Duration can be any value in the range 0x01..0xFD.

For reference, see:
CC:0000.00.00.11.015
CC:0033.02.05.11.007

Signed-off-by: Nenad Kljajic <nkljajic@control4.com>
  • Loading branch information
nkljajic committed Nov 29, 2023
1 parent 5ad3615 commit c3c9d91
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ fn switch_color_set(state_node: Attribute) -> Result<(sl_status_t, Vec<u8>), Att
reserved: 0,
},
vg1: colors,
// FIXME: UIC-1926 This SwitchColorSetFrame wants a SwitchColorSetDurationEnum for
// the duration, which prevents me to use my duration found in the attribute store.
duration: SwitchColorSetDurationEnum::Instantly,
duration: _duration as u8,
};

Ok((SL_STATUS_OK, set_frame.into()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12970,7 +12970,10 @@
<param key="0x00" name="Color Component ID" type="BYTE" />
<param key="0x01" name="Value" type="BYTE" />
</variant_group>
<param key="0x02" name="Duration" type="BYTE" />
<param key="0x02" name="Duration" type="BYTE">
<bitflag key="0x01" flagname="Instantly" flagmask="0x00" />
<bitflag key="0x02" flagname="Default" flagmask="0xFF" />
</param>
</cmd>
<cmd key="0x06" name="SWITCH_COLOR_START_LEVEL_CHANGE" help="Color Switch Start Level Change" support_mode="RX">
<param key="0x00" name="Properties1" type="STRUCT_BYTE">
Expand Down Expand Up @@ -12998,10 +13001,10 @@
<param key="0x00" name="Color Component ID" type="BYTE" />
<param key="0x01" name="Current Value" type="BYTE" />
<param key="0x02" name="Target Value" type="BYTE" />
<param key="0x03" name="Duration" type="CONST">
<const key="0x00" flagname="Already at the Target Value" flagmask="0x00" />
<const key="0x01" flagname="Unknown duration" flagmask="0xFE" />
<const key="0x02" flagname="Reserved" flagmask="0xFF" />
<param key="0x03" name="Duration" type="BYTE">
<bitflag key="0x00" flagname="Already at the Target Value" flagmask="0x00" />
<bitflag key="0x01" flagname="Unknown duration" flagmask="0xFE" />
<bitflag key="0x02" flagname="Reserved" flagmask="0xFF" />
</param>
</cmd>
<cmd key="0x05" name="SWITCH_COLOR_SET" help="Color Switch Set" support_mode="RX">
Expand All @@ -13013,9 +13016,9 @@
<param key="0x00" name="Color Component ID" type="BYTE" />
<param key="0x01" name="Value" type="BYTE" />
</variant_group>
<param key="0x02" name="Duration" type="CONST">
<const key="0x00" flagname="Instantly" flagmask="0x00" />
<const key="0x01" flagname="Default" flagmask="0xFF" />
<param key="0x02" name="Duration" type="BYTE">
<bitflag key="0x01" flagname="Instantly" flagmask="0x00" />
<bitflag key="0x02" flagname="Default" flagmask="0xFF" />
</param>
</cmd>
<cmd key="0x06" name="SWITCH_COLOR_START_LEVEL_CHANGE" help="Color Switch Start Level Change" support_mode="RX">
Expand All @@ -13027,9 +13030,9 @@
</param>
<param key="0x01" name="Color Component ID" type="BYTE" />
<param key="0x02" name="Start Level" type="BYTE" />
<param key="0x03" name="Duration" type="CONST">
<const key="0x00" flagname="Instantly" flagmask="0x00" />
<const key="0x01" flagname="Default" flagmask="0xFF" />
<param key="0x03" name="Duration" type="BYTE">
<bitflag key="0x01" flagname="Instantly" flagmask="0x00" />
<bitflag key="0x02" flagname="Default" flagmask="0xFF" />
</param>
</cmd>
<cmd key="0x07" name="SWITCH_COLOR_STOP_LEVEL_CHANGE" help="Color Switch Stop Level Change" support_mode="RX">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "attribute_store_defined_attribute_types.h"
#include "ZW_classcmd.h"
#include "zpc_attribute_resolver.h"
#include "zwave_command_classes_utils.h"

// Includes from other Unify Components
#include "dotdot_mqtt.h"
Expand All @@ -34,6 +35,38 @@
#include "attribute_timeouts.h"
#include "sl_log.h"

#define LOG_TAG "zwave_command_class_switch_color"

[[maybe_unused]]
static void set_desired_duration(attribute_store_node_t state_node,
uint32_t duration)
{
attribute_store_node_t duration_node
= attribute_store_get_first_child_by_type(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);

attribute_store_set_node_attribute_value(duration_node,
DESIRED_ATTRIBUTE,
(uint8_t *)&duration,
sizeof(duration));
}

static void set_reported_duration(attribute_store_node_t state_node,
uint32_t duration)
{
attribute_store_node_t duration_node
= attribute_store_get_first_child_by_type(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);

attribute_store_set_node_attribute_value(duration_node,
REPORTED_ATTRIBUTE,
(uint8_t *)&duration,
sizeof(duration));
}

[[maybe_unused]]
static void
set_all_color_switch_durations(attribute_store_node_t state_node,
attribute_store_node_value_state_t value_state,
Expand Down Expand Up @@ -64,6 +97,34 @@ static void
}
}

static void switch_color_undefine_reported(attribute_store_node_t state_node)
{
zwave_command_class_switch_color_invoke_on_all_attributes_with_return_value(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_stop_transition);

attribute_store_node_t duration_node
= attribute_store_get_first_child_by_type(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);
color_component_id_duration_t duration = 0;
attribute_store_undefine_desired(duration_node);
attribute_store_set_reported(duration_node,
&duration,
sizeof(duration));

sl_log_debug(LOG_TAG, "Transition time expired, probe color");
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_store_undefine_desired);
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_store_undefine_reported);
}

// FIXME: UIC-1901 This function belongs to zwave_command_class_switch_color.rs, but this
// component really cannot interact with the attribute resolver.
static void
Expand All @@ -78,12 +139,22 @@ static void
return;
}

attribute_store_node_t duration_node
= attribute_store_get_first_child_by_type(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);

color_component_id_duration_t duration = 0;
attribute_store_get_desired(duration_node,
&duration,
sizeof(duration));

clock_time_t zwave_desired_duration
= zwave_duration_to_time((uint8_t)duration);

switch (event) {
case FRAME_SENT_EVENT_OK_SUPERVISION_WORKING:
zwave_command_class_switch_color_invoke_on_all_attributes_with_return_value(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION,
&attribute_store_set_reported_as_desired);
attribute_store_set_reported_as_desired(duration_node);
break;

case FRAME_SENT_EVENT_OK_SUPERVISION_SUCCESS:
Expand All @@ -95,11 +166,44 @@ static void
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
&attribute_store_undefine_desired);
set_all_color_switch_durations(state_node, REPORTED_ATTRIBUTE, 0);
set_all_color_switch_durations(state_node, DESIRED_ATTRIBUTE, 0);
set_reported_duration(state_node, 0);
attribute_store_undefine_desired(duration_node);
break;

case FRAME_SENT_EVENT_OK_NO_SUPERVISION:
zwave_command_class_switch_color_invoke_on_all_attributes_with_return_value(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_stop_transition);
if(zwave_desired_duration > 0) {
// Should we estimate reported color values during transition
// and publish them as reported, like we did for level cluster?

zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_store_undefine_desired);

attribute_store_set_reported_as_desired(duration_node);
attribute_store_undefine_desired(duration_node);

// Probe again after this duration
attribute_timeout_set_callback(state_node,
zwave_desired_duration + PROBE_BACK_OFF,
&switch_color_undefine_reported);
} else {
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_store_undefine_desired);
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
attribute_store_undefine_reported);
attribute_store_undefine_desired(duration_node);
}
break;

// FRAME_SENT_EVENT_OK_NO_SUPERVISION:
// FRAME_SENT_EVENT_OK_SUPERVISION_NO_SUPPORT:
// FRAME_SENT_EVENT_OK_SUPERVISION_FAIL:
default:
Expand All @@ -115,14 +219,8 @@ static void
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
&attribute_store_undefine_reported);
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION,
&attribute_store_undefine_desired);
zwave_command_class_switch_color_invoke_on_all_attributes(
state_node,
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION,
&attribute_store_undefine_reported);
attribute_store_undefine_desired(duration_node);
attribute_store_undefine_reported(duration_node);
break;
}

Expand Down Expand Up @@ -190,4 +288,4 @@ void zwave_command_class_switch_color_invoke_on_all_attributes_with_return_value
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_COLOR_COMPONENT_ID,
index);
}
}
}

0 comments on commit c3c9d91

Please sign in to comment.