def __init__(self, **kwargs):
        super().__init__(**kwargs)
        accelerometer.enable()
        gyroscope.enable()
        gravity.enable()
        self.cols = 2
        if os.path.isfile("prev_details.txt"):
            with open("prev_details.txt", "r") as f:
                d = f.read().split(",")
                prev_ip = d[0]
                prev_port = d[1]
                prev_username = d[2]
        else:
            prev_ip = ''
            prev_port = ''
            prev_username = ''

        self.add_widget(Label(text='IP:', font_size=60))
        self.ip = TextInput(text=prev_ip, multiline=False, font_size=40)
        self.add_widget(self.ip)
        self.add_widget(Label(text='Port:', font_size=60))
        self.port = TextInput(text=prev_port, multiline=False, font_size=40)
        self.add_widget(self.port)

        self.add_widget(Label(text='Username:', font_size=60))
        self.username = TextInput(text=prev_username,
                                  multiline=False,
                                  font_size=40)
        self.add_widget(self.username)

        self.join = Button(text="Join", font_size=60)
        self.join.bind(on_press=self.join_button)
        self.add_widget(Label())
        self.add_widget(self.join)
Exemple #2
0
 def do_toggle(self):
     if not self.sensorEnabled:
         gravity.enable()
         Clock.schedule_interval(self.get_gravity, refresh_rate)
         self.sensorEnabled = True
     else:
         gravity.disable()
         Clock.unschedule(self.get_gravity)
         self.sensorEnabled = False
Exemple #3
0
    def is_implemented(self):
        try:
            gravity.enable()
            print(gravity.gravity[:3])

            gravity.disable()
            return True
        except:
            # import traceback
            # traceback.print_exc()
            print('Gravity is not implemented for your platform')
            return False
Exemple #4
0
 def askForPermissions(self):
     if kivy.platform == 'android':
         #self.request_android_permissions2()
         print("trying ... gps ...")
         try:
             gps.configure( 
                 on_location=self.on_gps_location,
                 on_status=self.on_gps_status
                 )
             self.request_android_permissions1()
             print("    gps OK")
         except:
             print("no gps :(")
             
             
         print("trying ... accelerometers ...")
         try:
             accelerometer.enable()
             print("    accelerometers OK")
         except:
             print("no accelerometers")
             
             
         print("trying ... spacial orientation ...")
         try:
             spatialorientation.enable_listener()
             print("    spacial orientation OK")
         except:
             print("no spacial orientation")
             
         print("trying ... gravity ...")    
         try:
             gravity.enable()
             print("    gravity OK")
         except:
             print("no gravity")
             
             
             
         print("trying ... gyroscope ...")
         try:
             gyroscope.enable()
             print("    gyroscope OK")
         except:
             print("no gyroscope")
     
         print("trying ... compass calibrated...")
         try:
             compass.enable()
             print("    compass calibrated OK")
         except:
             print("no compass calibrated")
Exemple #5
0
 def build(self):
     try:
         gravity.enable()
         compass.enable()
         gps.configure(self.on_location, on_status=None)
     except:
         print("GPS, Compass or Gravity sensors not implemented")
     try:
         nbrick = bluesock.BlueSock(address).connect()
         on_connect(nbrick)
     except:
         print("Cant connect to NXT")
     return Button(text='hello world')
Exemple #6
0
    def do_toggle(self):
        try:
            if not self.sensorEnabled:
                gravity.enable()
                Clock.schedule_interval(self.get_gravity, 1 / 10.)

                self.sensorEnabled = True
                self.ids.toggle_button.text = "Stop Gravity Sensor"
            else:
                gravity.disable()
                Clock.unschedule(self.get_gravity)

                self.sensorEnabled = False
                self.ids.toggle_button.text = "Start Gravity Sensor"
        except NotImplementedError:
            import traceback
            traceback.print_exc()
            status = "Gravity sensor is not implemented " \
                     "for your platform"
            self.ids.status.text = status
Exemple #7
0
    def do_toggle(self):
        try:
            if not self.sensorEnabled:
                gravity.enable()
                Clock.schedule_interval(self.get_gravity, 1 / 20.)

                self.sensorEnabled = True
                self.ids.toggle_button.text = "Stop Gravity Sensor"
            else:
                gravity.disable()
                Clock.unschedule(self.get_gravity)

                self.sensorEnabled = False
                self.ids.toggle_button.text = "Start Gravity Sensor"
        except NotImplementedError:
            import traceback
            traceback.print_exc()
            status = "Gravity sensor is not implemented " \
                     "for your platform"
            self.ids.status.text = status
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        accelerometer.enable()
        gyroscope.enable()
        gravity.enable()
        self.cols = 1
        self.AcceX = ''
        self.AcceY = ''
        self.AcceZ = ''
        self.gryX = ''
        self.gryY = ''
        self.gryZ = ''
        self.graX = ''
        self.graY = ''
        self.graZ = ''

        self.event = Clock.schedule_interval(self.update, 1.0 / 10)
        self.event()
        self.add_widget(
            Label(text="SENDING ACCELEROMETER DATA...", font_size=60))
        self.add_widget(
            Label(text="Press STOP to stop sending accelerometer data",
                  font_size=30))

        self.stop = Button(text="STOP",
                           font_size=60,
                           size_hint_y=None,
                           height=100)
        self.stop.bind(on_press=self.stop_client)
        self.add_widget(self.stop)

        self.back = Button(text="Back",
                           font_size=60,
                           size_hint_y=None,
                           height=100)
        self.back.bind(on_press=self.backbutton)
        self.add_widget(self.back)
