Added php-bindings
This commit is contained in:
parent
d6ee193ab4
commit
366871fc01
4 changed files with 260 additions and 0 deletions
41
bindings/php/config.m4
Normal file
41
bindings/php/config.m4
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
PHP_ARG_ENABLE(telldus, whether to enable Telldus TellStick support,
|
||||||
|
[ --enable-telldus Enable Telldus TellStick support])
|
||||||
|
|
||||||
|
if test "$PHP_TELLDUS" = "yes"; then
|
||||||
|
AC_DEFINE(HAVE_TELLDUS, 1, [Whether you have Telldus TellStick])
|
||||||
|
|
||||||
|
SEARCH_PATH="/usr/local /usr"
|
||||||
|
SEARCH_FOR="/include/TellUsbD101.h"
|
||||||
|
if test -r $PHP_TELLDUS/; then # path given as parameter
|
||||||
|
TELLDUS_DIR=$PHP_TELLDUS
|
||||||
|
else # search default path list
|
||||||
|
AC_MSG_CHECKING([for telldus files in default path])
|
||||||
|
for i in $SEARCH_PATH ; do
|
||||||
|
if test -r $i/$SEARCH_FOR; then
|
||||||
|
TELLDUS_DIR=$i
|
||||||
|
AC_MSG_RESULT(found in $i)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if test -z "$TELLDUS_DIR"; then
|
||||||
|
AC_MSG_RESULT([not found])
|
||||||
|
AC_MSG_ERROR([Please reinstall the telldus-core distribution])
|
||||||
|
fi
|
||||||
|
# --enable-telldus -> add include path
|
||||||
|
PHP_ADD_INCLUDE($TELLDUS_DIR/include)
|
||||||
|
# --enable-telldus -> check for lib and symbol presence
|
||||||
|
LIBNAME=tellusbd101
|
||||||
|
LIBSYMBOL=devGetNumberOfDevices
|
||||||
|
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
|
||||||
|
[
|
||||||
|
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TELLDUS_DIR/lib, TELLDUS_SHARED_LIBADD)
|
||||||
|
AC_DEFINE(HAVE_TELLDUSLIB,1,[ ])
|
||||||
|
],[
|
||||||
|
AC_MSG_ERROR([wrong telldus lib version or lib not found])
|
||||||
|
],[
|
||||||
|
-L$TELLDUS_DIR/lib -lm
|
||||||
|
])
|
||||||
|
PHP_SUBST(TELLDUS_SHARED_LIBADD)
|
||||||
|
|
||||||
|
PHP_NEW_EXTENSION(telldus, telldus.c, $ext_shared)
|
||||||
|
fi
|
39
bindings/php/example/example.php
Normal file
39
bindings/php/example/example.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
if(!extension_loaded('telldus')) {
|
||||||
|
dl('telldus.' . PHP_SHLIB_SUFFIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
$devices = telldus_get_number_of_devices();
|
||||||
|
|
||||||
|
for( $i = 0; $i < $devices; ++$i ) {
|
||||||
|
$id = telldus_get_device_id( $i );
|
||||||
|
$name = utf8_encode(telldus_get_name( $id ));
|
||||||
|
printf("%s - %s\n", $id, $name);
|
||||||
|
|
||||||
|
$methods = telldus_dev_methods( $id );
|
||||||
|
if ($methods & TELLDUS_TURNON) {
|
||||||
|
echo " * TurnOn\n";
|
||||||
|
telldus_dev_turn_on( $id );
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
if ($methods & TELLDUS_TURNOFF) {
|
||||||
|
echo " * TurnOff\n";
|
||||||
|
telldus_dev_turn_off( $id );
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
if ($methods & TELLDUS_BELL) {
|
||||||
|
echo " * Bell\n";
|
||||||
|
telldus_dev_bell( $id );
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
if ($methods & TELLDUS_TOGGLE) {
|
||||||
|
echo " * Toggle\n";
|
||||||
|
}
|
||||||
|
if ($methods & TELLDUS_DIM) {
|
||||||
|
echo " * Dim\n";
|
||||||
|
telldus_dev_dim( $id, 128 );
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
24
bindings/php/php_telldus.h
Normal file
24
bindings/php/php_telldus.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef PHP_TELLDUS_H
|
||||||
|
#define PHP_TELLDUS_H 1
|
||||||
|
|
||||||
|
#define PHP_TELLDUS_VERSION "1.2.2"
|
||||||
|
#define PHP_TELLDUS_EXTNAME "telldus"
|
||||||
|
|
||||||
|
PHP_MINIT_FUNCTION(telldus);
|
||||||
|
PHP_MSHUTDOWN_FUNCTION(telldus);
|
||||||
|
PHP_RINIT_FUNCTION(telldus);
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_turn_on);
|
||||||
|
PHP_FUNCTION(telldus_dev_turn_off);
|
||||||
|
PHP_FUNCTION(telldus_dev_bell);
|
||||||
|
PHP_FUNCTION(telldus_dev_dim);
|
||||||
|
PHP_FUNCTION(telldus_dev_methods);
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_get_number_of_devices);
|
||||||
|
PHP_FUNCTION(telldus_get_device_id);
|
||||||
|
PHP_FUNCTION(telldus_get_name);
|
||||||
|
|
||||||
|
extern zend_module_entry telldus_module_entry;
|
||||||
|
#define phpext_telldus_ptr &telldus_module_entry
|
||||||
|
|
||||||
|
#endif
|
156
bindings/php/telldus.c
Normal file
156
bindings/php/telldus.c
Normal file
|
@ -0,0 +1,156 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "php.h"
|
||||||
|
#include "php_telldus.h"
|
||||||
|
#include "TellUsbD101.h"
|
||||||
|
|
||||||
|
|
||||||
|
static function_entry telldus_functions[] = {
|
||||||
|
PHP_FE(telldus_dev_turn_on, NULL)
|
||||||
|
PHP_FE(telldus_dev_turn_off, NULL)
|
||||||
|
PHP_FE(telldus_dev_bell, NULL)
|
||||||
|
PHP_FE(telldus_dev_dim, NULL)
|
||||||
|
PHP_FE(telldus_dev_methods, NULL)
|
||||||
|
|
||||||
|
PHP_FE(telldus_get_number_of_devices, NULL)
|
||||||
|
PHP_FE(telldus_get_device_id, NULL)
|
||||||
|
PHP_FE(telldus_get_name, NULL)
|
||||||
|
{NULL, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
zend_module_entry telldus_module_entry = {
|
||||||
|
#if ZEND_MODULE_API_NO >= 20010901
|
||||||
|
STANDARD_MODULE_HEADER,
|
||||||
|
#endif
|
||||||
|
PHP_TELLDUS_EXTNAME,
|
||||||
|
telldus_functions,
|
||||||
|
PHP_MINIT(telldus),
|
||||||
|
PHP_MSHUTDOWN(telldus),
|
||||||
|
PHP_RINIT(telldus),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
#if ZEND_MODULE_API_NO >= 20010901
|
||||||
|
PHP_TELLDUS_VERSION,
|
||||||
|
#endif
|
||||||
|
STANDARD_MODULE_PROPERTIES
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef COMPILE_DL_TELLDUS
|
||||||
|
ZEND_GET_MODULE(telldus)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
PHP_RINIT_FUNCTION(telldus)
|
||||||
|
{
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_MINIT_FUNCTION(telldus)
|
||||||
|
{
|
||||||
|
REGISTER_LONG_CONSTANT("TELLDUS_TURNON", TELLSTICK_TURNON, CONST_CS | CONST_PERSISTENT);
|
||||||
|
REGISTER_LONG_CONSTANT("TELLDUS_TURNOFF", TELLSTICK_TURNOFF, CONST_CS | CONST_PERSISTENT);
|
||||||
|
REGISTER_LONG_CONSTANT("TELLDUS_BELL", TELLSTICK_BELL, CONST_CS | CONST_PERSISTENT);
|
||||||
|
REGISTER_LONG_CONSTANT("TELLDUS_TOGGLE", TELLSTICK_TOGGLE, CONST_CS | CONST_PERSISTENT);
|
||||||
|
REGISTER_LONG_CONSTANT("TELLDUS_DIM", TELLSTICK_DIM, CONST_CS | CONST_PERSISTENT);
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_MSHUTDOWN_FUNCTION(telldus)
|
||||||
|
{
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_turn_on)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_BOOL( devTurnOn( id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_turn_off)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_BOOL( devTurnOff( id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_bell)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_BOOL( devBell( id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_dim)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
long level;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &level) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
if (level < 0 || level > 255) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_BOOL( devDim( id, level ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_dev_methods)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
long methods;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
methods = devMethods( id );
|
||||||
|
RETURN_LONG(methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_get_number_of_devices)
|
||||||
|
{
|
||||||
|
int nbr = devGetNumberOfDevices();
|
||||||
|
RETURN_LONG(nbr);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_get_device_id)
|
||||||
|
{
|
||||||
|
long index;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
|
||||||
|
RETURN_LONG(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_LONG( devGetDeviceId( index ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(telldus_get_name)
|
||||||
|
{
|
||||||
|
long id;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||||
|
RETURN_NULL();
|
||||||
|
}
|
||||||
|
|
||||||
|
name = devGetName( id );
|
||||||
|
RETURN_STRING( name, 1 );
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue