rpi_gpio 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,48 +1,47 @@
1
- /*
2
- Original code by Ben Croston modified for Ruby by Nick Lowery
3
- (github.com/clockvapor)
4
- Copyright (c) 2014-2015 Nick Lowery
5
-
6
- Copyright (c) 2013-2014 Ben Croston
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy of
9
- this software and associated documentation files (the "Software"), to deal in
10
- the Software without restriction, including without limitation the rights to
11
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12
- of the Software, and to permit persons to whom the Software is furnished to do
13
- so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in all
16
- copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- SOFTWARE.
25
- */
26
-
27
- #include "ruby.h"
28
- #include "c_gpio.h"
29
- #include "event_gpio.h"
30
- #include "cpuinfo.h"
31
- #include "common.h"
32
- #include "rb_pwm.h"
33
-
34
- void define_gpio_module_stuff(void);
35
- int mmap_gpio_mem(void);
36
- int is_gpio_initialized(unsigned int gpio);
37
- int is_gpio_output(unsigned int gpio);
38
- int is_rpi(void);
39
- VALUE GPIO_clean_up(int argc, VALUE *argv, VALUE self);
40
- VALUE GPIO_reset(VALUE self);
41
- VALUE GPIO_setup(VALUE self, VALUE channel, VALUE hash);
42
- VALUE GPIO_set_numbering(VALUE self, VALUE mode);
43
- VALUE GPIO_set_high(VALUE self, VALUE channel);
44
- VALUE GPIO_set_low(VALUE self, VALUE channel);
45
- VALUE GPIO_test_high(VALUE self, VALUE channel);
46
- VALUE GPIO_test_low(VALUE self, VALUE channel);
47
- VALUE GPIO_set_warnings(VALUE self, VALUE setting);
48
-
1
+ /*
2
+ Original code by Ben Croston modified for Ruby by Nick Lowery
3
+ (github.com/clockvapor)
4
+ Copyright (c) 2014-2020 Nick Lowery
5
+
6
+ Copyright (c) 2013-2014 Ben Croston
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+ this software and associated documentation files (the "Software"), to deal in
10
+ the Software without restriction, including without limitation the rights to
11
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12
+ of the Software, and to permit persons to whom the Software is furnished to do
13
+ so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ */
26
+
27
+ #include "ruby.h"
28
+ #include "c_gpio.h"
29
+ #include "event_gpio.h"
30
+ #include "cpuinfo.h"
31
+ #include "common.h"
32
+ #include "rb_pwm.h"
33
+
34
+ void define_gpio_module_stuff(void);
35
+ int mmap_gpio_mem(void);
36
+ int is_gpio_initialized(unsigned int gpio);
37
+ int is_gpio_output(unsigned int gpio);
38
+ int is_rpi(void);
39
+ VALUE GPIO_clean_up(int argc, VALUE *argv, VALUE self);
40
+ VALUE GPIO_reset(VALUE self);
41
+ VALUE GPIO_setup(VALUE self, VALUE channel, VALUE hash);
42
+ VALUE GPIO_set_numbering(VALUE self, VALUE mode);
43
+ VALUE GPIO_set_high(VALUE self, VALUE channel);
44
+ VALUE GPIO_set_low(VALUE self, VALUE channel);
45
+ VALUE GPIO_test_high(VALUE self, VALUE channel);
46
+ VALUE GPIO_test_low(VALUE self, VALUE channel);
47
+ VALUE GPIO_set_warnings(VALUE self, VALUE setting);
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  Original code by Ben Croston modified for Ruby by Nick Lowery
3
3
  (github.com/clockvapor)
4
- Copyright (c) 2014-2015 Nick Lowery
4
+ Copyright (c) 2014-2020 Nick Lowery
5
5
 
6
- Copyright (c) 2013-2014 Ben Croston
6
+ Copyright (c) 2013-2018 Ben Croston
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy of
9
9
  this software and associated documentation files (the "Software"), to deal in
@@ -54,13 +54,20 @@ VALUE PWM_initialize(VALUE self, VALUE channel, VALUE frequency)
54
54
  // convert channel to gpio
55
55
  if (get_gpio_number(chan, &gpio))
56
56
  return Qnil;
57
+
58
+ // does soft pwm already exist on this channel?
59
+ if (pwm_exists(gpio))
60
+ {
61
+ rb_raise(rb_eRuntimeError, "a PWM object already exists for this GPIO channel");
62
+ return Qnil;
63
+ }
57
64
 
