lgpio 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3007d43d8623a895efdcfb2089ccc3c9105bde952af5095d904019d2df56eaaf
4
- data.tar.gz: 8aa7f8ecf78eff10e04deb2bc5a5732b939cbbaa99f7b4f578dd8320a7634fb7
3
+ metadata.gz: 968e706762503c9d172b41ff4df8a9c17021af5b4a4cb4372eeaaa166c30f5ff
4
+ data.tar.gz: 82d8221f8e28293f542c4bd1913f85addb567c217d071fdbb1e47451c3be1da1
5
5
  SHA512:
6
- metadata.gz: 93cc1be6fcafd45e98a11272f608241adc2c809f0ff6d71333a63f93453bb34fba4a75155cb973c06407b6cea281fbdd934664970077a1608718f0f218eb49cd
7
- data.tar.gz: f94f8859d0b7c3999687263a54979472fd73df50c0a3e09319aeb908c3b4e7de1bac458d97478f0ddeba19e4fe10d061c57e9331fc6910f386101315f4d087d5
6
+ metadata.gz: 8749280110629032e20ac94c203c512a699e90b58266f78f7c26a9305b8e22ef0f97822247744403c2723b7417838b5972c2618a65ebcb0ee2ae483cd0d12e41
7
+ data.tar.gz: a9bbac8e2f8c80de6adf86249bf559b10c590234597a15d3bf6dce37bc3b60ce27856f2343bdc1fe885a1a78105401419e221eb0ae5a10fa404ec7fc9c90a4fd
data/README.md CHANGED
@@ -43,16 +43,21 @@ These use the sysfs PWM interface, not lgpio C, but are a good fit for this gem.
43
43
  ## Installation
44
44
  On Debian-based Linuxes (RaspberryPi OS, Armbian, DietPi etc.):
45
45
  ```bash
46
- sudo apt install swig python3-dev python3-setuptools
46
+ # Requirements to install lgpio C
47
+ sudo apt install swig python3-dev python3-setuptools gcc make
47
48
 
48
49
  # Temporary fork of: wget https://github.com/joan2937/lg/archive/master.zip
49
50
  wget https://github.com/vickash/lg/archive/refs/heads/master.zip
50
51
 
52
+ # Install lgpio C
51
53
  unzip master.zip
52
54
  cd lg-master
53
55
  make
54
56
  sudo make install
55
57
 
58
+ # The latest Ruby 3 + YJIT is recommended, but you can use the system Ruby from apt too.
59
+ # sudo apt install ruby ruby-dev
60
+
56
61
  gem install lgpio
57
62
  ```
58
63
 
@@ -76,4 +81,10 @@ Even when these are enabled, you may not have permission to access them. To run
76
81
  - Method names have the leading `lg` removed, since inside the `LGPIO` class.
77
82
  - Constants have leading `LG_` removed, as above.
78
83
  - "count" or "length" arguments associated with array args are not needed.
84
+ - Arg order for `_claim_` methods varies from lgpio C, so that gpio number always follows handle. The general pattern is `handle, gpio, flags, state`. This affects:
85
+ - `gpio_claim_input`
86
+ - `gpio_claim_output`
87
+ - `gpio_claim_alert`
88
+ - `group_claim_input`
89
+ - `group_claim_output`
79
90
  - Check the return values of your method calls. On failure, they return negative values, matching the `LG_` error codes at the bottom of the C API doc page.
@@ -5,7 +5,7 @@ PIN = 260
5
5
  COUNT = 1000000
6
6
 
7
7
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
8
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_UP, PIN)
8
+ LGPIO.gpio_claim_input(chip_handle, PIN, LGPIO::SET_PULL_UP)
9
9
 
10
10
  t1 = Time.now
11
11
  COUNT.times do
@@ -5,7 +5,7 @@ PIN = 272
5
5
  COUNT = 1000000
6
6
 
