This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
module.php
57 lines (43 loc) · 1.48 KB
/
module.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
<?
class Umrechnen extends IPSModule
{
public function Create()
{
//Never delete this line!
parent::Create();
$this->RegisterPropertyInteger("SourceVariable", 0);
$this->RegisterPropertyString("Formula", "\$Value/10*sin(30)*pi()");
$this->RegisterVariableFloat("Value", "Value", "", 0);
}
public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
//Create our trigger
if(IPS_VariableExists($this->ReadPropertyInteger("SourceVariable"))) {
$eid = @IPS_GetObjectIDByIdent("SourceTrigger", $this->InstanceID);
if($eid === false) {
$eid = IPS_CreateEvent(0 /* Trigger */);
IPS_SetParent($eid, $this->InstanceID);
IPS_SetIdent($eid, "SourceTrigger");
IPS_SetName($eid, "Trigger for #".$this->ReadPropertyInteger("SourceVariable"));
}
IPS_SetEventTrigger($eid, 0, $this->ReadPropertyInteger("SourceVariable"));
IPS_SetEventScript($eid, "SetValue(IPS_GetObjectIDByIdent(\"Value\", \$_IPS['TARGET']), UMR_Calculate(\$_IPS['TARGET'], \$_IPS['VALUE']));");
IPS_SetEventActive($eid, true);
}
}
/**
* This function will be available automatically after the module is imported with the module control.
* Using the custom prefix this function will be callable from PHP and JSON-RPC through:
*
* UMR_Calculate($id);
*
*/
public function Calculate(float $Value)
{
eval("\$Value = " . $this->ReadPropertyString("Formula") . ";");
return $Value;
}
}
?>