Skip to content

Commit f0024af

Browse files
authored
feature: add ramp functionality to lighting output override command (#75)
2 parents a37dfda + a98b2f4 commit f0024af

1 file changed

Lines changed: 32 additions & 13 deletions

File tree

zephyr/subsys/bacnet_shell/bacnet_shell_lighting_output.c

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ cmd_lighting_output_override(const struct shell *shell, int argc, char **argv)
166166
unsigned long long_value;
167167
float float_value = 0.0f;
168168
double double_value;
169+
float ramp_value = 0.0f;
169170
char *end;
170171

172+
/* <instance> <clear|ramp <percent> <rate>|<percent> [momentary] */
171173
if (argc > 1) {
172174
/* <instance> */
173175
long_value = strtoul(argv[1], &end, 0);
@@ -189,6 +191,23 @@ cmd_lighting_output_override(const struct shell *shell, int argc, char **argv)
189191
/* clear the override */
190192
Lighting_Output_Overridden_Clear(instance);
191193
return cmd_lighting_output_value_print(shell, instance);
194+
} else if (bacnet_strnicmp(argv[2], "ramp", 4) == 0) {
195+
/* <level in percent>*/
196+
double_value = strtod(argv[3], &end);
197+
if (end == argv[3]) {
198+
shell_error(shell, "argv[3]=%s invalid percentage", argv[3]);
199+
return -EINVAL;
200+
}
201+
float_value = (float)double_value;
202+
/* <ramp in percent per second>*/
203+
double_value = strtod(argv[4], &end);
204+
if (end == argv[4]) {
205+
shell_error(shell, "argv[4]=%s invalid ramp rate", argv[4]);
206+
return -EINVAL;
207+
}
208+
ramp_value = (float)double_value;
209+
/* ramp the override */
210+
Lighting_Output_Overridden_Ramp(instance, float_value, ramp_value);
192211
} else {
193212
/* <level in percent>*/
194213
double_value = strtod(argv[2], &end);
@@ -197,20 +216,20 @@ cmd_lighting_output_override(const struct shell *shell, int argc, char **argv)
197216
return -EINVAL;
198217
}
199218
float_value = (float)double_value;
219+
if (argc > 3) {
220+
if (bacnet_strnicmp(argv[3], "momentary", 9) == 0) {
221+
/* momentarily override the value */
222+
Lighting_Output_Overridden_Momentary(instance, float_value);
223+
} else {
224+
shell_help(shell);
225+
return -EINVAL;
226+
}
227+
} else {
228+
/* set the override without momentary */
229+
Lighting_Output_Overridden_Set(instance, float_value);
230+
}
200231
}
201232
}
202-
if (argc > 3) {
203-
if (bacnet_strnicmp(argv[3], "momentary", 9) == 0) {
204-
/* momentarily override the value */
205-
Lighting_Output_Overridden_Momentary(instance, float_value);
206-
} else {
207-
shell_help(shell);
208-
return -EINVAL;
209-
}
210-
} else {
211-
/* set the override */
212-
Lighting_Output_Overridden_Set(instance, float_value);
213-
}
214233
return cmd_lighting_output_value_print(shell, instance);
215234
}
216235

@@ -783,7 +802,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
783802
CONFIG_BACNET_BASIC_OBJECT_LIGHTING_OUTPUT,
784803
override,
785804
NULL,
786-
"<instance> <clear|<level percent> [momentary]>",
805+
"<instance> <clear|ramp <percent> <rate>|<percent> [momentary]",
787806
cmd_lighting_output_override),
788807
SHELL_COND_CMD(
789808
CONFIG_BACNET_BASIC_OBJECT_LIGHTING_OUTPUT,

0 commit comments

Comments
 (0)