49 #ifdef IPSO_LIGHT_CONTROL
50 extern const struct ipso_objects_actuator IPSO_LIGHT_CONTROL;
53 static unsigned long last_on_time;
54 static uint32_t total_on_time;
55 static int dim_level = 0;
56 static uint8_t is_on = 0;
59 read_state(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
61 return ctx->writer->write_boolean(ctx, outbuf, outsize, is_on ? 1 : 0);
65 write_state(lwm2m_context_t *ctx,
const uint8_t *inbuf,
size_t insize,
66 uint8_t *outbuf,
size_t outsize)
71 len = ctx->reader->read_boolean(ctx, inbuf, insize, &value);
84 #ifdef IPSO_LIGHT_CONTROL
85 if(IPSO_LIGHT_CONTROL.set_on) {
86 IPSO_LIGHT_CONTROL.set_on(value);
87 }
else if(IPSO_LIGHT_CONTROL.set_dim_level) {
88 dim_level = value ? 100 : 0;
89 IPSO_LIGHT_CONTROL.set_dim_level(dim_level);
97 read_dim(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
99 return ctx->writer->write_int(ctx, outbuf, outsize, dim_level);
103 write_dim(lwm2m_context_t *ctx,
const uint8_t *inbuf,
size_t insize,
104 uint8_t *outbuf,
size_t outsize)
109 len = ctx->reader->read_int(ctx, inbuf, insize, &value);
113 }
else if(value > 100) {
129 #ifdef IPSO_LIGHT_CONTROL
130 if(IPSO_LIGHT_CONTROL.set_dim_level) {
131 IPSO_LIGHT_CONTROL.set_dim_level(dim_level);
132 }
else if(IPSO_LIGHT_CONTROL.set_on) {
133 IPSO_LIGHT_CONTROL.set_on(is_on);
141 read_on_time(lwm2m_context_t *ctx, uint8_t *outbuf,
size_t outsize)
147 total_on_time += now - last_on_time;
150 return ctx->writer->write_int(ctx, outbuf, outsize, (int32_t)total_on_time);
154 write_on_time(lwm2m_context_t *ctx,
155 const uint8_t *inbuf,
size_t insize,
156 uint8_t *outbuf,
size_t outsize)
161 len = ctx->reader->read_int(ctx, inbuf, insize, &value);
162 if(len > 0 && value == 0) {
171 LWM2M_RESOURCES(light_control_resources,
172 LWM2M_RESOURCE_CALLBACK(5850, { read_state, write_state,
NULL }),
173 LWM2M_RESOURCE_CALLBACK(5851, { read_dim, write_dim,
NULL }),
174 LWM2M_RESOURCE_CALLBACK(5852, { read_on_time, write_on_time,
NULL }),
176 LWM2M_INSTANCES(light_control_instances,
177 LWM2M_INSTANCE(0, light_control_resources));
178 LWM2M_OBJECT(light_control, 3311, light_control_instances);
181 ipso_light_control_init(
void)
183 #ifdef IPSO_LIGHT_CONTROL
184 if(IPSO_LIGHT_CONTROL.init) {
185 IPSO_LIGHT_CONTROL.init();
187 if(IPSO_LIGHT_CONTROL.is_on) {
188 is_on = IPSO_LIGHT_CONTROL.is_on();
190 if(IPSO_LIGHT_CONTROL.get_dim_level) {
191 dim_level = IPSO_LIGHT_CONTROL.get_dim_level();
192 if(dim_level > 0 && IPSO_LIGHT_CONTROL.is_on ==
NULL) {
199 lwm2m_engine_register_object(&light_control);
Header file for the Contiki IPSO Objects for OMA LWM2M
Header file for the Contiki OMA LWM2M object API
Header file for the Contiki OMA LWM2M engine
#define NULL
The null pointer.
CCIF unsigned long clock_seconds(void)
Get the current value of the platform seconds.