58
65
  // ensure channel is set as output
59
66
  if (gpio_direction[gpio] != OUTPUT)
60
67
  {
61
68
  rb_raise(rb_eRuntimeError, "you must setup the GPIO channel as output "
62
69
  "first with RPi::GPIO.setup CHANNEL, :as => :output");
63
- return Qnil;
70
+ return Qnil;
64
71
  }
65
72
 
66
73
  rb_iv_set(self, "@gpio", UINT2NUM(gpio));
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  Original code by Ben Croston modified for Ruby by Nick Lowery
3
3
  (github.com/clockvapor)
4
- Copyright (c) 2014-2015 Nick Lowery
4
+ Copyright (c) 2014-2020 Nick Lowery
5
5
 
6
- Copyright (c) 2013-2014 Ben Croston
6
+ Copyright (c) 2013-2018 Ben Croston
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy of
9
9
  this software and associated documentation files (the "Software"), to deal in
@@ -54,13 +54,14 @@ void remove_pwm(unsigned int gpio)
54
54
  {
55
55
  if (p->gpio == gpio)
56
56
  {
57
- if (prev == NULL)
57
+ if (prev == NULL) {
58
58
  pwm_list = p->next;
59
- else
59
+ } else {
60
60
  prev->next = p->next;
61
+ }
61
62
  temp = p;
62
63
  p = p->next;
63
- free(temp);
64
+ temp->running = 0; // signal the thread to stop. The thread will free() the pwm struct when it's done with it.
64
65
  } else {
65
66
  prev = p;
66
67
  p = p->next;
@@ -113,7 +114,7 @@ void *pwm_thread(void *threadarg)
113
114
 
114
115
  // clean up
115
116
  output_gpio(p->gpio, 0);
116
- remove_pwm(p->gpio);
117
+ free(p);
117
118
  pthread_exit(NULL);
118
119
  }
119
120
 
@@ -135,6 +136,7 @@ struct pwm *add_new_pwm(unsigned int gpio)
135
136
  }
136
137
 
137
138
  struct pwm *find_pwm(unsigned int gpio)
139
+ /* Return the pwm record for gpio, creating it if it does not exist */
138
140
  {
139
141
  struct pwm *p = pwm_list;
140
142
 
@@ -207,12 +209,27 @@ void pwm_start(unsigned int gpio)
207
209
  p->running = 0;
208
210
  return;
209
211
  }
212
+ pthread_detach(threads);
210
213
  }
211
214
 
212
215
  void pwm_stop(unsigned int gpio)
213
216
  {
214
- struct pwm *p;
217
+ remove_pwm(gpio);
218
+ }
215
219
 
216
- if ((p = find_pwm(gpio)) != NULL)
217
- p->running = 0;
220
+ // returns 1 if there is a PWM for this gpio, 0 otherwise
221
+ int pwm_exists(unsigned int gpio)
222
+ {
223
+ struct pwm *p = pwm_list;
224
+
225
+ while (p != NULL)
226
+ {
227
+ if (p->gpio == gpio)
228
+ {
229
+ return 1;
230
+ } else {
231
+ p = p->next;
232
+ }
233
+ }
234
+ return 0;
218
235
  }
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  Original code by Ben Croston modified for Ruby by Nick Lowery
3
3
  (github.com/clockvapor)
4
- Copyright (c) 2014-2015 Nick Lowery
4
+ Copyright (c) 2014-2020 Nick Lowery
5
5
 
6
- Copyright (c) 2013-2014 Ben Croston
6
+ Copyright (c) 2013-2018 Ben Croston
7
7
 
8
8
  Permission is hereby granted, free of charge, to any person obtaining a copy of
9
9
  this software and associated documentation files (the "Software"), to deal in
@@ -30,3 +30,4 @@ void pwm_set_duty_cycle(unsigned int gpio, float dutycycle);
30
30
  void pwm_set_frequency(unsigned int gpio, float freq);
31
31
  void pwm_start(unsigned int gpio);
32
32
  void pwm_stop(unsigned int gpio);
33
+ int pwm_exists(unsigned int gpio);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rpi_gpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Lowery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-24 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.2.2
89
+ rubygems_version: 3.1.2
91
90
  signing_key:
92
91
  specification_version: 4
93
92
  summary: Ruby conversion of RPi.GPIO Python module