def run(self):
		global sensors
		
		#self.flask_input = open('read_pipe','w')
		#self.flask_output = open('write_pipe','r')
		self.mmap_file = open('mmap_ipc','a+b')
		self.mmap_buf = mmap.mmap(self.mmap_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_altitude_file = open('/home/pi/.sensorian/mmap_altitude','a+b')
		self.mmap_altitude = mmap.mmap(self.mmap_altitude_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_pressure_file = open('/home/pi/.sensorian/mmap_pressure','a+b')
		self.mmap_pressure = mmap.mmap(self.mmap_pressure_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_temperature_file = open('/home/pi/.sensorian/mmap_temperature','a+b')
		self.mmap_temperature = mmap.mmap(self.mmap_temperature_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		self.mmap_ambientlight_file = open('/home/pi/.sensorian/mmap_ambientlight','a+b')
		self.mmap_ambientlight = mmap.mmap(self.mmap_ambientlight_file.fileno(),0,access=mmap.ACCESS_WRITE)
		
		SensorsInterface.setupSensorian()
		
		#Setup a dummy alarm for now
		SensorsInterface.setRTCCtime(2016,3,4,5,33,0)
		SensorsInterface.setRTCCalarm(2018,1,1,1,40,20,1) #MINUTES_MATCH mode
		
		prev_touchpad = SensorsInterface.getTouchpad()
		#prev_magnetometer = SensorsInterface.getMagnetometer()
		prev_magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
		prev_accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
		prev_alarmtrigger = SensorsInterface.pollRTCCalarm()
		while self.alive:
			sensors_lock.acquire()
			sensors = {}
			touchpad = SensorsInterface.getTouchpad()
			if touchpad != prev_touchpad:
				print "Touchpad: " + str(touchpad)
				#sensors_lock.acquire()
				sensors['touchpad'] = touchpad
				#sensors_lock.release()
			prev_touchpad = touchpad
			
			#magnetometer = SensorsInterface.getMagnetometer()
			magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
			if magnetometer != prev_magnetometer:
				print "Magnetometer: " + str(magnetometer)
				#sensors_lock.acquire()
				sensors['magnetometer'] = magnetometer
				#sensors_lock.release()
			prev_magnetometer = magnetometer
			
			accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
			if accelerometer != prev_accelerometer:
				print "Accelerometer: " + str(accelerometer)
				sensors['accelerometer'] = accelerometer
			prev_accelerometer = accelerometer
			
			alarmtrigger = SensorsInterface.pollRTCCalarm()
			if alarmtrigger != prev_alarmtrigger:
				print "Alarm Trigger: " + str(alarmtrigger)
				sensors['alarmtrigger'] = alarmtrigger
			prev_alarmtrigger = alarmtrigger
			
			#Poll flask_rtcc_interface.py for new updates to RTCC
			#print "polling flask_rtcc_interface.py"
			#self.flask_input.write("reqUpdate\n")
			#self.flask_input.flush()
			if self.mmap_buf[0] == '1':
				#Update the time
				new_time_tuple = get_time_from_mmap(self.mmap_buf,2)
				SensorsInterface.setRTCCtime(new_time_tuple[0],new_time_tuple[1],new_time_tuple[2],new_time_tuple[3],new_time_tuple[4],new_time_tuple[5])
				print "done setting the time"
				self.mmap_buf[0] = '0' #Clear NEW_TIME
			
			if self.mmap_buf[1] == '1':
				#Update the alarm
				new_alarm_tuple = get_alarm_from_mmap(self.mmap_buf,16)
				SensorsInterface.setRTCCalarm(new_alarm_tuple[0],new_alarm_tuple[1],new_alarm_tuple[2],new_alarm_tuple[3],new_alarm_tuple[4],new_alarm_tuple[5],new_alarm_tuple[6])
				print "done setting the alarm"
				self.mmap_buf[1] = '0' #Clear NEW_ALARM
			
			#Altitude
			if self.mmap_altitude[0] == '1':
				#Send altitude data... but first set the BUSY byte
				self.mmap_altitude[1] = '1'
				#Get the Altitude data
				print "Getting altitude data"
				sensors['altitude'] = str(SensorsInterface.getAltitude())
				self.mmap_altitude[0] = '0' #The request has been completed
				self.mmap_altitude[1] = '0' #...and we are no longer busy
			
			#Pressure
			if self.mmap_pressure[0] == '1':
				#Send pressure data... but first set the BUSY byte
				self.mmap_pressure[1] = '1'
				#Get the Pressure data
				print "Getting pressure data"
				sensors['pressure'] = str(SensorsInterface.getBarometricPressure())
				self.mmap_pressure[0] = '0' #The request has been completed
				self.mmap_pressure[1] = '0' #...and we are no longer busy
			
			#Temperature
			if self.mmap_temperature[0] == '1':
				#Send temperature data... but first set the BUSY byte
				self.mmap_temperature[1] = '1'
				#Get the Temperature data
				print "Getting temperature data"
				sensors['temperature'] = str(SensorsInterface.getTemperature())
				self.mmap_temperature[0] = '0' #The request has been completed
				self.mmap_temperature[1] = '0' #...and we are no longer busy
			
			#AmbientLight
			if self.mmap_ambientlight[0] == '1':
				#Send temperature data... but first set the BUSY byte
				self.mmap_ambientlight[1] = '1'
				#Get the Ambient Light data
				print "Getting ambient light data"
				sensors['ambientlight'] = str(SensorsInterface.getAmbientLight())
				self.mmap_ambientlight[0] = '0' #The request has been completed
				self.mmap_ambientlight[1] = '0' #...and we are no longer busy
			
			sensors_lock.release()
			
			"""If there is new data stored in sensors --> sensors != {},
			then we should make this thread wait until it is sent to the
			socket. """
			if sensors != {}:
				data_ready_event.clear()
				data_ready_event.wait()
コード例 #2
0
def output_handler(pin, value):
    # Sensorian-led
    if pin == 0:
        if value == "1":
            SensorsInterface.ledOn()
        else:
            SensorsInterface.ledOff()

            # Sensorian-tft
    elif pin == 1:
        print "update sensorian-tft was called"
        # Check TFT availablity
        print "waiting for TFT_available_lock"
        TFT_available_lock.acquire()
        print "acquired TFT_available_lock"
        availability = TFT_available
        TFT_available_lock.release()
        print "released TFT_available_lock"
        if availability == False:
            print "dropping TFT write."
            return
        print "waiting for TFT_orientation_lock"
        TFT_orientation_lock.acquire()
        print "acquired TFT_orientation_lock"
        orientation = TFT_orientation
        # orientation = 1
        TFT_orientation_lock.release()
        print "released TFT_orientation_lock"
        print "Writing to tft"
        # tft_printer.screen_print(str(value))
        print "Trying to acquire TFT_Lock"
        TFT_Lock.acquire()
        print "Acquired TFT_Lock"
        my_tft_writer = TFT_Thread(value, orientation)
        my_tft_writer.start()
        print "End of output handler"

        # Sensorian-rtcc.time
    elif pin == 2:
        try:
            # Extract the time
            time = str(value).split(",")
            year = int(time[0])
            month = int(time[1])
            date = int(time[2])
            hour = int(time[3])
            minute = int(time[4])
            second = int(time[5])
            # Set the time
            SensorsInterface.setRTCCtime(year, month, date, hour, minute, second)
            print "Time has been set"
        except:
            print "Error setting the time"

            # Sensorian-rtcc.alarmtime
    elif pin == 3:
        try:
            # Extract the time and alarm mode
            time = str(value).split(",")
            year = int(time[0])
            month = int(time[1])
            date = int(time[2])
            hour = int(time[3])
            minute = int(time[4])
            second = int(time[5])
            mode = int(time[6])
            # Set the alarm
            SensorsInterface.setRTCCalarm(year, month, date, hour, minute, second, mode)
            print "Alarm time has been set"
        except:
            print "Error setting the alarm"

            # Sensorian-rtcc.resetalarm
    elif pin == 4:
        SensorsInterface.resetRTCCalarm()
コード例 #3
0
    def run(self):
        global sensors

        #self.flask_input = open('read_pipe','w')
        #self.flask_output = open('write_pipe','r')
        self.mmap_file = open('mmap_ipc', 'a+b')
        self.mmap_buf = mmap.mmap(self.mmap_file.fileno(),
                                  0,
                                  access=mmap.ACCESS_WRITE)

        self.mmap_altitude_file = open('/home/pi/.sensorian/mmap_altitude',
                                       'a+b')
        self.mmap_altitude = mmap.mmap(self.mmap_altitude_file.fileno(),
                                       0,
                                       access=mmap.ACCESS_WRITE)

        self.mmap_pressure_file = open('/home/pi/.sensorian/mmap_pressure',
                                       'a+b')
        self.mmap_pressure = mmap.mmap(self.mmap_pressure_file.fileno(),
                                       0,
                                       access=mmap.ACCESS_WRITE)

        self.mmap_temperature_file = open(
            '/home/pi/.sensorian/mmap_temperature', 'a+b')
        self.mmap_temperature = mmap.mmap(self.mmap_temperature_file.fileno(),
                                          0,
                                          access=mmap.ACCESS_WRITE)

        self.mmap_ambientlight_file = open(
            '/home/pi/.sensorian/mmap_ambientlight', 'a+b')
        self.mmap_ambientlight = mmap.mmap(
            self.mmap_ambientlight_file.fileno(), 0, access=mmap.ACCESS_WRITE)

        SensorsInterface.setupSensorian()

        #Setup a dummy alarm for now
        SensorsInterface.setRTCCtime(2016, 3, 4, 5, 33, 0)
        SensorsInterface.setRTCCalarm(2018, 1, 1, 1, 40, 20,
                                      1)  #MINUTES_MATCH mode

        prev_touchpad = SensorsInterface.getTouchpad()
        #prev_magnetometer = SensorsInterface.getMagnetometer()
        prev_magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
        prev_accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
        prev_alarmtrigger = SensorsInterface.pollRTCCalarm()
        while self.alive:
            sensors_lock.acquire()
            sensors = {}
            touchpad = SensorsInterface.getTouchpad()
            if touchpad != prev_touchpad:
                print "Touchpad: " + str(touchpad)
                #sensors_lock.acquire()
                sensors['touchpad'] = touchpad
                #sensors_lock.release()
            prev_touchpad = touchpad

            #magnetometer = SensorsInterface.getMagnetometer()
            magnetometer = mk_bin_tuple(SensorsInterface.getMagnetometer())
            if magnetometer != prev_magnetometer:
                print "Magnetometer: " + str(magnetometer)
                #sensors_lock.acquire()
                sensors['magnetometer'] = magnetometer
                #sensors_lock.release()
            prev_magnetometer = magnetometer

            accelerometer = mk_bin_tuple(SensorsInterface.getAccelerometer())
            if accelerometer != prev_accelerometer:
                print "Accelerometer: " + str(accelerometer)
                sensors['accelerometer'] = accelerometer
            prev_accelerometer = accelerometer

            alarmtrigger = SensorsInterface.pollRTCCalarm()
            if alarmtrigger != prev_alarmtrigger:
                print "Alarm Trigger: " + str(alarmtrigger)
                sensors['alarmtrigger'] = alarmtrigger
            prev_alarmtrigger = alarmtrigger

            #Poll flask_rtcc_interface.py for new updates to RTCC
            #print "polling flask_rtcc_interface.py"
            #self.flask_input.write("reqUpdate\n")
            #self.flask_input.flush()
            if self.mmap_buf[0] == '1':
                #Update the time
                new_time_tuple = get_time_from_mmap(self.mmap_buf, 2)
                SensorsInterface.setRTCCtime(
                    new_time_tuple[0], new_time_tuple[1], new_time_tuple[2],
                    new_time_tuple[3], new_time_tuple[4], new_time_tuple[5])
                print "done setting the time"
                self.mmap_buf[0] = '0'  #Clear NEW_TIME

            if self.mmap_buf[1] == '1':
                #Update the alarm
                new_alarm_tuple = get_alarm_from_mmap(self.mmap_buf, 16)
                SensorsInterface.setRTCCalarm(
                    new_alarm_tuple[0], new_alarm_tuple[1], new_alarm_tuple[2],
                    new_alarm_tuple[3], new_alarm_tuple[4], new_alarm_tuple[5],
                    new_alarm_tuple[6])
                print "done setting the alarm"
                self.mmap_buf[1] = '0'  #Clear NEW_ALARM

            #Altitude
            if self.mmap_altitude[0] == '1':
                #Send altitude data... but first set the BUSY byte
                self.mmap_altitude[1] = '1'
                #Get the Altitude data
                print "Getting altitude data"
                sensors['altitude'] = str(SensorsInterface.getAltitude())
                self.mmap_altitude[0] = '0'  #The request has been completed
                self.mmap_altitude[1] = '0'  #...and we are no longer busy

            #Pressure
            if self.mmap_pressure[0] == '1':
                #Send pressure data... but first set the BUSY byte
                self.mmap_pressure[1] = '1'
                #Get the Pressure data
                print "Getting pressure data"
                sensors['pressure'] = str(
                    SensorsInterface.getBarometricPressure())
                self.mmap_pressure[0] = '0'  #The request has been completed
                self.mmap_pressure[1] = '0'  #...and we are no longer busy

            #Temperature
            if self.mmap_temperature[0] == '1':
                #Send temperature data... but first set the BUSY byte
                self.mmap_temperature[1] = '1'
                #Get the Temperature data
                print "Getting temperature data"
                sensors['temperature'] = str(SensorsInterface.getTemperature())
                self.mmap_temperature[0] = '0'  #The request has been completed
                self.mmap_temperature[1] = '0'  #...and we are no longer busy

            #AmbientLight
            if self.mmap_ambientlight[0] == '1':
                #Send temperature data... but first set the BUSY byte
                self.mmap_ambientlight[1] = '1'
                #Get the Ambient Light data
                print "Getting ambient light data"
                sensors['ambientlight'] = str(
                    SensorsInterface.getAmbientLight())
                self.mmap_ambientlight[
                    0] = '0'  #The request has been completed
                self.mmap_ambientlight[1] = '0'  #...and we are no longer busy

            sensors_lock.release()
            """If there is new data stored in sensors --> sensors != {},
			then we should make this thread wait until it is sent to the
			socket. """
            if sensors != {}:
                data_ready_event.clear()
                data_ready_event.wait()
コード例 #4
0
def output_handler(pin, value):
    #Sensorian-led
    if pin == 0:
        if value == "1":
            SensorsInterface.ledOn()
        else:
            SensorsInterface.ledOff()

    #Sensorian-tft
    elif pin == 1:
        print "update sensorian-tft was called"
        #Check TFT availablity
        print "waiting for TFT_available_lock"
        TFT_available_lock.acquire()
        print "acquired TFT_available_lock"
        availability = TFT_available
        TFT_available_lock.release()
        print "released TFT_available_lock"
        if availability == False:
            print "dropping TFT write."
            return
        print "waiting for TFT_orientation_lock"
        TFT_orientation_lock.acquire()
        print "acquired TFT_orientation_lock"
        orientation = TFT_orientation
        #orientation = 1
        TFT_orientation_lock.release()
        print "released TFT_orientation_lock"
        print "Writing to tft"
        #tft_printer.screen_print(str(value))
        print "Trying to acquire TFT_Lock"
        TFT_Lock.acquire()
        print "Acquired TFT_Lock"
        my_tft_writer = TFT_Thread(value, orientation)
        my_tft_writer.start()
        print "End of output handler"

    #Sensorian-rtcc.time
    elif pin == 2:
        try:
            #Extract the time
            time = str(value).split(",")
            year = int(time[0])
            month = int(time[1])
            date = int(time[2])
            hour = int(time[3])
            minute = int(time[4])
            second = int(time[5])
            #Set the time
            SensorsInterface.setRTCCtime(year, month, date, hour, minute,
                                         second)
            print "Time has been set"
        except:
            print "Error setting the time"

    #Sensorian-rtcc.alarmtime
    elif pin == 3:
        try:
            #Extract the time and alarm mode
            time = str(value).split(",")
            year = int(time[0])
            month = int(time[1])
            date = int(time[2])
            hour = int(time[3])
            minute = int(time[4])
            second = int(time[5])
            mode = int(time[6])
            #Set the alarm
            SensorsInterface.setRTCCalarm(year, month, date, hour, minute,
                                          second, mode)
            print "Alarm time has been set"
        except:
            print "Error setting the alarm"

    #Sensorian-rtcc.resetalarm
    elif pin == 4:
        SensorsInterface.resetRTCCalarm()