-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.php
66 lines (44 loc) · 1.36 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* @author Petter Kjelkenes <[email protected]>
* @license LGPL
*/
// Try running this in your browser.. Try adding some sleep(4) functions on some lines.
// Remember to change "C:\ahsdk\bin\ahcmd.exe" to where you have installed the X10 SDK!
// Include the library
include 'bootstrap.php';
// Create the object
$x10 = new X10('C:\Program Files (x86)\AHSDK\bin\ahcmd.exe');
/**
* Add the first device, this can be our ceiling lights.
*/
// Add all devices you have ( codes )
$x10->addPowerDevice('a1');
// Only allow certain commands.( This is recommended but not required ).
// Forexample, you don't want to dim appliance modules.
// To see what features is available, you can: print_r(X10Device::getFeatures());
$x10->dev('a1')->setAllowedFeatures(X10Device::FG_ON_OFF | X10Device::FG_DIM_BRIGHT);
// Turn 'a1' off.
$x10->dev('a1')->off();
// Turn 'a1' on!
$x10->dev('a1')->on();
// Dim the device.
$x10->dev('a1')->dim(50);
// Extended code.
$x10->dev('a1')->extendedCode('A1', '0F');
/**
* Add the 2th device, this can be our TV.
*/
// Now add appliance module for the TV.
$x10->addPowerDevice('a2')->setAllowedFeatures(X10Device::FG_ON_OFF);
$a2 = $x10->dev('a2');
// Turn TV on.
$a2->on();
// and TV off.
$a2->off();
// This is NOT allowed.
try{
$a2->dim(50);
}catch(\Exception $e){
echo "This is a correct exception: {$e->getMessage()}";
}