-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
.idea/ | ||
.phpunit.* | ||
.php_cs.cache | ||
.php_cs.cache | ||
.php-cs-fixer.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,119 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
class Schleppzeiger extends IPSModule | ||
class Schleppzeiger extends IPSModule | ||
{ | ||
public function Create() | ||
{ | ||
public function Create() | ||
{ | ||
//Never delete this line! | ||
parent::Create(); | ||
|
||
$this->RegisterPropertyInteger('Target', 0); | ||
$this->RegisterPropertyInteger('Interval', 0); | ||
$this->RegisterPropertyString('Option', 'Maximum'); | ||
|
||
if (!IPS_VariableProfileExists('SZ.Reset')) { | ||
IPS_CreateVariableProfile('SZ.Reset', VARIABLETYPE_BOOLEAN); | ||
IPS_SetVariableProfileAssociation('SZ.Reset', true, $this->Translate('Reset'), '', 0x00FF00); | ||
} | ||
|
||
$this->RegisterVariableFloat('TrailingPointer', $this->Translate('Trailing Pointer'), '', 0); | ||
$this->RegisterVariableBoolean('Reset', $this->Translate('Reset'), 'SZ.Reset', 1); | ||
$this->EnableAction('Reset'); | ||
//Never delete this line! | ||
parent::Create(); | ||
|
||
$this->RegisterTimer('ResetTimer', 0, 'SZ_Reset($_IPS[\'TARGET\']);'); | ||
} | ||
$this->RegisterPropertyInteger('Target', 0); | ||
$this->RegisterPropertyInteger('Interval', 0); | ||
$this->RegisterPropertyString('Option', 'Maximum'); | ||
|
||
public function Destroy() | ||
{ | ||
//Never delete this line! | ||
parent::Destroy(); | ||
if (!IPS_VariableProfileExists('SZ.Reset')) { | ||
IPS_CreateVariableProfile('SZ.Reset', VARIABLETYPE_BOOLEAN); | ||
IPS_SetVariableProfileAssociation('SZ.Reset', true, $this->Translate('Reset'), '', 0x00FF00); | ||
} | ||
|
||
public function ApplyChanges() | ||
{ | ||
//Never delete this line! | ||
parent::ApplyChanges(); | ||
$this->RegisterVariableFloat('TrailingPointer', $this->Translate('Trailing Pointer'), '', 0); | ||
$this->RegisterVariableBoolean('Reset', $this->Translate('Reset'), 'SZ.Reset', 1); | ||
$this->EnableAction('Reset'); | ||
|
||
$targetID = $this->ReadPropertyInteger('Target'); | ||
if (!IPS_VariableExists($targetID)) { | ||
$this->SetStatus(200); //Target Variable is not valid | ||
return; | ||
} | ||
$this->SetStatus(102); | ||
|
||
//Reference | ||
//Unregister | ||
foreach ($this->GetReferenceList() as $id) { | ||
$this->UnregisterReference($id); | ||
} | ||
$this->RegisterTimer('ResetTimer', 0, 'SZ_Reset($_IPS[\'TARGET\']);'); | ||
} | ||
|
||
//Register | ||
$this->RegisterReference($targetID); | ||
public function Destroy() | ||
{ | ||
//Never delete this line! | ||
parent::Destroy(); | ||
} | ||
|
||
//Messages | ||
//Unregister all messages | ||
foreach ($this->GetMessageList() as $senderID => $messages) { | ||
foreach ($messages as $message) { | ||
$this->UnregisterMessage($senderID, $message); | ||
} | ||
} | ||
public function ApplyChanges() | ||
{ | ||
//Never delete this line! | ||
parent::ApplyChanges(); | ||
|
||
//Register necessary messages | ||
$this->RegisterMessage($this->GetIDForIdent('Reset'), VM_UPDATE); | ||
$this->RegisterMessage($targetID, VM_UPDATE); | ||
$targetID = $this->ReadPropertyInteger('Target'); | ||
if (!IPS_VariableExists($targetID)) { | ||
$this->SetStatus(200); //Target Variable is not valid | ||
return; | ||
} | ||
$this->SetStatus(102); | ||
|
||
//Set TimerInterval | ||
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000); | ||
//Reference | ||
//Unregister | ||
foreach ($this->GetReferenceList() as $id) { | ||
$this->UnregisterReference($id); | ||
} | ||
|
||
public function RequestAction($Ident, $Value) | ||
{ | ||
switch ($Ident) { | ||
case 'Reset': | ||
$this->Reset(); | ||
break; | ||
default: | ||
$this->SetValue($Ident, $Value); | ||
break; | ||
//Register | ||
$this->RegisterReference($targetID); | ||
|
||
//Messages | ||
//Unregister all messages | ||
foreach ($this->GetMessageList() as $senderID => $messages) { | ||
foreach ($messages as $message) { | ||
$this->UnregisterMessage($senderID, $message); | ||
} | ||
} | ||
|
||
public function Reset() | ||
{ | ||
$this->SetValue('TrailingPointer', GetValue($this->ReadPropertyInteger('Target'))); | ||
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000); | ||
//Register necessary messages | ||
$this->RegisterMessage($this->GetIDForIdent('Reset'), VM_UPDATE); | ||
$this->RegisterMessage($targetID, VM_UPDATE); | ||
|
||
//Set TimerInterval | ||
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000); | ||
} | ||
|
||
public function RequestAction($Ident, $Value) | ||
{ | ||
switch ($Ident) { | ||
case 'Reset': | ||
$this->Reset(); | ||
break; | ||
default: | ||
$this->SetValue($Ident, $Value); | ||
break; | ||
} | ||
} | ||
|
||
public function MessageSink($timestamp, $sendId, $messageID, $data) | ||
{ | ||
if ($messageID == VM_UPDATE) { | ||
if ($sendId == $this->GetIDForIdent('Reset')) { | ||
$this->Reset(); | ||
} elseif ($sendId == $this->ReadPropertyInteger('Target')) { | ||
$this->trailingTarget($data[0]); | ||
} | ||
public function Reset() | ||
{ | ||
$this->SetValue('TrailingPointer', GetValue($this->ReadPropertyInteger('Target'))); | ||
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000); | ||
} | ||
|
||
public function MessageSink($timestamp, $sendId, $messageID, $data) | ||
{ | ||
if ($messageID == VM_UPDATE) { | ||
if ($sendId == $this->GetIDForIdent('Reset')) { | ||
$this->Reset(); | ||
} elseif ($sendId == $this->ReadPropertyInteger('Target')) { | ||
$this->trailingTarget($data[0]); | ||
} | ||
} | ||
} | ||
|
||
private function trailingTarget($value) | ||
{ | ||
$currentValue = $this->GetValue('TrailingPointer'); | ||
|
||
switch ($this->ReadPropertyString('Option')) { | ||
case 'Maximum': | ||
if ($value > $currentValue) { | ||
$this->SetValue('TrailingPointer', $value); | ||
} | ||
break; | ||
case 'Minimum': | ||
if ($value < $currentValue) { | ||
$this->SetValue('TrailingPointer', $value); | ||
} | ||
break; | ||
default: | ||
$this->SendDebug('Not Supported', 'Current Option is not supported', 0); | ||
break; | ||
} | ||
private function trailingTarget($value) | ||
{ | ||
$currentValue = $this->GetValue('TrailingPointer'); | ||
|
||
switch ($this->ReadPropertyString('Option')) { | ||
case 'Maximum': | ||
if ($value > $currentValue) { | ||
$this->SetValue('TrailingPointer', $value); | ||
} | ||
break; | ||
case 'Minimum': | ||
if ($value < $currentValue) { | ||
$this->SetValue('TrailingPointer', $value); | ||
} | ||
break; | ||
default: | ||
$this->SendDebug('Not Supported', 'Current Option is not supported', 0); | ||
break; | ||
} | ||
} | ||
} | ||
} |