7
7
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
8
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, PIN, LGPIO::LOW)
8
+ LGPIO.gpio_claim_output(chip_handle, PIN, LGPIO::SET_PULL_NONE, LGPIO::LOW)
9
9
 
10
10
  t1 = Time.now
11
11
  COUNT.times do
@@ -5,7 +5,7 @@ LED = 272
5
5
  INTERVAL = 0.25
6
6
 
7
7
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
8
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LED, LGPIO::LOW)
8
+ LGPIO.gpio_claim_output(chip_handle, LED, LGPIO::SET_PULL_NONE, LGPIO::LOW)
9
9
 
10
10
  loop do
11
11
  LGPIO.gpio_write(chip_handle, LED, 1)
@@ -7,8 +7,8 @@ LEDS = [272, 258]
7
7
  INIT_STATE = [0, 0]
8
8
 
9
9
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
10
- LGPIO.group_claim_input(chip_handle, LGPIO::SET_PULL_UP, BUTTONS)
11
- LGPIO.group_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LEDS, INIT_STATE)
10
+ LGPIO.group_claim_input(chip_handle, BUTTONS, LGPIO::SET_PULL_UP)
11
+ LGPIO.group_claim_output(chip_handle, LEDS, LGPIO::SET_PULL_NONE, INIT_STATE)
12
12
 
13
13
  # The inverted (active-low) state of each button controls the corresponding LED.
14
14
  loop do
@@ -7,7 +7,7 @@ INTERVAL = 250_000 # 250ms
7
7
  TIMES = 10
8
8
 
9
9
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
10
- LGPIO.group_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LEDS, INIT_STATE)
10
+ LGPIO.group_claim_output(chip_handle, LEDS, LGPIO::SET_PULL_NONE, INIT_STATE)
11
11
 
12
12
  # Convert us interval to seconds.
13
13
  interval = INTERVAL.to_f / 1_000_000
@@ -5,8 +5,8 @@ BUTTON = 259
5
5
  LED = 272
6
6
 
7
7
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
8
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_UP, BUTTON)
9
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LED, LGPIO::LOW)
8
+ LGPIO.gpio_claim_input(chip_handle, BUTTON, LGPIO::SET_PULL_UP)
9
+ LGPIO.gpio_claim_output(chip_handle, LED, LGPIO::SET_PULL_NONE, LGPIO::LOW)
10
10
 
11
11
  loop do
12
12
  if LGPIO.gpio_read(chip_handle, BUTTON) == 0
@@ -5,9 +5,9 @@ PIN = 259
5
5
 
6
6
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
7
7
 
8
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_NONE, PIN)
8
+ LGPIO.gpio_claim_input(chip_handle, PIN, LGPIO::SET_PULL_NONE)
9
9
  LGPIO.gpio_set_debounce(chip_handle, PIN, 1)
10
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::BOTH_EDGES, PIN)
10
+ LGPIO.gpio_claim_alert(chip_handle, PIN, 0, LGPIO::BOTH_EDGES)
11
11
  LGPIO.gpio_start_reporting
12
12
 
13
13
  loop do
@@ -17,17 +17,17 @@ state_b = 0
17
17
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
18
18
 
19
19
  # Encoder pin setup
20
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_NONE, PIN_A)
20
+ LGPIO.gpio_claim_input(chip_handle, PIN_A, LGPIO::SET_PULL_NONE)
21
21
  LGPIO.gpio_set_debounce(chip_handle, PIN_A, 1)
22
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::BOTH_EDGES, PIN_A)
23
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_NONE, PIN_B)
22
+ LGPIO.gpio_claim_alert(chip_handle, PIN_A, 0, LGPIO::BOTH_EDGES)
23
+ LGPIO.gpio_claim_input(chip_handle, PIN_B, LGPIO::SET_PULL_NONE)
24
24
  LGPIO.gpio_set_debounce(chip_handle, PIN_B, 1)
25
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::BOTH_EDGES, PIN_B)
25
+ LGPIO.gpio_claim_alert(chip_handle, PIN_B, 0, LGPIO::BOTH_EDGES)
26
26
 
