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 };
113 
121 };
122 
131 struct lightify_ctx;
132 
149 typedef int (*write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
150 
167 typedef int (*read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
168 
169 
170 // Library context and setup
181 int lightify_new(struct lightify_ctx **ctx, void *reserved);
182 
191 int lightify_free(struct lightify_ctx *ctx);
192 
193 // Socket handling setup
212 int lightify_set_socket_fn(struct lightify_ctx *ctx,
214 
215 
233 int lightify_skt_setfd(struct lightify_ctx *ctx, int socket);
234 
244 int lightify_skt_getfd(struct lightify_ctx *ctx);
245 
262 int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv);
263 
274 struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx);
275 
276 
296 
306 struct lightify_node *lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac);
307 
319  struct lightify_node *node );
320 
332  struct lightify_node *node );
333 
334 
335 // Managment stuff
336 
347 int lightify_set_log_fn(struct lightify_ctx *ctx,
348  void (*log_fn)(struct lightify_ctx *ctx, int priority, const char *file,
349  int line, const char *fn, const char *format, va_list args));
350 
358 int lightify_get_log_priority(struct lightify_ctx *ctx);
359 
368 int lightify_set_log_priority(struct lightify_ctx *ctx, int priority);
369 
378 void *lightify_get_userdata(struct lightify_ctx *ctx);
379 
392 int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata);
393 
394 
395 // Node information query
396 
404 const char* lightify_node_get_name(struct lightify_node* node);
405 
413 uint64_t lightify_node_get_nodeadr(struct lightify_node* node);
414 
422 uint16_t lightify_node_get_zoneadr(struct lightify_node* node);
423 
434 uint16_t lightify_node_get_grpadr(struct lightify_node* node);
435 
446 
454 int lightify_node_get_red(struct lightify_node* node);
455 
465 int lightify_node_get_green(struct lightify_node* node);
466 
476 int lightify_node_get_blue(struct lightify_node* node);
477 
487 int lightify_node_get_white(struct lightify_node* node);
488 
498 int lightify_node_get_cct(struct lightify_node* node);
499 
510 
520 int lightify_node_is_on(struct lightify_node* node);
521 
533 int lightify_node_is_stale(struct lightify_node *node);
534 
543 
544 // Node manipulation API -- will talk to the node
545 
555 int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff);
556 
567 int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime);
568 
585  struct lightify_node *node, unsigned int r, unsigned int g,
586  unsigned int b,unsigned int w,unsigned int fadetime);
587 
599  struct lightify_node *node, unsigned int level, unsigned int fadetime);
600 
614 int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node);
615 
616 
621 struct lightify_group;
622 
631 struct lightify_group *lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current);
632 
641 struct lightify_group *lightify_group_get_previous(struct lightify_ctx *ctx, struct lightify_group *current);
642 
650 const char *lightify_group_get_name(struct lightify_group *grp);
651 
659 int lightify_group_get_id(struct lightify_group *grp);
660 
669 
680 struct lightify_node *lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode);
681 
691 int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff);
692 
703 int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime);
704 
721  struct lightify_group *group, unsigned int r, unsigned int g,
722  unsigned int b,unsigned int w,unsigned int fadetime) ;
723 
735  struct lightify_group *group, unsigned int level, unsigned int fadetime) ;
736 
737 
738 #ifdef __cplusplus
739 } /* extern "C" */
740 #endif
741 
742 #endif
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:889
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
Definition: socket.c:206
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_free(struct lightify_ctx *ctx)
Definition: context.c:475
static void const char * format
int lightify_node_request_scan(struct lightify_ctx *ctx)
Definition: context.c:486
int(* read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:167
const char * lightify_node_get_name(struct lightify_node *node)
Definition: node.c:164
int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff)
Definition: context.c:1073
int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff)
Definition: context.c:852
int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv)
Definition: socket.c:217
int lightify_node_get_brightness(struct lightify_node *node)
Definition: node.c:274
int lightify_set_log_priority(struct lightify_ctx *ctx, int priority)
Definition: log.c:105
int lightify_group_request_scan(struct lightify_ctx *ctx)
Definition: context.c:977
int lightify_skt_getfd(struct lightify_ctx *ctx)
Definition: socket.c:212
uint64_t lightify_node_get_nodeadr(struct lightify_node *node)
Definition: node.c:175
int lightify_node_is_stale(struct lightify_node *node)
Definition: node.c:302
void * lightify_get_userdata(struct lightify_ctx *ctx)
Definition: context.c:400
struct lightify_group * lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:134
int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime)
Definition: context.c:1087
int lightify_node_is_on(struct lightify_node *node)
Definition: node.c:286
int lightify_group_get_id(struct lightify_group *grp)
Definition: groups.c:128
int fadetime
Definition: lightify-util.c:98
int lightify_set_socket_fn(struct lightify_ctx *ctx, write_to_socket_fn fpw, read_from_socket_fn fpr)
Definition: context.c:413
struct lightify_node * lightify_node_get_next(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:385
int(* write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:149
int lightify_group_request_brightness(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int level, unsigned int fadetime)
Definition: context.c:1118
uint16_t lightify_node_get_grpadr(struct lightify_node *node)
Definition: node.c:197
int lightify_node_get_red(struct lightify_node *node)
Definition: node.c:219
struct lightify_node * lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode)
Definition: groups.c:147
lightify_node_online_state
Definition: liblightify.h:118
struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx)
Definition: socket.c:223
int lightify_node_get_cct(struct lightify_node *node)
Definition: node.c:263
int lightify_node_request_brightness(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int level, unsigned int fadetime)
Definition: context.c:905
int lightify_node_get_white(struct lightify_node *node)
Definition: node.c:252
int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata)
Definition: context.c:406
lightify_node_type
Definition: liblightify.h:105
struct lightify_node * lightify_node_get_previous(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:393
int lightify_new(struct lightify_ctx **ctx, void *reserved)
Definition: context.c:428
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node *node)
Definition: node.c:208
int lightify_get_log_priority(struct lightify_ctx *ctx)
Definition: log.c:99
struct lightify_node * lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac)
Definition: context.c:297
int lightify_node_get_onlinestate(struct lightify_node *node)
Definition: node.c:297
struct lightify_group * lightify_group_get_previous(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:140
int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:919
int lightify_node_get_green(struct lightify_node *node)
Definition: node.c:241
int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime)
Definition: context.c:877
int lightify_node_get_blue(struct lightify_node *node)
Definition: node.c:230
const char * lightify_group_get_name(struct lightify_group *grp)
Definition: groups.c:117
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:1100
uint16_t lightify_node_get_zoneadr(struct lightify_node *node)
Definition: node.c:186
int cct
Definition: node.c:67
int socket
Definition: context.h:82