コード例 #1
0
    def _cb_set_value(self, value, tick, seq):
        def debcallback():
            self.pending = None
            self.value = value
            self.pulse_us = tick - self.tick
            self.tick = tick
            devents.status(self)
            #print("Input-%d = %d  %d" %(self.circuit,self.value, self.pulse_us))

        value = int(
            not bool(value)
        )  # normalize value and invert it - 0 = led on unipi board is off, 1 = led is shinning
        if self._debounce:
            if self.pending:
                self.bus.mainloop.remove_timeout(self.pending)
                #IOLoop.instance().remove_timeout(self.pending)
                self.pending = None

            if value != self.value:
                self.pending = self.bus.mainloop.add_timeout(
                    datetime.timedelta(seconds=self._debounce), debcallback)
                #self.pending = IOLoop.instance().add_timeout(datetime.timedelta(seconds=self._debounce),debcallback)
            return

        self.value = value
        #print("Input-%d = %d  %d" %(self.circuit,self.value, tick - self.tick))
        self.tick = tick
        devents.status(self)
コード例 #2
0
ファイル: unipig.py プロジェクト: EstebanCoto/evok
    def _cb_set_value(self, value, tick, seq):

        def debcallback():
            self.pending = None
            self.value = value
            self.pulse_us = tick - self.tick
            self.tick = tick
            devents.status(self)
            #print("Input-%d = %d  %d" %(self.circuit,self.value, self.pulse_us))

        value = int(
            not bool(value))  # normalize value and invert it - 0 = led on unipi board is off, 1 = led is shinning
        if self._debounce:
            if self.pending:
                self.bus.mainloop.remove_timeout(self.pending)
                #IOLoop.instance().remove_timeout(self.pending)
                self.pending = None

            if value != self.value:
                self.pending = self.bus.mainloop.add_timeout(datetime.timedelta(seconds=self._debounce), debcallback)
                #self.pending = IOLoop.instance().add_timeout(datetime.timedelta(seconds=self._debounce),debcallback)
            return

        self.value = value
        #print("Input-%d = %d  %d" %(self.circuit,self.value, tick - self.tick))
        self.tick = tick
        devents.status(self)
コード例 #3
0
ファイル: unipig.py プロジェクト: yaneti/evok
	def _cb_set_value(self, value, tick, seq):

		def debcallback():
			self.pending = None
			self.pulse_us = tick - self.tick
			self.__value = value
			self.tick = tick
			if (self.counter_mode == 'rising') and (value == 1):
				self.value += 1
			elif (self.counter_mode == 'falling') and (value == 0):
				self.value += 1
			elif self.counter_mode == 'disabled':
				self.value = value
			devents.status(self)
			#print("Input-%d = %d  %d" %(self.circuit,self.value, self.pulse_us))

		value = int(not bool(value))  # normalize value and invert it - 0 = led on unipi board is off, 1 = led is shinning
		if self._debounce:
			if self.pending:
				self.bus.mainloop.remove_timeout(self.pending)
				self.pending = None

			if value != self.__value:
				self.pending = self.bus.mainloop.add_timeout(datetime.timedelta(seconds=self._debounce), debcallback)
			return

		self.__value = value
		self.tick = tick
		if self.counter_mode == 'rising' and value == 1:
			self.value += 1
		elif self.counter_mode == 'falling' and value == 0:
			self.value += 1
		elif self.counter_mode == 'disabled':
			self.value = value
		devents.status(self)
コード例 #4
0
 def set_value(self, value):
     value10 = self.__calc_value(value)
     result = pigpio._u2i(
         (yield self.bus.apigpio_command(pigpio._PI_CMD_PWM, self.pin,
                                         value10)))
     self.value = value
     devents.status(self)
     raise gen.Return(result)
コード例 #5
0
 def set(self, debounce=None, counter=None):
     if not (debounce is None):
         if not debounce:
             self._debounce = 0
         else:
             self._debounce = float(debounce) / 1000.0  #milisecs
         devents.config(self)
     if not (counter is None):
         if self.counter_mode != 'disabled':
             self.value = counter
             devents.status(self)
