Nyx Node
Loading...
Searching...
No Matches
indi_light.c
1/* NyxNode
2 * Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3 * SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4 */
5
6/*--------------------------------------------------------------------------------------------------------------------*/
7
8#include <stdio.h>
9
10#include "../nyx_node_internal.h"
11
12/*--------------------------------------------------------------------------------------------------------------------*/
13/* PROP */
14/*--------------------------------------------------------------------------------------------------------------------*/
15
16nyx_dict_t *nyx_light_prop_new(STR_t name, STR_t label, nyx_state_t value)
17{
18 if(label == NULL || label[0] == '\0')
19 {
20 label = name;
21 }
22
23 /*----------------------------------------------------------------------------------------------------------------*/
24
25 nyx_dict_t *result = nyx_dict_new();
26
27 nyx_dict_set(result, "<>", nyx_string_from_dup("defLight"));
28
29 nyx_dict_set(result, "@name", nyx_string_from_dup(name));
30 nyx_dict_set(result, "@label", nyx_string_from_dup(label));
31
32 nyx_dict_set(result, "$", nyx_string_from_dup(nyx_state_to_str(value)));
33
34 /*----------------------------------------------------------------------------------------------------------------*/
35
36 return result;
37}
38
39/*--------------------------------------------------------------------------------------------------------------------*/
40/* PROP SETTER & GETTER */
41/*--------------------------------------------------------------------------------------------------------------------*/
42
44{
45 return nyx_dict_set(prop, "$", nyx_string_from_dup(nyx_state_to_str(value)));
46}
47
48/*--------------------------------------------------------------------------------------------------------------------*/
49
51{
52 return nyx_str_to_state(nyx_string_get((nyx_string_t *) nyx_dict_get(prop, "$")));
53}
54
55/*--------------------------------------------------------------------------------------------------------------------*/
56/* VECTOR */
57/*--------------------------------------------------------------------------------------------------------------------*/
58
59nyx_dict_t *nyx_light_vector_new(
60 STR_t device,
61 STR_t name,
62 nyx_state_t state,
63 nyx_dict_t *props[],
64 const nyx_opts_t *opts
65) {
66 /*----------------------------------------------------------------------------------------------------------------*/
67
68 nyx_dict_t *result = nyx_dict_new();
69
70 nyx_list_t *children = nyx_list_new();
71
72 /*----------------------------------------------------------------------------------------------------------------*/
73
74 nyx_dict_set(result, "<>", nyx_string_from_dup("defLightVector"));
75
76 nyx_dict_set(result, "children", children);
77
78 /*----------------------------------------------------------------------------------------------------------------*/
79
80 nyx_dict_set(result, "@client", nyx_string_from_dup("unknown"));
81 nyx_dict_set(result, "@device", nyx_string_from_dup(device));
82 nyx_dict_set(result, "@name", nyx_string_from_dup(name));
83
84 nyx_dict_set(result, "@state", nyx_string_from_dup(nyx_state_to_str(state)));
85
86 /*----------------------------------------------------------------------------------------------------------------*/
87
88 internal_set_opts(result, opts);
89
90 /*----------------------------------------------------------------------------------------------------------------*/
91
92 for(; *props != NULL; props++) nyx_list_push(children, *props);
93
94 /*----------------------------------------------------------------------------------------------------------------*/
95
96 return result;
97}
98
99/*--------------------------------------------------------------------------------------------------------------------*/
100/* SET VECTOR */
101/*--------------------------------------------------------------------------------------------------------------------*/
102
103nyx_dict_t *nyx_light_set_vector_new(const nyx_dict_t *vector)
104{
105 return internal_prop_to_set_vector(vector, "setLightVector", "oneLight");
106}
107
108/*--------------------------------------------------------------------------------------------------------------------*/
#define STR_t
Alias for const char *.
Definition nyx_node.h:71
bool nyx_light_prop_set(nyx_dict_t *prop, nyx_state_t value)
Sets the new value of the provided property object.
Definition indi_light.c:43
nyx_state_t nyx_light_prop_get(const nyx_dict_t *prop)
Gets the current value of the provided property object.
Definition indi_light.c:50
nyx_state_t
Vector state hint.
Definition nyx_node.h:1781
Struct describing a JSON dict object.
Struct describing a JSON list object.
Struct describing the options for INDI / Nyx vectors.
Definition nyx_node.h:1917
Struct describing a JSON string object.
Definition nyx_node.h:900