denko 0.13.3 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,128 @@
1
+ module Denko
2
+ module Sensor
3
+ class SHT3X
4
+ include I2C::Peripheral
5
+ include Behaviors::Poller
6
+
7
+ RESET = 0x30A2
8
+ RESET_TIME = 0.002
9
+ HEATER_OFF = 0x3066
10
+ HEATER_ON = 0x306D
11
+ FETCH_DATA = 0xE000
12
+ REPEATABILITY = {
13
+ high: { lsb: 0x00, measurement_time: 0.016 },
14
+ medium: { lsb: 0x0B, measurement_time: 0.007 },
15
+ low: { lsb: 0x16, measurement_time: 0.005 },
16
+ }
17
+
18
+ # Unused
19
+ READ_STATUS_REGISTER = 0xF32D
20
+ CLEAR_STATUS_REGISTER = 0x3041
21
+ BREAK = 0x3093
22
+ ART = 0x2B32
23
+
24
+ def before_initialize(options={})
25
+ @i2c_address = 0x44
26
+ super(options)
27
+ end
28
+
29
+ def after_initialize(options={})
30
+ super(options)
31
+
32
+ # Avoid repeated memory allocation for callback data and state.
33
+ @reading = { temperature: nil, humidity: nil }
34
+ self.state = { temperature: nil, humidity: nil }
35
+
36
+ reset
37
+ self.repeatability = :high
38
+ end
39
+
40
+ def repeatability=(key)
41
+ raise ArgumentError, "invalid repeatability setting: #{key}" unless REPEATABILITY.keys.include? key
42
+ @measurement_lsb = REPEATABILITY[key][:lsb]
43
+ @measurement_time = REPEATABILITY[key][:measurement_time]
44
+ end
45
+
46
+ def _read
47
+ i2c_write [0x24, @measurement_lsb]
48
+ sleep(@measurement_time)
49
+ i2c_read(FETCH_DATA, 6)
50
+ end
51
+
52
+ def pre_callback_filter(bytes)
53
+ # Temperature is bytes 0 to 2: MSB, LSB, CRC
54
+ if calculate_crc(bytes[0..2]) == bytes[2]
55
+ t_raw = (bytes[0] << 8) | bytes[1]
56
+ @reading[:temperature] = (175 * t_raw / 65535.0) - 45
57
+ else
58
+ @reading[:temperature] = nil
59
+ end
60
+
61
+ # Humidity is bytes 3 to 5: MSB, LSB, CRC
62
+ if calculate_crc(bytes[3..5]) == bytes[5]
63
+ h_raw = (bytes[3] << 8) | bytes[4]
64
+ @reading[:humidity] = 100 * h_raw / 65535.0
65
+ else
66
+ @reading[:humidity] = nil
67
+ end
68
+
69
+ @reading
70
+ end
71
+
72
+ def update_state(reading)
73
+ @state_mutex.synchronize do
74
+ @state[:temperature] = reading[:temperature]
75
+ @state[:humidity] = reading[:humidity]
76
+ end
77
+ end
78
+
79
+ def reset
80
+ i2c_write [RESET]
81
+ sleep RESET_TIME
82
+ @heater_on = false
83
+ end
84
+
85
+ def heater_on?
86
+ @heater_on
87
+ end
88
+
89
+ def heater_off?
90
+ !@heater_on
91
+ end
92
+
93
+ def heater_on
94
+ i2c_write [HEATER_ON]
95
+ @heater_on = true
96
+ end
97
+
98
+ def heater_off
99
+ i2c_write [HEATER_OFF]
100
+ @heater_on = false
101
+ end
102
+
103
+ # CRC is same as AHT20 sensor. Copied from that file.
104
+ CRC_INITIAL_VALUE = 0xFF
105
+ CRC_POLYNOMIAL = 0x31
106
+ MSBIT_MASK = 0x80
107
+
108
+ def calculate_crc(bytes)
109
+ crc = CRC_INITIAL_VALUE
110
+
111
+ # Ignore last byte. That's the CRC value to compare with.
112
+ bytes.take(bytes.length - 1).each do |byte|
113
+ crc = crc ^ byte
114
+ 8.times do
115
+ if (crc & MSBIT_MASK) > 0
116
+ crc = (crc << 1) ^ CRC_POLYNOMIAL
117
+ else
118
+ crc = crc << 1
119
+ end
120
+ end
121
+ end
122
+
123
+ # Limit CRC size to 8 bits.
124
+ crc = crc & 0xFF
125
+ end
126
+ end
127
+ end
128
+ end
data/lib/denko/sensor.rb CHANGED
@@ -4,10 +4,16 @@ module Denko
4
4
  autoload :Humidity, "#{__dir__}/sensor/virtual"