コード例 #6
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
 def set_state(self, value):
     """ Sets new on/off status. Disable pending timeouts
     """
     value = bool(value)
     if self.pending_id:
         IOLoop.instance().remove_timeout(self.pending_id)
         self.pending_id = None
     yield self.device.set_relay_state(self.pin, value)
     result = 1 if self.device.get_relay_state(self.pin) else 0
     devents.status(self)
     raise gen.Return(result)
コード例 #7
0
 def debcallback():
     self.pending = None
     self.pulse_us = tick - self.tick
     self.__value = value
     self.tick = tick
     if (self.counter_mode == 'rising') and (value == 1):
         self.value += 1
     elif (self.counter_mode == 'falling') and (value == 0):
         self.value += 1
     elif self.counter_mode == 'disabled':
         self.value = value
     devents.status(self)
コード例 #8
0
ファイル: neuron.py プロジェクト: seb-koch/evok
    def set_data(self, register, data):
        # ToDo!
        changeset = set()
        #print data
        for i in range(len(data)):
            try:
                if data[i] == self.data[i]: continue
            except:
                pass
            changeset.update(self.datadeps[i])  # add devices to set

        self.data = data
        if len(changeset) > 0:
            proxy = Proxy(changeset)
            devents.status(proxy)
コード例 #9
0
    def set_data(self, register, data):
        # ToDo!
        changeset = []
        #print data
        for i in range(len(data)):
            try:
                if data[i] == self.data[i]: continue
            except:
                pass
            if self.datadeps.has_key(i):
                changeset += self.datadeps[i]  # add devices to set

        self.data = data
        if len(changeset) > 0:
            proxy = Proxy(set(changeset))
            devents.status(proxy)
コード例 #10
0
    def set_bitmap(self, mask, bitmap):

        byte_val = (self.value & ~mask) | (bitmap & mask)
        with (yield self.i2cbus.iolock.acquire()):
            #write byte
            extents = [struct.pack("I", byte_val)]
            result = yield self.i2cbus.apigpio_command_ext(
                pigpio._PI_CMD_I2CWB, self.i2c, MCP23008_GPIO, 4, extents)
            pigpio._u2i(result)  # check errors

            #read byte
            result = yield self.i2cbus.apigpio_command(pigpio._PI_CMD_I2CRB,
                                                       self.i2c, MCP23008_OLAT)
            mask = self.value
            self.value = pigpio._u2i(result)
            mask = mask ^ self.value
            for r in filter(lambda r: r._mask & mask, self.relays):
                devents.status(r)
コード例 #11
0
ファイル: owclient.py プロジェクト: 0x7b4/evok
 def _set_value(self, value):
     """ Called in master process after receiving result from subprocess
         to update values
         Invokes Events
     """
     if type(value) is bool:
         if not self.lost:
             self.lost = True
             devents.status(self)
     else:
         self.lost = False
         self.time = time.time()
         if self.value != value:
             self.value = value
             devents.status(self)
             #update DS_2408_pio object that are attached to this DS2408
             if type(value) is list:
                 pios_cnt = len(value)
                 for pio in self.pios:
                     if pio.pin < pios_cnt:
                         pio.set_value(value[pio.pin])
コード例 #12
0
ファイル: owclient.py プロジェクト: JPLemelin/evok
 def _set_value(self, value):
     """ Called in master process after receiving result from subprocess
         to update values
         Invokes Events
     """
     if type(value) is bool:
         if not self.lost:
             self.lost = True
             devents.status(self)
     else:
         self.lost = False
         self.time = time.time()
         if self.value != value:
             self.value = value
             devents.status(self)
             #update DS_2408_pio object that are attached to this DS2408
             if type(value) is list:
                 pios_cnt = len(value)
                 for pio in self.pios:
                     if pio.pin < pios_cnt:
                         pio.set_value(value[pio.pin])
コード例 #13
0
ファイル: owclient.py プロジェクト: 0x7b4/evok
 def _set_value(self, value):
     """ Called in master process after receiving result from subprocess
         to update values
         Invokes Events
     """
     if type(value) is bool:
         if not self.lost:
             self.lost = True
             devents.status(self)
     elif type(value) is tuple:
         self.lost = False
         if self.value is None:
             self.value = ()
             for i in range(len(value)):
                 self.value += (None,)
         for old, new in zip(self.value, value):
             if old != new:
                 self.value = value
                 self.time = time.time()
                 devents.status(self)
                 break
     else:
         self.lost = False
         self.time = time.time()
         if self.value != value:
             self.value = value
             devents.status(self)