27
27
  # Switch pin setup
28
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_UP, PIN_SW)
28
+ LGPIO.gpio_claim_input(chip_handle, PIN_SW, LGPIO::SET_PULL_UP)
29
29
  LGPIO.gpio_set_debounce(chip_handle, PIN_SW, 1)
30
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::FALLING_EDGE, PIN_SW)
30
+ LGPIO.gpio_claim_alert(chip_handle, PIN_SW, 0, LGPIO::FALLING_EDGE)
31
31
 
32
32
  # Start generating reports for GPIO level changes.
33
33
  LGPIO.gpio_start_reporting
@@ -21,15 +21,15 @@ led_duty = 0
21
21
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
22
22
 
23
23
  # LED pin setup
24
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, PIN_LED, LGPIO::LOW)
24
+ LGPIO.gpio_claim_output(chip_handle, PIN_LED, LGPIO::SET_PULL_NONE, LGPIO::LOW)
25
25
 
26
26
  # Encoder pin setup
27
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_NONE, PIN_A)
27
+ LGPIO.gpio_claim_input(chip_handle, PIN_A, LGPIO::SET_PULL_NONE)
28
28
  LGPIO.gpio_set_debounce(chip_handle, PIN_A, 1)
29
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::BOTH_EDGES, PIN_A)
30
- LGPIO.gpio_claim_input(chip_handle, LGPIO::SET_PULL_NONE, PIN_B)
29
+ LGPIO.gpio_claim_alert(chip_handle, PIN_A, 0, LGPIO::BOTH_EDGES)
30
+ LGPIO.gpio_claim_input(chip_handle, PIN_B, LGPIO::SET_PULL_NONE)
31
31
  LGPIO.gpio_set_debounce(chip_handle, PIN_B, 1)
32
- LGPIO.gpio_claim_alert(chip_handle, 0, LGPIO::BOTH_EDGES, PIN_B)
32
+ LGPIO.gpio_claim_alert(chip_handle, PIN_B, 0, LGPIO::BOTH_EDGES)
33
33
 
34
34
  # Start generating reports for GPIO level changes.
35
35
  LGPIO.gpio_start_reporting
@@ -7,7 +7,7 @@ INTERVAL = 250_000 # 250ms
7
7
  TIMES = 10
8
8
 
9
9
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
10
- LGPIO.group_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LEDS, INIT_STATE)
10
+ LGPIO.group_claim_output(chip_handle, LEDS, LGPIO::SET_PULL_NONE, INIT_STATE)
11
11
 
12
12
  # Generic pulse that updates both LED states (first element) each INTERVAL.
13
13
  generic_pulse = [ nil, 0b11, INTERVAL ]
data/examples/pwm_sw.rb CHANGED
@@ -7,7 +7,7 @@ PWM_OFFSET = 0
7
7
  PWM_CYCLES = 0 # 0 = infinite
8
8
 
9
9
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
10
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, LED, LGPIO::LOW)
10
+ LGPIO.gpio_claim_output(chip_handle, LED, LGPIO::SET_PULL_NONE, LGPIO::LOW)
11
11
 
12
12
  # Seamless loop from 0-100 and back.
13
13
  duty_cycles = (0..100).to_a + (1..99).to_a.reverse
@@ -15,9 +15,9 @@ DC_PIN = 6
15
15
  # Initialize
16
16
  chip_handle = LGPIO.chip_open(GPIO_CHIP)
17
17
  spi_bb = LGPIO::SPIBitBang.new(handle: chip_handle, clock: CLOCK_PIN, output: OUTPUT_PIN)