5
5
  autoload :DHT, "#{__dir__}/sensor/dht"
6
6
  autoload :DS18B20, "#{__dir__}/sensor/ds18b20"
7
+ autoload :BMP180, "#{__dir__}/sensor/bmp180"
7
8
  autoload :BME280, "#{__dir__}/sensor/bme280"
9
+ autoload :BMP280, "#{__dir__}/sensor/bme280"
8
10
  autoload :HTU21D, "#{__dir__}/sensor/htu21d"
9
11
  autoload :HTU31D, "#{__dir__}/sensor/htu31d"
10
12
  autoload :AHT10, "#{__dir__}/sensor/aht"
11
13
  autoload :AHT20, "#{__dir__}/sensor/aht"
14
+ autoload :SHT3X, "#{__dir__}/sensor/sht3x"
15
+ autoload :QMP6988, "#{__dir__}/sensor/qmp6988"
16
+ autoload :RCWL9620, "#{__dir__}/sensor/rcwl9620"
17
+ autoload :GenericPIR, "#{__dir__}/sensor/generic_pir"
12
18
  end
13
19
  end
data/lib/denko/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Denko
2
- VERSION = "0.13.3"
2
+ VERSION = "0.13.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denko
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - vickash, Austinbv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-14 00:00:00.000000000 Z
11
+ date: 2023-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyserial
@@ -113,6 +113,7 @@ files:
113
113
  - bin/denko
114
114
  - build
115
115
  - denko.gemspec
116
+ - examples/advanced/m5_env.rb
116
117
  - examples/advanced/rotary_encoder_mac_volume.rb
117
118
  - examples/advanced/ssd1306_time_temp_rh.rb
118
119
  - examples/analog_io/ads1115.rb
@@ -120,6 +121,7 @@ files:
120
121
  - examples/analog_io/dac_loopback.rb
121
122
  - examples/analog_io/input.rb
122
123
  - examples/connection/tcp.rb
124
+ - examples/digital_io/button.rb
123
125
  - examples/digital_io/rotary_encoder.rb
124
126
  - examples/display/hd44780.png
125
127
  - examples/display/hd44780.rb
@@ -143,10 +145,16 @@ files:
143
145
  - examples/sensor/aht10.rb
144
146
  - examples/sensor/aht20.rb
145
147
  - examples/sensor/bme280.rb
148
+ - examples/sensor/bmp180.rb
146
149
  - examples/sensor/dht.rb
147
150
  - examples/sensor/ds18b20.rb
151
+ - examples/sensor/generic_pir.rb
148
152
  - examples/sensor/htu21d.rb
149
153
  - examples/sensor/htu31d.rb
154
+ - examples/sensor/neat_tph_readings.rb
155
+ - examples/sensor/qmp6988.rb
156
+ - examples/sensor/rcwl9620.rb
157
+ - examples/sensor/sht3x.rb
150
158
  - examples/spi/input_register.rb
151
159
  - examples/spi/output_register.rb
152
160
  - examples/spi/ssd_through_register.rb
@@ -247,10 +255,15 @@ files:
247
255
  - lib/denko/sensor.rb
248
256
  - lib/denko/sensor/aht.rb
249
257
  - lib/denko/sensor/bme280.rb
258
+ - lib/denko/sensor/bmp180.rb
250
259
  - lib/denko/sensor/dht.rb
251
260
  - lib/denko/sensor/ds18b20.rb
261
+ - lib/denko/sensor/generic_pir.rb
252
262
  - lib/denko/sensor/htu21d.rb
253
263
  - lib/denko/sensor/htu31d.rb
264
+ - lib/denko/sensor/qmp6988.rb
265
+ - lib/denko/sensor/rcwl9620.rb
266
+ - lib/denko/sensor/sht3x.rb
254
267
  - lib/denko/sensor/virtual.rb
255
268
  - lib/denko/spi.rb
256
269
  - lib/denko/spi/base_register.rb