Exemple #9
0
 def start(self):
     if self.working:
         gravity.enable()
Exemple #10
0
	def publish_terminal(self, terminal, _data_queue):
		terminal.insert_text("\n")
  
		if (platform == 'android') or (platform == 'ios'):
			try:
				vibrator.vibrate(1)
			except:
				pass

			#Accelerometer
			if self._data_object.get("sensor") == "Accelerometer":
				try:
					accelerometer.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								accelerometer.disable()
							except:
								pass
							break
					if None in accelerometer.acceleration:
						pass
					else:
						payload_hash = hashlib.md5(str(accelerometer.acceleration).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(accelerometer.acceleration)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(accelerometer.acceleration)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.1)
			#Compass
			elif self._data_object.get("sensor") == "Compass":
				try:
					compass.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								compass.disable()
							except:
								pass
							break
					if None in compass.field:
						pass
					else:
						payload_hash = hashlib.md5(str(compass.field).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(compass.field)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(compass.field)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.1)
			#GPS
			elif self._data_object.get("sensor") == "GPS":
				try:
					gps.configure(on_location=self.on_location, on_status=self.on_status)
					gps.start(1000, 0)
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gps.stop()
							except:
								pass
							break
					if self.gps_location is None:
						pass
					else:
						payload_hash = hashlib.md5(str(self.gps_location).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = str(self.gps_location)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(3)
						else:
							payload = str(self.gps_location)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
							time.sleep(0.5)
			#Barometer
			elif self._data_object.get("sensor") == "Barometer":
				try:
					barometer.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								barometer.disable()
							except:
								pass
							break
					if barometer.pressure is None:
						pass
					else:
						payload_hash = hashlib.md5(str(barometer.pressure).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "hPa: " + str(barometer.pressure)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "hPa: " + str(barometer.pressure)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
			#Gravity
			elif self._data_object.get("sensor") == "Gravity":
				try:
					gravity.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gravity.disable()
							except:
								pass
							break
					if None in gravity.gravity:
						pass
					else:
						payload_hash = hashlib.md5(str(gravity.gravity).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(gravity.gravity)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
							payload = "(x, y, z): " + str(gravity.gravity)
							terminal.insert_text(payload + "\n")
							if (self._data_object.get("protocol") != "terminal"):
								try:
									terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
								except Exception as _exp:
									terminal.insert_text("Exception: " + str(_exp) + "\n")
									return
			#Gyroscope
			elif self._data_object.get("sensor") == "Gyroscope":
				try:
					gyroscope.enable()
				except Exception as _exp:
					terminal.insert_text("Exception: " + str(_exp) + "\n")
					return
				previous_payload_hash = None	
				while True:
					if _data_queue.empty() is False:
						qdata = _data_queue.get()
						if qdata == "exit":
							try:
								gyroscope.disable()
							except:
								pass
							break
					if None in gyroscope.rotation:
						pass
					else:
						payload_hash = hashlib.md5(str(gyroscope.rotation).encode('utf-8')).hexdigest()
						if (previous_payload_hash is not None):
							if (previous_payload_hash == payload_hash):
								pass
							else:
								previous_payload_hash = payload_hash
								payload = "(x, y, z): " + str(gyroscope.rotation)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
								time.sleep(0.1)
						else:
								payload = "(x, y, z): " + str(gyroscope.rotation)
								terminal.insert_text(payload + "\n")
								if (self._data_object.get("protocol") != "terminal"):
									try:
										terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
									except Exception as _exp:
										terminal.insert_text("Exception: " + str(_exp) + "\n")
										return
			else:
				pass
		else:
			while True:
				if _data_queue.empty() is False:
					qdata = _data_queue.get()
					if qdata == "exit":
						break
				payload = "time: " + str(time.strftime("%c", time.gmtime()))
				terminal.insert_text(payload + "\n")
				if (self._data_object.get("protocol") != "terminal"):
					try:
						terminal.insert_text("xmit status: " + self.xmit_payload(payload) + "\n")
					except Exception as _exp:
						terminal.insert_text("Exception: " + str(_exp) + "\n")
						return
				time.sleep(2)