Пример #1
0
 def __init__(self, number=""):
     self.__remote = False
     if number:
         if os.path.isfile(number):
             self.__file = number # Simulation where number is the file used dor onewire stream emulation
         elif os.path.isfile(os.path.join(os.getcwd(), number)):
             self.__file = number # Same but in the current folder
         elif not isRaspberry:
             try: # Remote filesystem
                 self.__file = "/sys/bus/w1/devices/%s/w1_slave" % number
                 probe = host.Execute("open(\"%s\")" % self.__file)
                 host.Execute("close()", probe)
                 host.RemoveHandle(probe)
                 self.__remote = True
             except:
                 raise ValueError, "1-Wire Probe %s not detected in remote!" % number
         else:
             self.__file = "/sys/bus/w1/devices/%s/w1_slave" % number
             if not os.path.isfile(self.__file):
                 raise ValueError, "1-Wire Probe %s not detected!" % number
     else:
         # Try autodetection
         self.__file = ""
         for number in os.listdir('/sys/bus/w1/devices'):
             if number != 'w1_bus_master1':
                 self.__file = "/sys/bus/w1/devices/%s/w1_slave" % number
                 break
         if not os.path.isfile(self.__file):
             raise ValueError, "1-Wire Probe not auto-detected!"
Пример #2
0
 def setup(self, channel, direction, pull_up_down=None, initial=None):
     if direction == self.OUT:
         if initial == None:
             host.Execute("GPIO.setup(%s, %s)" % (str(channel), str(direction)))
         else:
             host.Execute("GPIO.setup(%s, %s, initial=%s)" % (str(channel), str(direction), str(initial)))
     else:
         if pull_up_down == None:
             host.Execute("GPIO.setup(%s, %s)" % (str(channel), str(direction)))
         else:
             host.Execute("GPIO.setup(%s, %s, pull_up_down=%s)" % (str(channel), str(direction), str(pull_up_down)))
Пример #3
0
 def read(self):
     if self.__remote:
         probe = host.Execute("open(\"%s\")" % self.__file)
         result = host.Execute("read()", probe)
         host.Execute("close()", probe)
         host.RemoveHandle(probe)
     else:
         probe = open(self.__file)
         result = probe.read()
         probe.close()
     return float(result.split("\n")[1].split("=")[-1]) / 1000
Пример #4
0
 def PWM(self, channel, frequency):
     handle = host.Execute("GPIO.PWM(%s, %s)" % (str(channel), str(frequency)))
     if self.__pwms.has_key(channel):
         pwm = self.__pwms.pop(channel)
         del pwm
     self.__pwms[channel] = Pmw(handle)
     return self.__pwms[channel]
Пример #5
0
 def setmode(self, mode):
     host.Execute("GPIO.setmode(%s)" % str(mode))
Пример #6
0
 def getmode(self):
     return host.Execute("GPIO.getmode()")
Пример #7
0
 def __init__(self, address):
     self.__can = host.Execute("ADS1x15.ADS1115(%d)" % address)
Пример #8
0
 def wait_for_edge(self, channel, edge, bouncetime=0, timeout=-1):
     return host.Execute("GPIO.wait_for_edge(%s, %s, %s, %s)" % (str(channel), str(edge), str(bouncetime), str(timeout)))
Пример #9
0
 def event_detected(self, channel):
     return host.Execute("GPIO.event_detected(%s)" % str(channel))
Пример #10
0
 def input(self, channel):
     return host.Execute("GPIO.input(%s)" % str(channel))
Пример #11
0
 def __init__(self, busType):
     self.__bus = host.Execute("smbus.SMBus(%d)" % busType)
Пример #12
0
 def close(self):
     host.Execute("close()", self.__bus)
     host.RemoveHandle(self.__bus)
     self.__bus = None
Пример #13
0
 def write_byte_data(self, address, value, data):
     host.Execute("write_byte_data(%d, %d, %d)" % (address, value, data), self.__bus)
Пример #14
0
 def write_byte(self, address, value):
     host.Execute("write_byte(%d, %d)" % (address, value), self.__bus)
Пример #15
0
 def read_byte(self, address):
     return host.Execute("read_byte(%d)" % address, self.__bus)
Пример #16
0
 def setwarnings(self, on):
     host.Execute("GPIO.setwarnings(%s)" % str(on))
Пример #17
0
 def cleanup(self): # use *args
     host.Execute("GPIO.cleanup()")
     host.RemoveAllCallback("evtDetect")
Пример #18
0
 def start(self, percent):
     host.Execute("start(%s)" % str(percent), self.__handle)
Пример #19
0
 def output(self, channel, value):
     host.Execute("GPIO.output(%s, %s)" % (str(channel), str(value)))
Пример #20
0
 def stop(self):
     host.Execute("stop()", self.__handle)
Пример #21
0
 def add_event_detect(self, channel, edge, callback=None, bouncetime=50):
     if callback != None:
         cbItems = ("evtDetect%d" % channel, callback)
     else:
         cbItems == None
     host.Execute("GPIO.add_event_detect(%s, %s, %s, %s)" % (str(channel), str(edge), host.CB_KEYWORD, str(bouncetime)), callback=cbItems)
Пример #22
0
 def ChangeFrequency(self, freq):
     host.Execute("ChangeFrequency(%s)" % str(freq), self.__handle)
Пример #23
0
 def remove_event_detect(self, channel):
     host.Execute("GPIO.remove_event_detect(%s)" % str(channel))
     host.RemoveCallback("evtDetect%d" % channel)
Пример #24
0
 def ChangeDutyCycle(self, dc):
     host.Execute("ChangeDutyCycle(%s)" % str(dc), self.__handle)
Пример #25
0
 def gpio_function(self, channel):
     return host.Execute("GPIO.gpio_function(%s)" % str(channel))
Пример #26
0
 def read_adc(self, inputPin, gain):
     return host.Execute("read_adc(%d, %d)" % (inputPin, gain), self.__can)