コード例 #14
0
ファイル: owclient.py プロジェクト: JPLemelin/evok
 def _set_value(self, value):
     """ Called in master process after receiving result from subprocess
         to update values
         Invokes Events
     """
     if type(value) is bool:
         if not self.lost:
             self.lost = True
             devents.status(self)
     elif type(value) is tuple:
         self.lost = False
         if self.value is None:
             self.value = ()
             for i in range(len(value)):
                 self.value += (None,)
         for old, new in zip(self.value, value):
             if old != new:
                 self.value = value
                 self.time = time.time()
                 devents.status(self)
                 break
     else:
         self.lost = False
         self.time = time.time()
         if self.value != value:
             self.value = value
             devents.status(self)
コード例 #15
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
    def set_masked_value(self, mask, value):
        if value:
            byte_val = (self.value | mask) & 0xff
        else:
            byte_val = (self.value & ~mask) & 0xff

        with (yield self.i2cbus.iolock.acquire()):
            #write byte
            extents = [struct.pack("I", byte_val)]
            result = yield self.i2cbus.apigpio_command_ext(
                pigpio._PI_CMD_I2CWB,
                self.i2c, MCP23008_GPIO, 4, extents)
            pigpio._u2i(result)  # check errors

            #read byte
            result = yield self.i2cbus.apigpio_command(
                pigpio._PI_CMD_I2CRB,
                self.i2c, MCP23008_OLAT)
            mask = self.value
            self.value = pigpio._u2i(result)
            mask = mask ^ self.value
            for r in filter(lambda r: r._mask & mask, self.relays):
                devents.status(r)
コード例 #16
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
    def set(self, value=None, timeout=None):
        """ Sets new on/off status. Disable pending timeouts
        """
        if value is None:
            raise Exception('Value must be specified')
        value = bool(int(value))
        if not (timeout is None):
            timeout = float(timeout)

        #yield self.device.set_relay_state(self.pin, value)
        self.device.set_relay_state(self.pin, value)
        devents.status(self)

        if timeout is None:
            raise gen.Return(1 if self.device.get_relay_state(self.pin) else 0)

        def timercallback():
            self.pending_id = None
            self.device.set_relay_state(self.pin, value)

        self.pending_id = IOLoop.instance().add_timeout(
            datetime.timedelta(seconds=float(timeout)), timercallback)
        raise gen.Return(1 if self.device.get_relay_state(self.pin) else 0)
コード例 #17
0
ファイル: unipig.py プロジェクト: moeins/evok
 def debcallback():
     self.pending = None
     self.value = value
     self.pulse_us = tick - self.tick
     self.tick = tick
     devents.status(self)
コード例 #18
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
 def set_value(self, value):
     #value = int(not value)
     if self.value != value:
         self.value = value
         devents.status(self)
コード例 #19
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
 def debcallback():
     self.pending = None
     self.value = value
     self.pulse_us = tick - self.tick
     self.tick = tick
     devents.status(self)
コード例 #20
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
 def set_value(self, value):
     value10 = self.__calc_value(value)
     result = pigpio._u2i((yield self.bus.apigpio_command(pigpio._PI_CMD_PWM, self.pin, value10)))
     self.value = value
     devents.status(self)
     raise gen.Return(result)
コード例 #21
0
ファイル: unipig.py プロジェクト: JPLemelin/evok
 def _set_voltage(self, raw_value):
     if raw_value < 0: raw_value = 0  #value = - (value & self.mask)
     self.value = raw_value * self.koef
     #self.mtime = datetime.datetime.now()
     self.time = time.time()
     devents.status(self)
コード例 #22
0
 def set_value(self, value):
     #value = int(not value)
     if self.value != value:
         self.value = value
         devents.status(self)
コード例 #23
0
 def _set_voltage(self, raw_value):
     if raw_value < 0: raw_value = 0  #value = - (value & self.mask)
     self.value = raw_value * self.koef
     #self.mtime = datetime.datetime.now()
     self.time = time.time()
     devents.status(self)