18
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, SELECT_PIN, LGPIO::HIGH)
19
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, RESET_PIN, LGPIO::LOW)
20
- LGPIO.gpio_claim_output(chip_handle, LGPIO::SET_PULL_NONE, DC_PIN, LGPIO::LOW)
18
+ LGPIO.gpio_claim_output(chip_handle, SELECT_PIN, LGPIO::SET_PULL_NONE, LGPIO::HIGH)
19
+ LGPIO.gpio_claim_output(chip_handle, RESET_PIN, LGPIO::SET_PULL_NONE, LGPIO::LOW)
20
+ LGPIO.gpio_claim_output(chip_handle, DC_PIN, LGPIO::SET_PULL_NONE, LGPIO::LOW)
21
21
 
22
22
  # OLED STARTUP
23
23
  LGPIO.gpio_write(chip_handle, RESET_PIN, 1)
data/ext/lgpio/lgpio.c CHANGED
@@ -60,12 +60,12 @@ static VALUE gpio_get_mode(VALUE self, VALUE handle, VALUE gpio) {
60
60
  return INT2NUM(result);
61
61
  }
62
62
 
63
- static VALUE gpio_claim_output(VALUE self, VALUE handle, VALUE flags, VALUE gpio, VALUE level) {
63
+ static VALUE gpio_claim_output(VALUE self, VALUE handle, VALUE gpio, VALUE flags, VALUE level) {
64
64
  int result = lgGpioClaimOutput(NUM2INT(handle), NUM2INT(flags), NUM2INT(gpio), NUM2INT(level));
65
65
  return INT2NUM(result);
66
66
  }
67
67
 
68
- static VALUE gpio_claim_input(VALUE self, VALUE handle, VALUE flags, VALUE gpio) {
68
+ static VALUE gpio_claim_input(VALUE self, VALUE handle, VALUE gpio, VALUE flags) {
69
69
  int result = lgGpioClaimInput(NUM2INT(handle), NUM2INT(flags), NUM2INT(gpio));
70
70
  return INT2NUM(result);
71
71
  }
@@ -85,7 +85,7 @@ static VALUE gpio_write(VALUE self, VALUE handle, VALUE gpio, VALUE level) {
85
85
  return INT2NUM(result);
86
86
  }
87
87
 
88
- static VALUE group_claim_input(VALUE self, VALUE handle, VALUE flags, VALUE gpios) {
88
+ static VALUE group_claim_input(VALUE self, VALUE handle, VALUE gpios, VALUE flags) {
89
89
  int count = rb_array_len(gpios);
90
90
  int lgGpios[count];
91
91
  int i;
@@ -96,7 +96,7 @@ static VALUE group_claim_input(VALUE self, VALUE handle, VALUE flags, VALUE gpio
96
96
  return INT2NUM(result);
97
97
  }
98
98
 
99
- static VALUE group_claim_output(VALUE self, VALUE handle, VALUE flags, VALUE gpios, VALUE levels) {
99
+ static VALUE group_claim_output(VALUE self, VALUE handle, VALUE gpios, VALUE flags, VALUE levels) {
100
100
  int count = rb_array_len(gpios);
101
101
  int lgGpios[count];
102
102
  int lgLevels[count];
@@ -130,7 +130,7 @@ static VALUE gpio_set_debounce(VALUE self, VALUE handle, VALUE gpio, VALUE debou
130
130
  return INT2NUM(result);
131
131
  }
132
132
 
133
- static VALUE gpio_claim_alert(VALUE self, VALUE handle, VALUE flags, VALUE eFlags, VALUE gpio) {
133
+ static VALUE gpio_claim_alert(VALUE self, VALUE handle, VALUE gpio, VALUE flags, VALUE eFlags) {
134
134
  int result = lgGpioClaimAlert(NUM2INT(handle), NUM2INT(flags), NUM2INT(eFlags), NUM2INT(gpio), -1);
135
135
  return INT2NUM(result);
136
136
  }
data/lib/lgpio/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LGPIO
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lgpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - vickash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-19 00:00:00.000000000 Z
11
+ date: 2024-09-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Use Linux GPIO, I2C, SPI and PWM in Ruby
14
14
  email: mail@vickash.com
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.5.16
85
+ rubygems_version: 3.5.20
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Use Linux GPIO, I2C, SPI and PWM in Ruby