liblightify
liblightify.h
Go to the documentation of this file.
1 /*
2  liblightify -- library to control OSRAM's LIGHTIFY
3 
4 Copyright (c) 2015, Tobias Frost <tobi@coldtobi.de>
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14  * Neither the name of the author nor the
15  names of its contributors may be used to endorse or promote products
16  derived from this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 #ifndef _LIBlightify_H_
31 #define _LIBlightify_H_
32 
33 #include <stdarg.h>
34 #include <stdint.h>
35 #include <stdlib.h>
36 #include <sys/time.h>
37 
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 
91 /*** \file liblightify.h
92  *
93  * This header defines the public interface to the library.
94  */
95 
96 
97 /* NXP has a nice ZigBee Light Link guide declaring all those types
98  * NOTE: Definitions for On/Off Light and Dimmable Plug Unit are unknown,
99  * those two ZLL classes are missing for completeness... */
100 
112  LIGHTIFY_UNKNOWNTYPE = 0xFF00
113 };
114 
122 };
123 
132 struct lightify_ctx;
133 
150 typedef int (*write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
151 
168 typedef int (*read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
169 
170 
171 // Library context and setup
182 int lightify_new(struct lightify_ctx **ctx, void *reserved);
183 
192 int lightify_free(struct lightify_ctx *ctx);
193 
194 // Socket handling setup
213 int lightify_set_socket_fn(struct lightify_ctx *ctx,
215 
216 
234 int lightify_skt_setfd(struct lightify_ctx *ctx, int socket);
235 
245 int lightify_skt_getfd(struct lightify_ctx *ctx);
246 
263 int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv);
264 
275 struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx);
276 
277 
297 
307 struct lightify_node *lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac);
308 
320  struct lightify_node *node );
321 
333  struct lightify_node *node );
334 
335 
336 // Managment stuff
337 
349  void (*log_fn)(struct lightify_ctx *ctx, int priority, const char *file,
350  int line, const char *fn, const char *format, va_list args));
351 
360 
369 int lightify_set_log_priority(struct lightify_ctx *ctx, int priority);
370 
379 void *lightify_get_userdata(struct lightify_ctx *ctx);
380 
393 int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata);
394 
395 
396 // Node information query
397 
405 const char* lightify_node_get_name(struct lightify_node* node);
406 
414 uint64_t lightify_node_get_nodeadr(struct lightify_node* node);
415 
423 uint16_t lightify_node_get_zoneadr(struct lightify_node* node);
424 
435 uint16_t lightify_node_get_grpadr(struct lightify_node* node);
436 
447 
455 int lightify_node_get_red(struct lightify_node* node);
456 
466 int lightify_node_get_green(struct lightify_node* node);
467 
477 int lightify_node_get_blue(struct lightify_node* node);
478 
488 int lightify_node_get_white(struct lightify_node* node);
489 
499 int lightify_node_get_cct(struct lightify_node* node);
500 
511 
521 int lightify_node_is_on(struct lightify_node* node);
522 
534 int lightify_node_is_stale(struct lightify_node *node);
535 
544 
545 // Node manipulation API -- will talk to the node
546 
556 int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff);
557 
568 int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime);
569 
586  struct lightify_node *node, unsigned int r, unsigned int g,
587  unsigned int b,unsigned int w,unsigned int fadetime);
588 
600  struct lightify_node *node, unsigned int level, unsigned int fadetime);
601 
616 
617 
622 struct lightify_group;
623 
632 struct lightify_group *lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current);
633 
643 
651 const char *lightify_group_get_name(struct lightify_group *grp);
652 
660 int lightify_group_get_id(struct lightify_group *grp);
661 
670 
681 struct lightify_node *lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode);
682 
692 int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff);
693 
704 int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime);
705 
722  struct lightify_group *group, unsigned int r, unsigned int g,
723  unsigned int b,unsigned int w,unsigned int fadetime) ;
724 
736  struct lightify_group *group, unsigned int level, unsigned int fadetime) ;
737 
738 
739 #ifdef __cplusplus
740 } /* extern "C" */
741 #endif
742 
743 #endif
int lightify_set_socket_fn(struct lightify_ctx *ctx, write_to_socket_fn fpw, read_from_socket_fn fpr)
Definition: context.c:430
void * lightify_get_userdata(struct lightify_ctx *ctx)
Definition: context.c:417
int lightify_new(struct lightify_ctx **ctx, void *reserved)
Definition: context.c:445
int lightify_free(struct lightify_ctx *ctx)
Definition: context.c:494
int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata)
Definition: context.c:423
const char * lightify_group_get_name(struct lightify_group *grp)
Definition: groups.c:117
int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime)
Definition: context.c:1192
int lightify_group_get_id(struct lightify_group *grp)
Definition: groups.c:128
struct lightify_group * lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:134
int lightify_group_request_brightness(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int level, unsigned int fadetime)
Definition: context.c:1223
int lightify_group_request_scan(struct lightify_ctx *ctx)
Definition: context.c:1082
struct lightify_group * lightify_group_get_previous(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:140
int lightify_group_request_rgbw(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int r, unsigned int g, unsigned int b, unsigned int w, unsigned int fadetime)
Definition: context.c:1205
int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff)
Definition: context.c:1178
struct lightify_node * lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode)
Definition: groups.c:147
int(* write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:150
struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx)
Definition: socket.c:221
int(* read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:168
int lightify_skt_getfd(struct lightify_ctx *ctx)
Definition: socket.c:210
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
Definition: socket.c:204
int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv)
Definition: socket.c:215
int lightify_node_request_rgbw(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int r, unsigned int g, unsigned int b, unsigned int w, unsigned int fadetime)
Definition: context.c:959
struct lightify_node * lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac)
Definition: context.c:314
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node *node)
Definition: node.c:208
int lightify_node_get_cct(struct lightify_node *node)
Definition: node.c:263
lightify_node_online_state
Definition: liblightify.h:119
int lightify_node_get_red(struct lightify_node *node)
Definition: node.c:219
int lightify_node_request_brightness(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int level, unsigned int fadetime)
Definition: context.c:975
uint16_t lightify_node_get_grpadr(struct lightify_node *node)
Definition: node.c:197
int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff)
Definition: context.c:922
int lightify_node_get_green(struct lightify_node *node)
Definition: node.c:241
int lightify_node_is_on(struct lightify_node *node)
Definition: node.c:286
int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime)
Definition: context.c:947
struct lightify_node * lightify_node_get_previous(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:410
struct lightify_node * lightify_node_get_next(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:402
int lightify_node_get_onlinestate(struct lightify_node *node)
Definition: node.c:297
int lightify_node_is_stale(struct lightify_node *node)
Definition: node.c:302
lightify_node_type
Definition: liblightify.h:105
uint64_t lightify_node_get_nodeadr(struct lightify_node *node)
Definition: node.c:175
int lightify_node_get_blue(struct lightify_node *node)
Definition: node.c:230
const char * lightify_node_get_name(struct lightify_node *node)
Definition: node.c:164
int lightify_node_get_white(struct lightify_node *node)
Definition: node.c:252
int lightify_node_request_scan(struct lightify_ctx *ctx)
Definition: context.c:505
uint16_t lightify_node_get_zoneadr(struct lightify_node *node)
Definition: node.c:186
int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:987
int lightify_node_get_brightness(struct lightify_node *node)
Definition: node.c:274
@ LIGHTIFY_OFFLINE
Definition: liblightify.h:120
@ LIGHTIFY_ONLINE
Definition: liblightify.h:121
@ LIGHTIFY_EXT_COLOUR_LIGHT
Definition: liblightify.h:109
@ LIGHTIFY_UNKNOWNTYPE
Definition: liblightify.h:112
@ LIGHTIFY_DIMABLE_LIGHT
Definition: liblightify.h:107
@ LIGHTIFY_4WAY_SWITCH
Definition: liblightify.h:111
@ LIGHTIFY_ONOFF_PLUG
Definition: liblightify.h:106
@ LIGHTIFY_CCT_LIGHT
Definition: liblightify.h:110
@ LIGHTIFY_COLOUR_LIGHT
Definition: liblightify.h:108
int lightify_set_log_fn(struct lightify_ctx *ctx, void(*log_fn)(struct lightify_ctx *ctx, int priority, const char *file, int line, const char *fn, const char *format, va_list args))
Definition: log.c:89
int lightify_set_log_priority(struct lightify_ctx *ctx, int priority)
Definition: log.c:105
int lightify_get_log_priority(struct lightify_ctx *ctx)
Definition: log.c:99
static void const char * format
int fadetime
Definition: lightify-util.c:99
int socket
Definition: context.h:87
struct lightify_ctx * ctx
Definition: groups.c:47
struct lightify_ctx * ctx
Definition: node.c:46
int cct
Definition: node.c:67