liblightify.h
Go to the documentation of this file.
/*
liblightify -- library to control OSRAM's LIGHTIFY
Copyright (c) 2015, Tobias Frost <tobi@coldtobi.de>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LIBlightify_H_
#define _LIBlightify_H_
#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/time.h>
#ifdef __cplusplus
extern "C" {
#endif
/*** \file liblightify.h
*
* This header defines the public interface to the library.
*/
/* NXP has a nice ZigBee Light Link guide declaring all those types
* NOTE: Definitions for On/Off Light and Dimmable Plug Unit are unknown,
* those two ZLL classes are missing for completeness... */
enum lightify_node_type {
LIGHTIFY_ONOFF_PLUG,
LIGHTIFY_DIMABLE_LIGHT,
LIGHTIFY_COLOUR_LIGHT,
LIGHTIFY_EXT_COLOUR_LIGHT,
LIGHTIFY_CCT_LIGHT,
LIGHTIFY_4WAY_SWITCH,
LIGHTIFY_UNKNOWNTYPE = 0xFF00
};
enum lightify_node_online_state {
LIGHTIFY_OFFLINE = 0,
LIGHTIFY_ONLINE = 2,
};
struct lightify_ctx;
typedef int (*write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
typedef int (*read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size);
// Library context and setup
int lightify_new(struct lightify_ctx **ctx, void *reserved);
int lightify_free(struct lightify_ctx *ctx);
// Socket handling setup
int lightify_set_socket_fn(struct lightify_ctx *ctx,
write_to_socket_fn fpw, read_from_socket_fn fpr);
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket);
int lightify_skt_getfd(struct lightify_ctx *ctx);
int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv);
struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx);
int lightify_node_request_scan(struct lightify_ctx *ctx);
struct lightify_node *lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac);
struct lightify_node* lightify_node_get_next(struct lightify_ctx *ctx,
struct lightify_node *node );
struct lightify_node* lightify_node_get_previous(struct lightify_ctx *ctx,
struct lightify_node *node );
// Managment stuff
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));
int lightify_get_log_priority(struct lightify_ctx *ctx);
int lightify_set_log_priority(struct lightify_ctx *ctx, int priority);
void *lightify_get_userdata(struct lightify_ctx *ctx);
int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata);
// Node information query
const char* lightify_node_get_name(struct lightify_node* node);
uint64_t lightify_node_get_nodeadr(struct lightify_node* node);
uint16_t lightify_node_get_zoneadr(struct lightify_node* node);
uint16_t lightify_node_get_grpadr(struct lightify_node* node);
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node* node);
int lightify_node_get_red(struct lightify_node* node);
int lightify_node_get_green(struct lightify_node* node);
int lightify_node_get_blue(struct lightify_node* node);
int lightify_node_get_white(struct lightify_node* node);
int lightify_node_get_cct(struct lightify_node* node);
int lightify_node_get_brightness(struct lightify_node* node);
int lightify_node_is_on(struct lightify_node* node);
int lightify_node_is_stale(struct lightify_node *node);
int lightify_node_get_onlinestate(struct lightify_node* node);
// Node manipulation API -- will talk to the node
int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff);
int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime);
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);
int lightify_node_request_brightness(struct lightify_ctx *ctx,
struct lightify_node *node, unsigned int level, unsigned int fadetime);
int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node);
struct lightify_group;
struct lightify_group *lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current);
struct lightify_group *lightify_group_get_previous(struct lightify_ctx *ctx, struct lightify_group *current);
const char *lightify_group_get_name(struct lightify_group *grp);
int lightify_group_get_id(struct lightify_group *grp);
int lightify_group_request_scan(struct lightify_ctx *ctx);
struct lightify_node *lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode);
int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff);
int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime);
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) ;
int lightify_group_request_brightness(struct lightify_ctx *ctx,
struct lightify_group *group, unsigned int level, unsigned int fadetime) ;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
lightify_node_request_rgbw
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
lightify_skt_setfd
int lightify_skt_setfd(struct lightify_ctx *ctx, int socket)
Definition: socket.c:204
lightify_set_log_fn
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
lightify_free
int lightify_free(struct lightify_ctx *ctx)
Definition: context.c:494
format
static void const char * format
Definition: liblightify-private.h:42
lightify_node_request_scan
int lightify_node_request_scan(struct lightify_ctx *ctx)
Definition: context.c:505
read_from_socket_fn
int(* read_from_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:168
lightify_node_get_name
const char * lightify_node_get_name(struct lightify_node *node)
Definition: node.c:164
LIGHTIFY_UNKNOWNTYPE
Definition: liblightify.h:112
lightify_group_request_onoff
int lightify_group_request_onoff(struct lightify_ctx *ctx, struct lightify_group *group, int onoff)
Definition: context.c:1178
lightify_node_request_onoff
int lightify_node_request_onoff(struct lightify_ctx *ctx, struct lightify_node *node, int onoff)
Definition: context.c:922
lightify_skt_setiotimeout
int lightify_skt_setiotimeout(struct lightify_ctx *ctx, struct timeval tv)
Definition: socket.c:215
lightify_node_get_brightness
int lightify_node_get_brightness(struct lightify_node *node)
Definition: node.c:274
lightify_set_log_priority
int lightify_set_log_priority(struct lightify_ctx *ctx, int priority)
Definition: log.c:105
lightify_group_request_scan
int lightify_group_request_scan(struct lightify_ctx *ctx)
Definition: context.c:1082
lightify_skt_getfd
int lightify_skt_getfd(struct lightify_ctx *ctx)
Definition: socket.c:210
lightify_node_get_nodeadr
uint64_t lightify_node_get_nodeadr(struct lightify_node *node)
Definition: node.c:175
lightify_node_is_stale
int lightify_node_is_stale(struct lightify_node *node)
Definition: node.c:302
lightify_get_userdata
void * lightify_get_userdata(struct lightify_ctx *ctx)
Definition: context.c:417
lightify_group_get_next
struct lightify_group * lightify_group_get_next(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:134
lightify_ctx
Definition: context.h:68
lightify_group_request_cct
int lightify_group_request_cct(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int cct, unsigned int fadetime)
Definition: context.c:1192
lightify_node_is_on
int lightify_node_is_on(struct lightify_node *node)
Definition: node.c:286
LIGHTIFY_DIMABLE_LIGHT
Definition: liblightify.h:107
lightify_group_get_id
int lightify_group_get_id(struct lightify_group *grp)
Definition: groups.c:128
fadetime
int fadetime
Definition: lightify-util.c:99
LIGHTIFY_COLOUR_LIGHT
Definition: liblightify.h:108
lightify_set_socket_fn
int lightify_set_socket_fn(struct lightify_ctx *ctx, write_to_socket_fn fpw, read_from_socket_fn fpr)
Definition: context.c:430
lightify_node_get_next
struct lightify_node * lightify_node_get_next(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:402
write_to_socket_fn
int(* write_to_socket_fn)(struct lightify_ctx *ctx, unsigned char *msg, size_t size)
Definition: liblightify.h:150
lightify_group
Definition: groups.c:46
LIGHTIFY_4WAY_SWITCH
Definition: liblightify.h:111
lightify_group_request_brightness
int lightify_group_request_brightness(struct lightify_ctx *ctx, struct lightify_group *group, unsigned int level, unsigned int fadetime)
Definition: context.c:1223
lightify_node_get_grpadr
uint16_t lightify_node_get_grpadr(struct lightify_node *node)
Definition: node.c:197
LIGHTIFY_CCT_LIGHT
Definition: liblightify.h:110
lightify_node_get_red
int lightify_node_get_red(struct lightify_node *node)
Definition: node.c:219
lightify_group_get_next_node
struct lightify_node * lightify_group_get_next_node(struct lightify_group *grp, struct lightify_node *lastnode)
Definition: groups.c:147
lightify_node_online_state
lightify_node_online_state
Definition: liblightify.h:119
lightify_skt_getiotimeout
struct timeval lightify_skt_getiotimeout(struct lightify_ctx *ctx)
Definition: socket.c:221
lightify_node_get_cct
int lightify_node_get_cct(struct lightify_node *node)
Definition: node.c:263
lightify_node_request_brightness
int lightify_node_request_brightness(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int level, unsigned int fadetime)
Definition: context.c:975
lightify_node_get_white
int lightify_node_get_white(struct lightify_node *node)
Definition: node.c:252
lightify_set_userdata
int lightify_set_userdata(struct lightify_ctx *ctx, void *userdata)
Definition: context.c:423
lightify_node_type
lightify_node_type
Definition: liblightify.h:105
LIGHTIFY_ONLINE
Definition: liblightify.h:121
lightify_node_get_previous
struct lightify_node * lightify_node_get_previous(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:410
LIGHTIFY_EXT_COLOUR_LIGHT
Definition: liblightify.h:109
lightify_new
int lightify_new(struct lightify_ctx **ctx, void *reserved)
Definition: context.c:445
lightify_node
Definition: node.c:43
lightify_node_get_lamptype
enum lightify_node_type lightify_node_get_lamptype(struct lightify_node *node)
Definition: node.c:208
lightify_get_log_priority
int lightify_get_log_priority(struct lightify_ctx *ctx)
Definition: log.c:99
lightify_node_get_from_mac
struct lightify_node * lightify_node_get_from_mac(struct lightify_ctx *ctx, uint64_t mac)
Definition: context.c:314
lightify_node_get_onlinestate
int lightify_node_get_onlinestate(struct lightify_node *node)
Definition: node.c:297
lightify_group_get_previous
struct lightify_group * lightify_group_get_previous(struct lightify_ctx *ctx, struct lightify_group *current)
Definition: groups.c:140
lightify_node_request_update
int lightify_node_request_update(struct lightify_ctx *ctx, struct lightify_node *node)
Definition: context.c:987
lightify_node_get_green
int lightify_node_get_green(struct lightify_node *node)
Definition: node.c:241
lightify_node_request_cct
int lightify_node_request_cct(struct lightify_ctx *ctx, struct lightify_node *node, unsigned int cct, unsigned int fadetime)
Definition: context.c:947
LIGHTIFY_ONOFF_PLUG
Definition: liblightify.h:106
lightify_node_get_blue
int lightify_node_get_blue(struct lightify_node *node)
Definition: node.c:230
lightify_group_get_name
const char * lightify_group_get_name(struct lightify_group *grp)
Definition: groups.c:117
lightify_group_request_rgbw
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
lightify_node_get_zoneadr
uint16_t lightify_node_get_zoneadr(struct lightify_node *node)
Definition: node.c:186
lightify_node::cct
int cct
Definition: node.c:67
LIGHTIFY_OFFLINE
Definition: liblightify.h:120
lightify_ctx::socket
int socket
Definition: context.h:87