Exemple #1
0
def raw_sample(io_sample):
    """raw_sample(channel) => A/D reading
    Returns raw unscaled A/D light, temperature and humidity sample data"""
    
    light = parseIS(io_sample)["AI1"]
    temp  = parseIS(io_sample)["AI2"]
    hum   = parseIS(io_sample)["AI3"]

    item = {'t': temp, 'l': light, 'h': hum}
    return item
Exemple #2
0
def raw_sample(io_sample):
    """raw_sample(channel) => A/D reading
    Returns raw unscaled A/D light, temperature and humidity sample data"""

    light = parseIS(io_sample)["AI1"]
    temp = parseIS(io_sample)["AI2"]
    hum = parseIS(io_sample)["AI3"]

    item = {'t': temp, 'l': light, 'h': hum}
    return item
Exemple #3
0
    def raw_sample(self, io_sample=None):
        """raw_sample(channel) => A/D reading
        Returns raw unscaled A/D light and temperature sample data"""

        if io_sample is None:
            io_sample = self.XBeeCommandGet("is")

        light = parseIS(io_sample)["AI1"]
        temp = parseIS(io_sample)["AI2"]

        item = {'temperature': temp, 'light': light}
        return item
Exemple #4
0
    def sample(self, channel, io_sample=None):
        """sample(channel) Returns digital sample data for specified channel"""

        assert channel < len(control_lines), "Unrecognized channel"
        assert channel >= 0, "Unrecognized channel"

        if io_sample is None:
            io_sample = self.XBeeCommandGet("is")

        return parseIS(io_sample)["DIO%d" % channel_to_pin[channel]]
    def raw_sample(self, channel, io_sample=None):
        """raw_sample(channel) => A/D reading
        Returns raw unscaled A/D converter sample data"""
        if channel >= len(ain_control_lines):
            raise ValueError, "Unrecognized channel"

        if io_sample is None:
            io_sample = self.XBeeCommandGet("is")

        return parseIS(io_sample)["AI%d" % channel]
Exemple #6
0
 def raw_sample(self, io_sample=None):
   """  Provides a untransulated sample in dictionary form.    
        temperature, light, current."""
        
   if io_sample is None:         
       io_sample = self.XBeeCommandGet("is")    
       
   parsed_struct = parseIS(io_sample)
   return {'temperature': parsed_struct["AI2"], 'light': parsed_struct["AI1"], 
           'current': parsed_struct["AI3"]}
Exemple #7
0
    def sample(self, channel):
        """sample(channel)
        Returns digital sample data for specified channel"""

        if channel >= len(control_lines):
            raise ValueError, "Unrecognized channel"

        if digihw.get_channel_type(channel) != Digital:
            raise ValueError, "Not a digital channel"

        result = self.XBeeCommandGet("is")

        return parseIS(result)["DIO%d" % channel]
    def raw_sample(self, channel):
        """raw_sample(channel) => A/D reading
        Returns raw unscaled A/D convertor sample data"""

        if channel >= len(input_lines):
            raise ValueError, "Unrecognized channel"

        if digihw.get_channel_type(channel) != Analog:
            raise ValueError, "Not an analog input channel"

# Calibrate every calInterval seconds
        now = time.clock()
        if debug:
            print "time is %f, calTime is %f" % (now, calTime)
        if now >= calTime + calInterval or now < calTime:
            self.calibrate()

        result = self.XBeeCommandGet("is")

        val = float(parseIS(result)["AI%d" % channel])
        val = scale * val
        val1 = int(round(val))
        return val1
    def calibrate(self):
        """calibrate()
        Calibrate analog inputs. Calculates scale and offset."""

        global calTime, scale, offset
        calTime = time.clock()

        # XBee series 1 uses one calibration voltage on AN2
        if self.device_type == XBeeSeries1:

            if digihw.get_channel_type(1) != Analog:
                raise ValueError, "No analog input channels"

            # Configure channel 1 as analog input
            self.XBeeCommandSet(input_lines[1], 2)

            # Enable calibration voltage on channel 1
            self.XBeeCommandSet("d4", 4)
            time.sleep(0.010)

            # Read calibration sample
            result = self.XBeeCommandGet("is")
            sample = parseIS(result)["AI1"]

            if debug:
                print "calibration sample is %d" % sample

            # Return channel to operating mode
            self.XBeeCommandSet("d4", 5)
            time.sleep(0.010)

            if sample == 0:
                raise ValueError, "Calibration error: bad sample"

            # Calulate linear scale and offset.
            # These apply to all analog channels.
            scale = 1.25 / sample
            offset = 0

        # XBee series 2 uses two calibration voltages on AN1 and AN2
        elif self.device_type == XBeeSeries2 or self.device_type == XBeeZB:

            if digihw.get_channel_type(0) != Analog or digihw.get_channel_type(
                    1) != Analog:
                raise ValueError, "No analog input channels"

            # Configure channels 0 and 1 as analog inputs
            self.XBeeCommandSet(input_lines[0], 2)
            self.XBeeCommandSet(input_lines[1], 2)

            # Enable calibration voltages on channels 0 and 1
            self.XBeeCommandSet("p2", 4)
            self.XBeeCommandSet("d4", 4)
            time.sleep(0.010)

            # Read calibration samples
            result = self.XBeeCommandGet("is")
            data = parseIS(result)
            sample = [data["AI0"], data["AI1"]]

            if debug:
                print "calibration samples are %d, %d" % (sample[0], sample[1])

            # Return channels to operating mode
            self.XBeeCommandSet("p2", 5)
            self.XBeeCommandSet("d4", 5)
            time.sleep(0.010)

            if sample[0] == sample[1]:
                raise ValueError, "Calibration error: equal samples"

            scale1 = 511.5 / float(sample[1])
            scale2 = 853.333 / float(sample[0])
            scale = (scale1 + scale2) / 2.0

            # Wasn't sure how to figure this out...
            offset = 0

        else:
            raise ValueError, "XBee does not support analog inputs"

        if debug:
            print "scale is %f, offset is %f" % (scale, offset)