class PhidgetTextLCD(object): """ A class modelled after a Phidget InterfaceKit with an integrated LCD. It contains a list of objects, which are subclasses of Sensor object. Attributes: analog_sensors: a list containing objects of one of subclasses of Sensor data_dir: a string of directory path to save sensor reading data in """ def __init__(self, analog_sensors, data_dir): """Initializes the members.""" self.__interfaceKit = InterfaceKit() self.__textLCD = TextLCD() self.__data_dir = data_dir # instantiate classes according to actual sensor port configuration self.sensors = [] for sensor in analog_sensors: a_sensor = self.__Factory(sensor) self.sensors.append(a_sensor) try: # Interface Kit self.__interfaceKit.openPhidget() self.__interfaceKit.waitForAttach(10000) print "%s (serial: %d) attached!" % ( self.__interfaceKit.getDeviceName(), self.__interfaceKit.getSerialNum()) # get initial value from each sensor i = 0 for sensor in self.sensors: #print sensor.product_name #print sensor.value sensor.value = self.__interfaceKit.getSensorValue(i) i += 1 self.__interfaceKit.setOnSensorChangeHandler(self.__SensorChanged) # Text LCD self.__textLCD.openPhidget() self.__textLCD.waitForAttach(10000) print "%s attached!" % (self.__textLCD.getDeviceName()) self.__textLCD.setCursorBlink(False) except PhidgetException, e: print "Phidget Exception %i: %s" % (e.code, e.message) sys.exit(1)
def __init__(self, analog_sensors, data_dir): """Initializes the members.""" self.__interfaceKit = InterfaceKit() self.__textLCD = TextLCD() self.__data_dir = data_dir # instantiate classes according to actual sensor port configuration self.sensors = [] for sensor in analog_sensors: a_sensor = self.__Factory(sensor) self.sensors.append(a_sensor) try: # Interface Kit self.__interfaceKit.openPhidget() self.__interfaceKit.waitForAttach(10000) print "%s (serial: %d) attached!" % ( self.__interfaceKit.getDeviceName(), self.__interfaceKit.getSerialNum()) # get initial value from each sensor i = 0 for sensor in self.sensors: #print sensor.product_name #print sensor.value sensor.value = self.__interfaceKit.getSensorValue(i) i += 1 self.__interfaceKit.setOnSensorChangeHandler(self.__SensorChanged) # Text LCD self.__textLCD.openPhidget() self.__textLCD.waitForAttach(10000) print "%s attached!" % (self.__textLCD.getDeviceName()) self.__textLCD.setCursorBlink(False) except PhidgetException, e: print "Phidget Exception %i: %s" % (e.code, e.message) sys.exit(1)