Updated php-binding to use the new api in telldus-core version 2.0
This commit is contained in:
parent
ea7989bdef
commit
8c8288333f
4 changed files with 53 additions and 46 deletions
|
@ -5,7 +5,7 @@ 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"
|
||||
SEARCH_FOR="/include/telldus-core.h"
|
||||
if test -r $PHP_TELLDUS/; then # path given as parameter
|
||||
TELLDUS_DIR=$PHP_TELLDUS
|
||||
else # search default path list
|
||||
|
@ -24,8 +24,8 @@ if test "$PHP_TELLDUS" = "yes"; then
|
|||
# --enable-telldus -> add include path
|
||||
PHP_ADD_INCLUDE($TELLDUS_DIR/include)
|
||||
# --enable-telldus -> check for lib and symbol presence
|
||||
LIBNAME=tellusbd101
|
||||
LIBSYMBOL=devGetNumberOfDevices
|
||||
LIBNAME=telldus-core
|
||||
LIBSYMBOL=tdGetNumberOfDevices
|
||||
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
|
||||
[
|
||||
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TELLDUS_DIR/lib, TELLDUS_SHARED_LIBADD)
|
||||
|
@ -39,3 +39,4 @@ if test "$PHP_TELLDUS" = "yes"; then
|
|||
|
||||
PHP_NEW_EXTENSION(telldus, telldus.c, $ext_shared)
|
||||
fi
|
||||
|
||||
|
|
|
@ -5,27 +5,30 @@ if(!extension_loaded('telldus')) {
|
|||
dl('telldus.' . PHP_SHLIB_SUFFIX);
|
||||
}
|
||||
|
||||
$devices = telldus_get_number_of_devices();
|
||||
$devices = tdGetNumberOfDevices();
|
||||
printf("Devices: %d\n", $devices);
|
||||
|
||||
$allMethods = TELLDUS_TURNON | TELLDUS_TURNOFF | TELLDUS_BELL | TELLDUS_DIM;
|
||||
|
||||
for( $i = 0; $i < $devices; ++$i ) {
|
||||
$id = telldus_get_device_id( $i );
|
||||
$name = utf8_encode(telldus_get_name( $id ));
|
||||
$id = tdGetDeviceId( $i );
|
||||
$name = utf8_encode(tdGetName( $id ));
|
||||
printf("%s - %s\n", $id, $name);
|
||||
|
||||
$methods = telldus_dev_methods( $id );
|
||||
$methods = tdMethods( $id, $allMethods );
|
||||
if ($methods & TELLDUS_TURNON) {
|
||||
echo " * TurnOn\n";
|
||||
telldus_dev_turn_on( $id );
|
||||
tdTurnOn( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_TURNOFF) {
|
||||
echo " * TurnOff\n";
|
||||
telldus_dev_turn_off( $id );
|
||||
tdTurnOff( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_BELL) {
|
||||
echo " * Bell\n";
|
||||
telldus_dev_bell( $id );
|
||||
tdBell( $id );
|
||||
sleep(1);
|
||||
}
|
||||
if ($methods & TELLDUS_TOGGLE) {
|
||||
|
@ -33,7 +36,8 @@ for( $i = 0; $i < $devices; ++$i ) {
|
|||
}
|
||||
if ($methods & TELLDUS_DIM) {
|
||||
echo " * Dim\n";
|
||||
telldus_dev_dim( $id, 128 );
|
||||
tdDim( $id, 128 );
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
#ifndef PHP_TELLDUS_H
|
||||
#define PHP_TELLDUS_H 1
|
||||
|
||||
#define PHP_TELLDUS_VERSION "1.2.2"
|
||||
#define PHP_TELLDUS_VERSION "2.0.0"
|
||||
#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(tdTurnOn);
|
||||
PHP_FUNCTION(tdTurnOff);
|
||||
PHP_FUNCTION(tdBell);
|
||||
PHP_FUNCTION(tdDim);
|
||||
PHP_FUNCTION(tdMethods);
|
||||
|
||||
PHP_FUNCTION(telldus_get_number_of_devices);
|
||||
PHP_FUNCTION(telldus_get_device_id);
|
||||
PHP_FUNCTION(telldus_get_name);
|
||||
PHP_FUNCTION(tdGetNumberOfDevices);
|
||||
PHP_FUNCTION(tdGetDeviceId);
|
||||
PHP_FUNCTION(tdGetName);
|
||||
|
||||
extern zend_module_entry telldus_module_entry;
|
||||
#define phpext_telldus_ptr &telldus_module_entry
|
||||
|
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
#include "php.h"
|
||||
#include "php_telldus.h"
|
||||
#include "TellUsbD101.h"
|
||||
#include <telldus-core.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(tdTurnOn, NULL)
|
||||
PHP_FE(tdTurnOff, NULL)
|
||||
PHP_FE(tdBell, NULL)
|
||||
PHP_FE(tdDim, NULL)
|
||||
PHP_FE(tdMethods, NULL)
|
||||
|
||||
PHP_FE(telldus_get_number_of_devices, NULL)
|
||||
PHP_FE(telldus_get_device_id, NULL)
|
||||
PHP_FE(telldus_get_name, NULL)
|
||||
PHP_FE(tdGetNumberOfDevices, NULL)
|
||||
PHP_FE(tdGetDeviceId, NULL)
|
||||
PHP_FE(tdGetName, NULL)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -63,7 +63,7 @@ PHP_MSHUTDOWN_FUNCTION(telldus)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_dev_turn_on)
|
||||
PHP_FUNCTION(tdTurnOn)
|
||||
{
|
||||
long id;
|
||||
|
||||
|
@ -71,10 +71,10 @@ PHP_FUNCTION(telldus_dev_turn_on)
|
|||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( devTurnOn( id ) );
|
||||
RETURN_BOOL( tdTurnOn( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_dev_turn_off)
|
||||
PHP_FUNCTION(tdTurnOff)
|
||||
{
|
||||
long id;
|
||||
|
||||
|
@ -82,10 +82,10 @@ PHP_FUNCTION(telldus_dev_turn_off)
|
|||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( devTurnOff( id ) );
|
||||
RETURN_BOOL( tdTurnOff( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_dev_bell)
|
||||
PHP_FUNCTION(tdBell)
|
||||
{
|
||||
long id;
|
||||
|
||||
|
@ -93,10 +93,10 @@ PHP_FUNCTION(telldus_dev_bell)
|
|||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( devBell( id ) );
|
||||
RETURN_BOOL( tdBell( id ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_dev_dim)
|
||||
PHP_FUNCTION(tdDim)
|
||||
{
|
||||
long id;
|
||||
long level;
|
||||
|
@ -108,30 +108,31 @@ PHP_FUNCTION(telldus_dev_dim)
|
|||
RETURN_NULL();
|
||||
}
|
||||
|
||||
RETURN_BOOL( devDim( id, level ) );
|
||||
RETURN_BOOL( tdDim( id, level ) );
|
||||
}
|
||||
|
||||
|
||||
PHP_FUNCTION(telldus_dev_methods)
|
||||
PHP_FUNCTION(tdMethods)
|
||||
{
|
||||
long id;
|
||||
long supportedMethods;
|
||||
long methods;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &id, &supportedMethods) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
methods = devMethods( id );
|
||||
methods = tdMethods( id, supportedMethods );
|
||||
RETURN_LONG(methods);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_get_number_of_devices)
|
||||
PHP_FUNCTION(tdGetNumberOfDevices)
|
||||
{
|
||||
int nbr = devGetNumberOfDevices();
|
||||
int nbr = tdGetNumberOfDevices();
|
||||
RETURN_LONG(nbr);
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_get_device_id)
|
||||
PHP_FUNCTION(tdGetDeviceId)
|
||||
{
|
||||
long index;
|
||||
|
||||
|
@ -139,10 +140,10 @@ PHP_FUNCTION(telldus_get_device_id)
|
|||
RETURN_LONG(0);
|
||||
}
|
||||
|
||||
RETURN_LONG( devGetDeviceId( index ) );
|
||||
RETURN_LONG( tdGetDeviceId( index ) );
|
||||
}
|
||||
|
||||
PHP_FUNCTION(telldus_get_name)
|
||||
PHP_FUNCTION(tdGetName)
|
||||
{
|
||||
long id;
|
||||
char *name;
|
||||
|
@ -151,6 +152,7 @@ PHP_FUNCTION(telldus_get_name)
|
|||
RETURN_NULL();
|
||||
}
|
||||
|
||||
name = devGetName( id );
|
||||
name = tdGetName( id );
|
||||
RETURN_STRING( name, 1 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue