コード例 #1
0
    def __init__(self, name, sda=None, scl=None,
                 addr=8, ignore_case=False, report_change=True):
        not_found = "i2c device not found"

        self.addr = addr
        self.ownaddr = addr
        self.count = None
        self.current_value = ""
        self.suspend_start = None
        self.suspend_time = 0
        self.msgq = None
        if type(sda) is I2C:
            i2c = sda
        else:
            i2c = I2C(sda=sda, scl=scl)

        try:
            l = i2c.scan()  # see, if you can find the dive with respective addr
        except OSError:
            print(not_found)
        else:
            if addr in l:
                self.present = True
                Device.__init__(self, name, i2c, setters={"set":self.evaluate},
                                ignore_case=ignore_case,report_change=report_change)
                self.getters[""]=self.value
            else:
                print(not_found)
コード例 #2
0
ファイル: _display.py プロジェクト: sourceclimber/ulnoiot
    def __init__(self,
                 name,
                 sda=None,
                 scl=None,
                 width=128,
                 height=64,
                 addr=0x3c):
        self.present = False
        self._y = 0
        self._x = 0
        self.last_text = ""
        self.char_width = width // 8
        self.char_height = height // 8

        if type(sda) is I2C:
            i2c = sda
        else:
            i2c = I2C(sda=sda, scl=scl)
        # test if lcd is responding
        try:
            self.dp = ssd1306.SSD1306_I2C(width, height, i2c, addr=addr)
            self.clear(show=False)
            self.println("  iot.ulno.net\n", show=True)

        except OSError:
            print("lcd not found")
        else:
            self.present = True
            Device.__init__(self,
                            name,
                            i2c,
                            setters={"set": self.evaluate},
                            report_change=False)
            self.getters[""] = self.value
コード例 #3
0
ファイル: _trigger.py プロジェクト: pramodag/ulnoiot
 def __init__(self,
              name,
              pin,
              rising=False,
              falling=False,
              pullup=True,
              on_change=None,
              report_change=True):
     Device.__init__(self,
                     name,
                     pin,
                     on_change=on_change,
                     report_change=report_change)
     if pullup:
         pin.init(Pin.IN, Pin.PULL_UP)
     else:
         pin.init(Pin.IN, Pin.OPEN_DRAIN)
     trigger = None
     if rising and falling:
         trigger = Pin.IRQ_RISING | Pin.IRQ_FALLING
     elif not rising and falling:
         trigger = Pin.IRQ_FALLING
     else:  # also if both all false
         trigger = Pin.IRQ_RISING
     pin.irq(trigger=trigger, handler=self.callback)
     self.counter = 0
     self.report_counter = 0
     self.triggered = False
コード例 #4
0
ファイル: _output.py プロジェクト: sourceclimber/ulnoiot
 def __init__(self,
              name,
              pin,
              *args,
              high_command='on',
              low_command='off',
              ignore_case=True,
              on_change=None,
              report_change=False):
     if len(args) > 0:
         high_command = args[0]
         if len(args) > 1:
             low_command = args[1]
     if ignore_case:
         high_command = high_command.lower()
         low_command = low_command.lower()
     self.high_command = high_command
     self.low_command = low_command
     Device.__init__(self,
                     name,
                     pin,
                     setters={"set": self.evaluate},
                     ignore_case=ignore_case,
                     on_change=on_change,
                     report_change=report_change,
                     value_map={
                         1: self.high_command,
                         0: self.low_command
                     })
     pin.init(Pin.OUT)
コード例 #5
0
 def __init__(self,
              name,
              pin,
              ignore_case=True,
              on_change=None,
              report_change=False):
     self.is_on = False
     self.last_rgb = _c.white
     self.current_rgb = _c.black
     self.ani = None
     b = "brightness"
     r = "rgb"
     s = "set"
     st = "/status"
     Device.__init__(self,
                     name,
                     pin,
                     setters={
                         b + "/" + s: self._command_brightness,
                         r + "/" + s: self._command_rgb,
                         s: self._command_status,
                         "animation": self.animation
                     },
                     getters={
                         "": self.get_status,
                         b + st: self.get_brightness,
                         r + st: self.get
                     },
                     ignore_case=ignore_case,
                     on_change=on_change,
                     report_change=report_change)
     self.set(*_c.black)  # off
コード例 #6
0
ファイル: _hcsr04.py プロジェクト: KinKir/ulnoiot
 def __init__(self,
              name,
              trigger_pin,
              echo_pin,
              echo_timeout_us=30000,
              precision=10,
              on_change=None,
              report_change=True):
     # trigger_pin: Output pin to send pulses
     # echo_pin: Readonly pin to measure the distance.
     #           The pin should be protected with 1k resistor
     # echo_timeout_us: Timeout in microseconds to listen to echo pin.
     # By default is based in sensor limit range (4m)
     self.current_value = 0
     self._last_measured = 0
     if type(trigger_pin) is not Pin:
         trigger_pin = Pin(trigger_pin)
     self.trigger_pin = trigger_pin
     if type(echo_pin) is not Pin:
         echo_pin = Pin(trigger_pin)
     self.echo_pin = echo_pin
     self.precision = precision
     trigger_pin.init(Pin.OUT)
     trigger_pin.off()
     echo_pin.init(Pin.IN)
     echo_pin.init(Pin.OPEN_DRAIN)
     self.echo_timeout_us = echo_timeout_us
     self._distance = self._measure()
     Device.__init__(self,
                     name, (trigger_pin, echo_pin),
                     getters={"": self.value},
                     on_change=on_change,
                     report_change=report_change)
