lgpio 0.1.11 → 0.1.12
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/examples/dht.rb +1 -1
- data/ext/lgpio/lgpio.c +7 -4
- data/lib/lgpio/hardware_pwm.rb +6 -8
- data/lib/lgpio/infrared.rb +11 -1
- data/lib/lgpio/one_wire.rb +6 -4
- data/lib/lgpio/version.rb +1 -1
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3b3d476891ddae4745580531d10dc7c58de9ac0f7c93f75ad2743597db0fd74
|
4
|
+
data.tar.gz: df0d8c8b767115c07c1d9174cb9cf69797a04278035fb6fbc41be68b4877a585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: affc87dba05d69d20589acbcffb3988018a5f2759516d9b55a452dc8baa7c00de4c1cc61bc511590503063a06b1a41efadcf589dfcc628a53704cde9eeafe423
|
7
|
+
data.tar.gz: 2ea4c0c0f9ba1f602dcaff830543fd69ca6e1c6c0555fec0961362be3e51482a38210158776e94e54a445c9a17a29198a6d541ade0cdbc8863e80bd5112372e6
|
data/Gemfile
ADDED
data/examples/dht.rb
CHANGED
@@ -13,7 +13,7 @@ chip_handle = LGPIO.chip_open(GPIO_CHIP)
|
|
13
13
|
# Maximum number of pulses to read
|
14
14
|
# Timeout in milliseconds
|
15
15
|
#
|
16
|
-
data = LGPIO.gpio_read_pulses_us(chip_handle, DHT_PIN,
|
16
|
+
data = LGPIO.gpio_read_pulses_us(chip_handle, DHT_PIN, 10_000, 0, 84, 100)
|
17
17
|
|
18
18
|
# Handle errors.
|
19
19
|
raise "error: DHT sensor not connected" unless data
|
data/ext/lgpio/lgpio.c
CHANGED
@@ -438,8 +438,8 @@ static VALUE spi_ws2812_write(VALUE self, VALUE handle, VALUE pixelArray){
|
|
438
438
|
Check_Type(currentByte_rb, T_FIXNUM);
|
439
439
|
currentByte = NUM2CHR(currentByte_rb);
|
440
440
|
|
441
|
-
for (int
|
442
|
-
currentBit = (currentByte & (1 <<
|
441
|
+
for (int j=7; j>=0; j--) {
|
442
|
+
currentBit = (currentByte & (1 << j));
|
443
443
|
temp = temp << 3;
|
444
444
|
temp = (currentBit == 0) ? (temp | 0b100) : (temp | 0b110);
|
445
445
|
}
|
@@ -605,6 +605,7 @@ static VALUE one_wire_reset(VALUE self, VALUE rbHandle, VALUE rbGPIO) {
|
|
605
605
|
int handle = NUM2INT(rbHandle);
|
606
606
|
int gpio = NUM2INT(rbGPIO);
|
607
607
|
struct timespec start;
|
608
|
+
struct timespec now;
|
608
609
|
uint8_t presence = 1;
|
609
610
|
|
610
611
|
// Hold low for 500us to reset, then go high.
|
@@ -615,8 +616,10 @@ static VALUE one_wire_reset(VALUE self, VALUE rbHandle, VALUE rbGPIO) {
|
|
615
616
|
|
616
617
|
// Poll for 250us. If a device pulls the line low, return 0 (device present).
|
617
618
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
618
|
-
|
619
|
-
|
619
|
+
now = start;
|
620
|
+
while(nanoDiff(&now, &start) < 250000){
|
621
|
+
if (digitalRead(gpio) == 0) presence = 0;
|
622
|
+
clock_gettime(CLOCK_MONOTONIC, &now);
|
620
623
|
}
|
621
624
|
|
622
625
|
return UINT2NUM(presence);
|
data/lib/lgpio/hardware_pwm.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module LGPIO
|
2
2
|
class HardwarePWM
|
3
|
-
NS_PER_S =
|
4
|
-
NS_PER_US =
|
3
|
+
NS_PER_S = 10**9
|
4
|
+
NS_PER_US = 10**3
|
5
5
|
SYS_FS_PWM_PATH = "/sys/class/pwm/"
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :period, :duty, :polarity, :enabled
|
8
8
|
|
9
9
|
def initialize(chip, channel, frequency: nil, period: nil)
|
10
10
|
@chip = chip
|
@@ -61,14 +61,12 @@ module LGPIO
|
|
61
61
|
|
62
62
|
def frequency
|
63
63
|
# If not set explicitly, calculate from period, rounded to nearest Hz.
|
64
|
-
@frequency ||= (
|
64
|
+
@frequency ||= (NS_PER_S / period.to_f).round
|
65
65
|
end
|
66
66
|
|
67
67
|
def period=(p)
|
68
|
-
|
69
|
-
unless (
|
70
|
-
File.open(duty_path, 'w') { |f| f.write("0") }
|
71
|
-
end
|
68
|
+
old_duty = duty || File.read(duty_path).strip.to_i
|
69
|
+
duty = 0 unless (old_duty == 0)
|
72
70
|
File.open(period_path, 'w') { |f| f.write(p) }
|
73
71
|
@frequency = nil
|
74
72
|
@period = p
|
data/lib/lgpio/infrared.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
module LGPIO
|
2
2
|
class Infrared < HardwarePWM
|
3
|
-
|
3
|
+
FREQUENCY = 38_000
|
4
|
+
DUTY = 33.333
|
5
|
+
|
6
|
+
def initialize(*args, **kwargs)
|
7
|
+
new_kwargs = {frequency: FREQUENCY}.merge(kwargs)
|
8
|
+
super(*args, **new_kwargs)
|
9
|
+
# Avoid needing to call #enable and #disable, before and after each #transmit call.
|
10
|
+
# disable
|
11
|
+
end
|
12
|
+
|
13
|
+
def transmit(pulses, duty: DUTY)
|
4
14
|
self.duty_percent = duty
|
5
15
|
tx_wave_ook(duty_path, @duty.to_s, pulses)
|
6
16
|
end
|
data/lib/lgpio/one_wire.rb
CHANGED
@@ -123,12 +123,12 @@ module LGPIO
|
|
123
123
|
new_discrepancies = address ^ complement
|
124
124
|
|
125
125
|
high_discrepancy = -1
|
126
|
-
(0..63).each { |i| high_discrepancy = i if new_discrepancies
|
126
|
+
(0..63).each { |i| high_discrepancy = i if ((new_discrepancies >> i) & 0b1 == 0) }
|
127
127
|
|
128
128
|
[address, high_discrepancy]
|
129
129
|
end
|
130
130
|
|
131
|
-
#
|
131
|
+
# Result is 16 bytes, 8 byte address and complement interleaved LSByte first.
|
132
132
|
def split_search_result(data)
|
133
133
|
address = 0
|
134
134
|
complement = 0
|
@@ -155,7 +155,7 @@ module LGPIO
|
|
155
155
|
crc = 0b00000000
|
156
156
|
bytes.take(bytes.length - 1).each do |byte|
|
157
157
|
for bit in (0..7)
|
158
|
-
xor = byte
|
158
|
+
xor = ((byte >> bit) & 0b1) ^ (crc & 0b1)
|
159
159
|
crc = crc ^ ((xor * (2 ** 3)) | (xor * (2 ** 4)))
|
160
160
|
crc = crc >> 1
|
161
161
|
crc = crc | (xor * (2 ** 7))
|
@@ -165,7 +165,9 @@ module LGPIO
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def self.address_to_bytes(address)
|
168
|
-
[
|
168
|
+
bytes = []
|
169
|
+
8.times { |i| bytes[i] = address >> (8*i) & 0xFF }
|
170
|
+
bytes
|
169
171
|
end
|
170
172
|
end
|
171
173
|
end
|
data/lib/lgpio/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lgpio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vickash
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Use Linux GPIO, I2C, SPI and PWM in Ruby
|
14
13
|
email: mail@vickash.com
|
@@ -18,6 +17,7 @@ extensions:
|
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
20
19
|
- ".gitignore"
|
20
|
+
- Gemfile
|
21
21
|
- LICENSE
|
22
22
|
- README.md
|
23
23
|
- Rakefile
|
@@ -67,7 +67,6 @@ licenses:
|
|
67
67
|
- MIT
|
68
68
|
metadata:
|
69
69
|
source_code_uri: https://github.com/denko-rb/lgpio
|
70
|
-
post_install_message:
|
71
70
|
rdoc_options: []
|
72
71
|
require_paths:
|
73
72
|
- lib
|
@@ -82,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
81
|
- !ruby/object:Gem::Version
|
83
82
|
version: '0'
|
84
83
|
requirements: []
|
85
|
-
rubygems_version: 3.
|
86
|
-
signing_key:
|
84
|
+
rubygems_version: 3.6.7
|
87
85
|
specification_version: 4
|
88
86
|
summary: Ruby C extension for Linux GPIO
|
89
87
|
test_files: []
|