diff --git a/CC100_HW/module.php b/CC100_HW/module.php index c328c57..9c44949 100644 --- a/CC100_HW/module.php +++ b/CC100_HW/module.php @@ -16,6 +16,17 @@ class CC100_HW extends IPSModule $this->RegisterVariableBoolean('Bit2', 'DO 2', '~Switch', 2); $this->RegisterVariableBoolean('Bit3', 'DO 3', '~Switch', 3); $this->RegisterVariableBoolean('Bit4', 'DO 4', '~Switch', 4); + + $this->RegisterVariableBoolean('DI1', 'DI1'); + $this->RegisterVariableBoolean('DI2', 'DI2'); + $this->RegisterVariableBoolean('DI3', 'DI3'); + $this->RegisterVariableBoolean('DI4', 'DI4'); + $this->RegisterVariableBoolean('DI5', 'DI5'); + $this->RegisterVariableBoolean('DI6', 'DI6'); + $this->RegisterVariableBoolean('DI7', 'DI7'); + $this->RegisterVariableBoolean('DI8', 'DI8'); + + $this->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5); $this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6); $this->EnableAction('Bit1'); @@ -55,8 +66,59 @@ class CC100_HW extends IPSModule $this->TryWriteFile($starttime); } + + private function readAndConvertToBools($filePath) +{ + // Überprüfen, ob die Datei existiert und lesbar ist + if (!file_exists($filePath) || !is_readable($filePath)) { + break; N + } + + // Inhalt der Datei auslesen + $content = file_get_contents($filePath); + + if ($content === false) { + throw new Exception("Fehler beim Lesen der Datei $filePath."); + } + + // Die gelesene Zahl bereinigen (Leerzeichen oder Zeilenumbrüche entfernen) + $number = trim($content); + + // Sicherstellen, dass die Zahl gültig ist + if (!ctype_digit($number)) { + throw new Exception("Der Inhalt der Datei ist keine gültige Zahl: $number"); + } + + // Die Zahl in einen Integer umwandeln + $intValue = (int)$number; + + // Sicherstellen, dass die Zahl zwischen 0 und 255 liegt + if ($intValue < 0 || $intValue > 255) { + throw new Exception("Die Zahl muss zwischen 0 und 255 liegen: $intValue"); + } + + // In einen 8-Bit-Binärstring umwandeln + $binaryString = str_pad(decbin($intValue), 8, "0", STR_PAD_LEFT); + + // Binärwerte in ein Array von booleschen Werten umwandeln + $boolValues = array_map(fn($bit) => $bit === "1", str_split($binaryString)); + + $this->SetValue("DI1", $boolValues[0]); + $this->SetValue("DI2", $boolValues[1]); + $this->SetValue("DI3", $boolValues[2]); + $this->SetValue("DI4", $boolValues[3]); + $this->SetValue("DI5", $boolValues[4]); + $this->SetValue("DI6", $boolValues[5]); + $this->SetValue("DI7", $boolValues[6]); + $this->SetValue("DI8", $boolValues[7]); + return $boolValues; +} + + private function TryWriteFile($starttime) { + $this->readAndConvertToBools("/sys/devices/platform/soc/44009000.spi/spi_master/spi0/spi0.0/din"); + $currentTime = microtime(true) * 1000; if (($currentTime - $starttime) <= $this->maxTime) { $file = $this->ReadPropertyString('FilePath'); diff --git a/library.json b/library.json index feb1b6d..005d01b 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "0.151", + "version": "0.152", "build": 0, "date": 0 } \ No newline at end of file