rpi_gpio 0.2.0 → 0.3.0

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.
@@ -1,48 +1,48 @@
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_input(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-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_input(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,141 +1,141 @@
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 "rb_pwm.h"
28
-
29
- extern VALUE m_GPIO;
30
- VALUE c_PWM = Qnil;
31
-
32
- void define_pwm_class_stuff(void)
33
- {
34
- c_PWM = rb_define_class_under(m_GPIO, "PWM", rb_cObject);
35
- rb_define_method(c_PWM, "initialize", PWM_initialize, 2);
36
- rb_define_method(c_PWM, "start", PWM_start, 1);
37
- rb_define_method(c_PWM, "gpio", PWM_get_gpio, 0);
38
- rb_define_method(c_PWM, "duty_cycle", PWM_get_duty_cycle, 0);
39
- rb_define_method(c_PWM, "duty_cycle=", PWM_set_duty_cycle, 1);
40
- rb_define_method(c_PWM, "frequency", PWM_get_frequency, 0);
41
- rb_define_method(c_PWM, "frequency=", PWM_set_frequency, 1);
42
- rb_define_method(c_PWM, "stop", PWM_stop, 0);
43
- rb_define_method(c_PWM, "running?", PWM_get_running, 0);
44
- }
45
-
46
- // RPi::GPIO::PWM#initialize
47
- VALUE PWM_initialize(VALUE self, VALUE channel, VALUE frequency)
48
- {
49
- int chan;
50
- unsigned int gpio;
51
-
52
- chan = NUM2INT(channel);
53
-
54
- // convert channel to gpio
55
- if (get_gpio_number(chan, &gpio))
56
- return Qnil;
57
-
58
- // ensure channel is set as output
59
- if (gpio_direction[gpio] != OUTPUT)
60
- {
61
- rb_raise(rb_eRuntimeError, "you must setup the GPIO channel as output "
62
- "first with RPi::GPIO.setup CHANNEL, :as => :output");
63
- return Qnil;
64
- }
65
-
66
- rb_iv_set(self, "@gpio", UINT2NUM(gpio));
67
- rb_iv_set(self, "@running", Qfalse);
68
- PWM_set_frequency(self, frequency);
69
- return self;
70
- }
71
-
72
- // RPi::GPIO::PWM#start
73
- VALUE PWM_start(VALUE self, VALUE duty_cycle)
74
- {
75
- pwm_start(NUM2UINT(rb_iv_get(self, "@gpio")));
76
- PWM_set_duty_cycle(self, duty_cycle);
77
- rb_iv_set(self, "@running", Qtrue);
78
- return self;
79
- }
80
-
81
- // RPi::GPIO::PWM#gpio
82
- VALUE PWM_get_gpio(VALUE self)
83
- {
84
- return rb_iv_get(self, "@gpio");
85
- }
86
-
87
- // RPi::GPIO::PWM#duty_cycle
88
- VALUE PWM_get_duty_cycle(VALUE self)
89
- {
90
- return rb_iv_get(self, "@duty_cycle");
91
- }
92
-
93
- // RPi::GPIO::PWM#duty_cycle=
94
- VALUE PWM_set_duty_cycle(VALUE self, VALUE duty_cycle)
95
- {
96
- float dc = (float) NUM2DBL(duty_cycle);
97
- if (dc < 0.0f || dc > 100.0f)
98
- {
99
- rb_raise(rb_eArgError, "duty cycle must be between 0.0 and 100.0");
100
- return Qnil;
101
- }
102
-
103
- rb_iv_set(self, "@duty_cycle", duty_cycle);
104
- pwm_set_duty_cycle(NUM2UINT(rb_iv_get(self, "@gpio")), dc);
105
- return self;
106
- }
107
-
108
- // RPi::GPIO::PWM#frequency
109
- VALUE PWM_get_frequency(VALUE self)
110
- {
111
- return rb_iv_get(self, "@frequency");
112
- }
113
-
114
- // RPi::GPIO::PWM#frequency=
115
- VALUE PWM_set_frequency(VALUE self, VALUE frequency)
116
- {
117
- float freq = (float) NUM2DBL(frequency);
118
- if (freq <= 0.0f)
119
- {
120
- rb_raise(rb_eArgError, "frequency must be greater than 0.0");
121
- return Qnil;
122
- }
123
-
124
- rb_iv_set(self, "@frequency", frequency);
125
- pwm_set_frequency(NUM2UINT(rb_iv_get(self, "@gpio")), freq);
126
- return self;
127
- }
128
-
129
- // RPi::GPIO::PWM#stop
130
- VALUE PWM_stop(VALUE self)
131
- {
132
- pwm_stop(NUM2UINT(rb_iv_get(self, "@gpio")));
133
- rb_iv_set(self, "@running", Qfalse);
134
- return self;
135
- }
136
-
137
- // RPi::GPIO::PWM#running?
138
- VALUE PWM_get_running(VALUE self)
139
- {
140
- return rb_iv_get(self, "@running");
141
- }
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 "rb_pwm.h"
28
+
29
+ extern VALUE m_GPIO;
30
+ VALUE c_PWM = Qnil;
31
+
32
+ void define_pwm_class_stuff(void)
33
+ {
34
+ c_PWM = rb_define_class_under(m_GPIO, "PWM", rb_cObject);
35
+ rb_define_method(c_PWM, "initialize", PWM_initialize, 2);
36
+ rb_define_method(c_PWM, "start", PWM_start, 1);
37
+ rb_define_method(c_PWM, "gpio", PWM_get_gpio, 0);
38
+ rb_define_method(c_PWM, "duty_cycle", PWM_get_duty_cycle, 0);
39
+ rb_define_method(c_PWM, "duty_cycle=", PWM_set_duty_cycle, 1);
40
+ rb_define_method(c_PWM, "frequency", PWM_get_frequency, 0);
41
+ rb_define_method(c_PWM, "frequency=", PWM_set_frequency, 1);
42
+ rb_define_method(c_PWM, "stop", PWM_stop, 0);
43
+ rb_define_method(c_PWM, "running?", PWM_get_running, 0);
44
+ }
45
+
46
+ // RPi::GPIO::PWM#initialize
47
+ VALUE PWM_initialize(VALUE self, VALUE channel, VALUE frequency)
48
+ {
49
+ int chan;
50
+ unsigned int gpio;
51
+
52
+ chan = NUM2INT(channel);
53
+
54
+ // convert channel to gpio
55
+ if (get_gpio_number(chan, &gpio))
56
+ return Qnil;
57
+
58
+ // ensure channel is set as output
59
+ if (gpio_direction[gpio] != OUTPUT)
60
+ {
61
+ rb_raise(rb_eRuntimeError, "you must setup the GPIO channel as output "
62
+ "first with RPi::GPIO.setup CHANNEL, :as => :output");
63
+ return Qnil;
64
+ }
65
+
66
+ rb_iv_set(self, "@gpio", UINT2NUM(gpio));
67
+ rb_iv_set(self, "@running", Qfalse);
68
+ PWM_set_frequency(self, frequency);
69
+ return self;
70
+ }
71
+
72
+ // RPi::GPIO::PWM#start
73
+ VALUE PWM_start(VALUE self, VALUE duty_cycle)
74
+ {
75
+ pwm_start(NUM2UINT(rb_iv_get(self, "@gpio")));
76
+ PWM_set_duty_cycle(self, duty_cycle);
77
+ rb_iv_set(self, "@running", Qtrue);
78
+ return self;
79
+ }
80
+
81
+ // RPi::GPIO::PWM#gpio
82
+ VALUE PWM_get_gpio(VALUE self)
83
+ {
84
+ return rb_iv_get(self, "@gpio");
85
+ }
86
+
87
+ // RPi::GPIO::PWM#duty_cycle
88
+ VALUE PWM_get_duty_cycle(VALUE self)
89
+ {
90
+ return rb_iv_get(self, "@duty_cycle");
91
+ }
92
+
93
+ // RPi::GPIO::PWM#duty_cycle=
94
+ VALUE PWM_set_duty_cycle(VALUE self, VALUE duty_cycle)
95
+ {
96
+ float dc = (float) NUM2DBL(duty_cycle);
97
+ if (dc < 0.0f || dc > 100.0f)
98
+ {
99
+ rb_raise(rb_eArgError, "duty cycle must be between 0.0 and 100.0");
100
+ return Qnil;
101
+ }
102
+
103
+ rb_iv_set(self, "@duty_cycle", duty_cycle);
104
+ pwm_set_duty_cycle(NUM2UINT(rb_iv_get(self, "@gpio")), dc);
105
+ return self;
106
+ }
107
+
108
+ // RPi::GPIO::PWM#frequency
109
+ VALUE PWM_get_frequency(VALUE self)
110
+ {
111
+ return rb_iv_get(self, "@frequency");
112
+ }
113
+
114
+ // RPi::GPIO::PWM#frequency=
115
+ VALUE PWM_set_frequency(VALUE self, VALUE frequency)
116
+ {
117
+ float freq = (float) NUM2DBL(frequency);
118
+ if (freq <= 0.0f)
119
+ {
120
+ rb_raise(rb_eArgError, "frequency must be greater than 0.0");
121
+ return Qnil;
122
+ }
123
+
124
+ rb_iv_set(self, "@frequency", frequency);
125
+ pwm_set_frequency(NUM2UINT(rb_iv_get(self, "@gpio")), freq);
126
+ return self;
127
+ }
128
+
129
+ // RPi::GPIO::PWM#stop
130
+ VALUE PWM_stop(VALUE self)
131
+ {
132
+ pwm_stop(NUM2UINT(rb_iv_get(self, "@gpio")));
133
+ rb_iv_set(self, "@running", Qfalse);
134
+ return self;
135
+ }
136
+
137
+ // RPi::GPIO::PWM#running?
138
+ VALUE PWM_get_running(VALUE self)
139
+ {
140
+ return rb_iv_get(self, "@running");
141
+ }
@@ -1,41 +1,41 @@
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 "soft_pwm.h"
29
- #include "common.h"
30
- #include "c_gpio.h"
31
-
32
- void define_pwm_class_stuff(void);
33
- VALUE PWM_initialize(VALUE self, VALUE channel, VALUE frequency);
34
- VALUE PWM_start(VALUE self, VALUE duty_cycle);
35
- VALUE PWM_get_gpio(VALUE self);
36
- VALUE PWM_get_duty_cycle(VALUE self);
37
- VALUE PWM_set_duty_cycle(VALUE self, VALUE duty_cycle);
38
- VALUE PWM_get_frequency(VALUE self);
39
- VALUE PWM_set_frequency(VALUE self, VALUE frequency);
40
- VALUE PWM_stop(VALUE self);
41
- VALUE PWM_get_running(VALUE self);
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 "soft_pwm.h"
29
+ #include "common.h"
30
+ #include "c_gpio.h"
31
+
32
+ void define_pwm_class_stuff(void);
33
+ VALUE PWM_initialize(VALUE self, VALUE channel, VALUE frequency);
34
+ VALUE PWM_start(VALUE self, VALUE duty_cycle);
35
+ VALUE PWM_get_gpio(VALUE self);
36
+ VALUE PWM_get_duty_cycle(VALUE self);
37
+ VALUE PWM_set_duty_cycle(VALUE self, VALUE duty_cycle);
38
+ VALUE PWM_get_frequency(VALUE self);
39
+ VALUE PWM_set_frequency(VALUE self, VALUE frequency);
40
+ VALUE PWM_stop(VALUE self);
41
+ VALUE PWM_get_running(VALUE self);