contrib/wiringPi: move pseudo-toplevel methods from Object
[nit.git] / contrib / wiringPi / lib / wiringPi.nit
index 2852256..d21cbbb 100644 (file)
@@ -29,20 +29,21 @@ in "C Header" `{
 `}
 
 
-redef class Object
-       # This initialises wiringPi and assumes that the calling program is
-       # going to be using the wiringPi pin numbering scheme.
-       fun wiringPi_setup `{ wiringPiSetup(); `}
-       # Same as wiringPi_setup, however it allows the calling programs to
-       # use the Broadcom GPIO pin numbers directly with no re-mapping.
-       fun wiringPi_setup_gpio `{ wiringPiSetupGpio(); `}
-       # Identical to wiringPi_setup, however it allows the calling
-       # programs to use the physical pin numbers on the P1 connector only.
-       fun wiringPi_setup_phys `{ wiringPiSetupPhys(); `}
-       # This initialises wiringPi but uses the /sys/class/gpio interface
-       # rather than accessing the hardware directly.
-       fun wiringPi_setup_sys `{ wiringPiSetupSys(); `}
-end
+# Initializes wiringPi.
+# Assumes that the calling program is going to be using the wiringPi pin numbering scheme.
+fun wiringPi_setup `{ wiringPiSetup(); `}
+
+# Same as wiringPi_setup, but with GPIO.
+# It allows the calling programs to use the Broadcom GPIO pin numbers directly with no re-mapping.
+fun wiringPi_setup_gpio `{ wiringPiSetupGpio(); `}
+
+# Same as to wiringPi_setup, but with physical pin numbers.
+# It allows the calling programs to use the physical pin numbers on the P1 connector only.
+fun wiringPi_setup_phys `{ wiringPiSetupPhys(); `}
+
+# This initializes wiringPi, but with the /sys/class/gpio interface.
+# Use `/sys/class/gpio` rather than accessing the hardware directly.
+fun wiringPi_setup_sys `{ wiringPiSetupSys(); `}
 
 # A Raspberry Pi GPIO Pin
 extern class RPiPin `{ CRPiPin *`}
@@ -53,28 +54,28 @@ extern class RPiPin `{ CRPiPin *`}
        `}
 
        # The pin `id` depends on wiringPi setup used
-       fun id: Int `{ return recv->id; `}
+       fun id: Int `{ return self->id; `}
 
        # Sets the mode of the pin
-       fun mode(mode: RPiPinMode) `{ pinMode(recv->id, mode); `}
+       fun mode(mode: RPiPinMode) `{ pinMode(self->id, mode); `}
 
        # This sets the pull-up or pull-down resistor mode on the given pin,
        # which should be set as an input.
-       fun pullup_dncontrol(pud: PUDControl) `{ pullUpDnControl(recv->id, pud); `}
+       fun pullup_dncontrol(pud: PUDControl) `{ pullUpDnControl(self->id, pud); `}
 
        # Writes the value HIGH or LOW (true or false) to the given pin which must
        # have been previously set as an output.
-       fun write(high: Bool) `{ digitalWrite(recv->id, high? HIGH: LOW); `}
+       fun write(high: Bool) `{ digitalWrite(self->id, high? HIGH: LOW); `}
 
        # Writes the value to the PWM register for the given pin.
        # The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12)
        # and the range is 0-1024.
        # Other PWM devices may have other PWM ranges.
-       fun pwm_write(value: Int) `{ pwmWrite(recv->id, value); `}
+       fun pwm_write(value: Int) `{ pwmWrite(self->id, value); `}
 
        # This function returns the value read at the given pin.
        # It will be HIGH or LOW (true or false) depending on the logic level at the pin.
-       fun read: Bool `{ return digitalRead(recv->id) == HIGH? true: false; `}
+       fun read: Bool `{ return digitalRead(self->id) == HIGH? true: false; `}
 end
 
 # RPI Pin modes