diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-11-21 03:51:37 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-11-21 03:51:37 +0300 |
commit | 35eec7f8126801a02008d405624927099ca53e5e (patch) | |
tree | 6bf89eaeb7674866b9f9918d4e22511d68481bd1 /localwebsite/classes | |
parent | 80bca2085f1cc177ea5060b6f1f23cab19e9f410 (diff) |
lws: fix for malfunctioning si7021 sensor
Diffstat (limited to 'localwebsite/classes')
-rw-r--r-- | localwebsite/classes/TemphumdClient.php (renamed from localwebsite/classes/Si7021dClient.php) | 14 | ||||
-rw-r--r-- | localwebsite/classes/config.php | 3 |
2 files changed, 15 insertions, 2 deletions
diff --git a/localwebsite/classes/Si7021dClient.php b/localwebsite/classes/TemphumdClient.php index b976448..07e5a3e 100644 --- a/localwebsite/classes/Si7021dClient.php +++ b/localwebsite/classes/TemphumdClient.php @@ -1,17 +1,19 @@ <?php -class Si7021dClient extends MySimpleSocketClient { +class TemphumdClient extends MySimpleSocketClient { public string $name; public float $temp; public float $humidity; + public ?int $flags; /** * @throws Exception */ - public function __construct(string $host, int $port, string $name) { + public function __construct(string $host, int $port, string $name, ?int $flags = null) { parent::__construct($host, $port); $this->name = $name; + $this->flags = $flags; socket_set_timeout($this->sock, 3); } @@ -28,4 +30,12 @@ class Si7021dClient extends MySimpleSocketClient { $this->humidity = $hum; } + public function hasTemperature(): bool { + return ($this->flags & config::TEMPHUMD_NO_TEMP) == 0; + } + + public function hasHumidity(): bool { + return ($this->flags & config::TEMPHUMD_NO_HUM) == 0; + } + }
\ No newline at end of file diff --git a/localwebsite/classes/config.php b/localwebsite/classes/config.php index 87ecf1c..927321e 100644 --- a/localwebsite/classes/config.php +++ b/localwebsite/classes/config.php @@ -2,6 +2,9 @@ class config { + const TEMPHUMD_NO_TEMP = 1 << 0; + const TEMPHUMD_NO_HUM = 1 << 1; + public static function get(string $key) { global $config; return is_callable($config[$key]) ? $config[$key]() : $config[$key]; |