Skip to content

Commit

Permalink
Set input mode upfront for DHT sensors and 1-Wire buses too
Browse files Browse the repository at this point in the history
  • Loading branch information
vickash committed Sep 2, 2024
1 parent c0c2087 commit 67ff945
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/denko/one_wire/bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Bus
attr_reader :parasite_power

def after_initialize(options = {})
# Set input mode to force upfront pin validation.
self.mode = :input

super(options)
read_power_supply
end
Expand Down
3 changes: 3 additions & 0 deletions lib/denko/sensor/dht.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class DHT
include TemperatureHelper

def after_initialize(options={})
# Set input mode to force upfront pin validation.
self.mode = :input

# Avoid repeated memory allocation for callback data and state.
@reading = { temperature: nil, humidity: nil }
self.state = { temperature: nil, humidity: nil }
Expand Down

0 comments on commit 67ff945

Please sign in to comment.