Class: Pin
- Inherits:
-
Object
- Object
- Pin
- Defined in:
- ext/bonekit/pin_class.c
Instance Method Summary collapse
-
#analog_value ⇒ Float
Reads the analog value from the pin.
-
#analog_value=(value) ⇒ Float
Write the analog value to the pin.
-
#initialize(pin, mode = Input) ⇒ Pin
constructor
Returns a new Pin object with default value of 0.
-
#mode ⇒ Integer
Returns the mode of the pin.
-
#mode=(mode) ⇒ Integer
Sets the mode of the pin.
-
#value ⇒ Integer
Reads the value from the pin.
-
#value=(value) ⇒ Integer
Write the value to the pin.
Constructor Details
#initialize(pin, mode = Input) ⇒ Pin
Returns a new Pin object with default value of 0
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/bonekit/pin_class.c', line 60 static VALUE Pin_initialize(int argc, VALUE* argv, VALUE self) { if (argc > 2 || argc == 0) // there should only be 1 or 2 arguments rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc); pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); if(Beaglebone_global_const_check_type(argv[0]) == 0) rb_raise(rb_eArgError, "wrong pin argument type Fixnum (expected BeaglebonePin)"); beaglebone_t * bp_ptr = (beaglebone_t *)Beaglebone_global_const_to_beaglebone_t(argv[0]); beaglebone_t bp; memcpy(&bp, bp_ptr, sizeof(beaglebone_t)); if(pin_init(ptr, bp) < 0) // pin must support gpio, ain, pwm rb_raise(rb_eArgError, "invalid pin (%d GPIO not supported)", NUM2UINT(argv[0])); int mode = INPUT; if(argc == 2) mode = NUM2INT(argv[1]); pin_set_mode(ptr, mode); return self; } |
Instance Method Details
#analog_value ⇒ Float
Reads the analog value from the pin. The range of values is [0.0..1.0]. NOTE: If the pin doesn’t support ADC, analog_value is the floating point equivalent of value. If the pin has been previously used to set analog values (PWM) its returns the last analog value set.
111 112 113 114 115 116 117 |
# File 'ext/bonekit/pin_class.c', line 111 static VALUE Pin_analog_value(VALUE self) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); return rb_float_new(pin_analog_value(ptr)); } |
#analog_value=(value) ⇒ Float
Write the analog value to the pin. The pin must support Pulse-Width Modulation (PWM). Possible values: 0.0 to 1.0
142 143 144 145 146 147 148 149 |
# File 'ext/bonekit/pin_class.c', line 142 static VALUE Pin_set_analog_value(VALUE self, VALUE value) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); pin_set_analog_value(ptr, NUM2DBL(value)); return value; } |
#mode ⇒ Integer
Returns the mode of the pin. Possible modes: Input, Output.
158 159 160 161 162 163 |
# File 'ext/bonekit/pin_class.c', line 158 static VALUE Pin_mode(VALUE self) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); return INT2NUM(pin_mode(ptr)); } |
#mode=(mode) ⇒ Integer
Sets the mode of the pin. Possible modes: Input, Output.
172 173 174 175 176 177 178 179 |
# File 'ext/bonekit/pin_class.c', line 172 static VALUE Pin_set_mode(VALUE self, VALUE value) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); pin_set_mode(ptr, NUM2INT(value)); return value; } |
#value ⇒ Integer
Reads the value from the pin. The values are [0,1].
94 95 96 97 98 99 100 |
# File 'ext/bonekit/pin_class.c', line 94 static VALUE Pin_value(VALUE self) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); return INT2NUM(pin_value(ptr)); } |
#value=(value) ⇒ Integer
Write the value to the pin. The pin mode must be set to Output. Possible values: High, Low.
126 127 128 129 130 131 132 133 |
# File 'ext/bonekit/pin_class.c', line 126 static VALUE Pin_set_value(VALUE self, VALUE value) { pin_t * ptr; Data_Get_Struct(self, pin_t, ptr); pin_set_value(ptr, NUM2INT(value)); return value; } |