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
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
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
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 stop(self): if self.working: gravity.disable()
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)