Browse Source

renamed gpio to _gpio

digital 8 years ago
parent
commit
983457f6ad
1 changed files with 16 additions and 11 deletions
  1. 16 11
      pin/__init__.py

+ 16 - 11
pin/__init__.py

@@ -32,13 +32,17 @@ lgpio = logging.getLogger(__name__+".gpio")
 ERROR_TAKES_ARGUMENTS = "{} takes {} {} argument(s): {}"
 
 _pins_for_cleanup = set()
+_gpio = None
+
+def _make_gpio_warpper():
+    _gpio = GPIOWrapper()
 
 # gpio = GPIOWrapper()
 
 # respond(ERROR_TAKES_ARGUMENTS.format(
 #         command, "one", "positional", "<name>"))
 
-# def gpio.parse_to_int_list(parse):
+# def _gpioparse_to_int_list(parse):
 #     if type(parse) is list:
 #         return parse
 #     elif type(parse) is int:
@@ -192,16 +196,19 @@ class PinBase(object):
     value = None
     def __init__(self,pin_number,mode):
         super(PinBase,self).__init__()
+        if _gpio == None:
+            _gpio = _make_gpio_warpper()
         self.pin_number = pin_number
         self.value = self.value_low
+        _gpio.setup(self.pin_number,_gpio.OUT)
 
     def output(self,value):
-        [value] = gpio.parse_to_int_list(value)
+        [value] = gpioself.parse_to_int_list(value)
         self.value = value
-        gpio.output(self.pin_number,value)
+        _gpiooutput(self.pin_number,value)
 
     def read(self):
-        value = gpio.read(self.pin_number,value)
+        value = _gpioread(self.pin_number,value)
         return value
 
 class DigitalPin(PinBase):
@@ -380,19 +387,17 @@ class DebugPinController(PinControllerBase):
             respond(ERROR_TAKES_ARGUMENTS.format(
                     command, "two", "positional", "<name>"))
             return False
-        pins = gpio.parse_to_int_list(args[0])
-        [state] = gpio.parse_to_int_list(args[1])
+        pins = _gpioparse_to_int_list(args[0])
+        [state] = _gpioparse_to_int_list(args[1])
         gpio.output(pins,state)
     def read(self,args=[],command=None,respond=None):
         if len(args) != 2:
             respond(ERROR_TAKES_ARGUMENTS.format(
                     command, "two", "positional", "<name>"))
             return False
-        pins = gpio.parse_to_int_list(args[0])
-        [state] = gpio.parse_to_int_list(args[1])
-        return gpio.read(pins,state)
-
-gpio = GPIOWrapper()
+        pins = _gpioparse_to_int_list(args[0])
+        [state] = _gpioparse_to_int_list(args[1])
+        return _gpioread(pins,state)
 
 if __name__ == "__main__":
     pass