コード例 #7
0
 def __init__(self,
              name,
              pin,
              ignore_case=True,
              on_change=None,
              report_change=False,
              turn_time_ms=700,
              freq=50,
              min_us=600,
              max_us=2400,
              angle=180):
     self.min_us = min_us
     self.max_us = max_us
     self.us = 0
     self.freq = freq
     self.angle = angle
     self.angle_list = None
     self.turn_time_ms = turn_time_ms
     self.turn_start = None
     Device.__init__(self,
                     name,
                     PWM(pin, freq=self.freq, duty=0),
                     setters={"set": self.turn},
                     ignore_case=ignore_case,
                     on_change=on_change,
                     report_change=report_change)
     self._init()
コード例 #8
0
ファイル: _ht.py プロジェクト: pramodag/ulnoiot
 def __init__(self, name, pin, on_change=None):
     import onewire, ds18x20
     gc.collect()
     Device.__init__(self, name, pin,on_change=on_change)
     self.ds = ds18x20.DS18X20(onewire.OneWire(pin))
     self.roms = self.ds.scan()
     self.lasttime = time.ticks_ms()
     self.ds.convert_temp()
     self.temp_list = None
コード例 #9
0
ファイル: _pwm.py プロジェクト: sourceclimber/ulnoiot
 def __init__(self, name, pin, freq=50, duty=0,
              ignore_case=True, on_change=None,
              report_change=False):
     self._duty = 0
     self._freq = freq
     Device.__init__(self, name, PWM(pin, freq=freq, duty=duty),
                     setters={"freq/set":self.set_freq,"duty/set":self.set_duty},
                     getters={"freq":self.get_freq,"duty":self.get_duty},
                     ignore_case=ignore_case,
                     on_change=on_change, report_change=report_change)
コード例 #10
0
ファイル: _ht.py プロジェクト: pramodag/ulnoiot
 def __init__(self, name, pin, dht_dev, delay,
              on_change=None,report_change=True):
     Device.__init__(self, name, pin, on_change=on_change,
                     getters={"temperature":self.temperature(),
                              "humidity":self.humidity()},
                     report_change=report_change)
     self.delay = delay
     import dht
     self.dht = dht_dev
     self.lasttime = time.ticks_ms()
     self.dht.measure()
コード例 #11
0
 def __init__(self,
              name,
              precision=1,
              threshold=None,
              on_change=None,
              report_change=True):
     self.precision = precision
     self.threshold = None
     if threshold is not None:
         self.threshold = max(1, min(threshold, 1023))
     self.current_value = -10000
     Device.__init__(self,
                     name,
                     ADC(0),
                     on_change=on_change,
                     report_change=report_change)
コード例 #12
0
    def __init__(self, name, sda=None, scl=None, ignore_case=False):
        self.present = False
        self._y = 0
        self._x = 0
        self.last_text = ""

        # test if lcd is responding
        i2c = I2C(sda=sda, scl=scl)
        try:
            self.dp = ssd1306.SSD1306_I2C(128, 64, i2c)
            self.clear(show=False)
            self.println("  iot.ulno.net\n",show=True)

        except OSError:
            print("lcd not found")
        else:
            self.present = True
            Device.__init__(self, name, i2c, setters={"set":self.evaluate},
                            ignore_case=ignore_case,report_change=False)
コード例 #13
0
ファイル: _hcsr04.py プロジェクト: sourceclimber/ulnoiot
    def __init__(self, name, trigger_pin, echo_pin, echo_timeout_us=500*2*30, on_change=None, report_change=None):
        """
        trigger_pin: Output pin to send pulses
        echo_pin: Readonly pin to measure the distance. The pin should be protected with 1k resistor
        echo_timeout_us: Timeout in microseconds to listen to echo pin.
        By default is based in sensor limit range (4m)
        """
        self.echo_timeout_us = echo_timeout_us
        # Init trigger pin (out)
        self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None)
        self.trigger.value(0)

        # Init echo pin (in)
        self.echo = Pin(echo_pin, mode=Pin.IN, pull=None)

        Device.__init__(self, name, trigger_pin, echo_pin,
                        getters={"cm":self.distance_cm,
                                 "mm":self.distance_mm},
                        on_change=on_change,
                        report_change=report_change)
コード例 #14
0
    def __init__(self,
                 name,
                 sda=None,
                 scl=None,
                 width=16,
                 height=2,
                 addr=0x27):
        self.present = False
        self.last_text = ""
        self.char_width = width
        self.char_height = height
        self.display_buffer = bytearray(b" " * width * height)
        self.back_buffer = bytearray(b" " * width * height)
        self.x = 0
        self.y = 0

        if type(sda) is I2C:
            i2c = sda
        else:
            i2c = I2C(sda=sda, scl=scl)
        # test if lcd is responding
        try:
            self.dp = I2cLcd(i2c, addr, height, width)
            self.dp.clear()
            self.clear()
            self.hide_cursor()
            self.println("iot.ulno.net")

        except OSError:
            print("lcd not found")
        else:
            self.present = True
            Device.__init__(self,
                            name,
                            i2c,
                            setters={"set": self.evaluate},
                            report_change=False)
            self.getters[""] = self.value
コード例 #15
0
 def __init__(self, name, pin, *args,
              report_high="on", report_low="off",
              pullup=True, threshold=0,
              on_change=None, report_change=True):
     if len(args) > 0:
         report_high = args[0]
         if len(args) > 1:
             report_low = args[1]
     Device.__init__(self, name, pin,
                     value_map={True: report_high,
                                False: report_low},
                     on_change = on_change,
                     report_change=report_change)
     if pullup:
         pin.init(Pin.IN,Pin.PULL_UP)
     else:
         pin.init(Pin.IN)
         try:
             Pin.init(Pin.OPEN_DRAIN)
         except:
             pass
     self.debouncer = 0
     self.threshold = threshold + 1