def build(self): if platform == "android": from android import AndroidService service = AndroidService('desire sensors service', 'running') service.start('service started') self.service = service status_page = StatusPage() accelerometer.enable() compass.enable() self.gps = gps self.gps.configure(on_location=self.on_gps_location, on_status=self.on_gps_status) self.gps.start() notification.notify(title="Hello", message="Just Checking") #vibrator.vibrate(0.2) # vibrate for 0.2 seconds print("Hello World") status_page.gps_data = self.gps_data # Clock.schedule_interval(status_page.update, 1.0 / 10.0) # 10H Clock.schedule_interval(status_page.update, 1.0) # 1Hz button = Button(text='Service', size_hint=(0.12, 0.12)) button.bind(on_press=self.callback) status_page.add_widget(button) switch = Switch() switch.bind(active=self.callback) status_page.add_widget(switch) return status_page
def build(self): if platform == "android": from android import AndroidService service = AndroidService('desire sensors service', 'running') service.start('service started') self.service = service status_page = StatusPage() accelerometer.enable() compass.enable() self.gps = gps self.gps.configure(on_location=self.on_gps_location, on_status=self.on_gps_status) self.gps.start() notification.notify(title="Hello",message="Just Checking") #vibrator.vibrate(0.2) # vibrate for 0.2 seconds print("Hello World") status_page.gps_data = self.gps_data # Clock.schedule_interval(status_page.update, 1.0 / 10.0) # 10H Clock.schedule_interval(status_page.update, 1.0) # 1Hz button=Button(text='Service',size_hint=(0.12,0.12)) button.bind(on_press=self.callback) status_page.add_widget(button) switch = Switch() switch.bind(active=self.callback) status_page.add_widget(switch) return status_page
def build(self): status_page = StatusPage() # Startup the "cheap" sensors try: accelerometer.enable() compass.enable() except: pass Clock.schedule_interval(status_page.update, UPDATE_FREQ) #vibrator.vibrate(0.2) # vibrate for 0.2 seconds return status_page
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")
def Encender(self, *args): Mensaje1 = "\nSe esta encendiendo el sensor de campo magnetico\n" Mensaje2 = "\nSensor de campo magnetico encendido\n" Mensaje3 = "\nFallo al activar el sensor de campo magnetico\n" print Mensaje1 try: compass.enable() print Mensaje2 return True except: print Mensaje3 return False pass
def build(self): status_page = StatusPage() # Startup the "cheap" sensors try: accelerometer.enable() compass.enable() except: pass Clock.schedule_interval(status_page.update, UPDATE_FREQ) #vibrator.vibrate(0.2) # vibrate for 0.2 seconds return status_page
def connect(self): ip = self.ip_field.text if re.match(r'\d+\.\d+\.\d+\.\d+', ip): try: global s s = socket.socket() s.connect((ip, 8080)) compass.enable() self.parent.current = "clicks" except Exception: self.info_label.text = "Unable to connect" else: self.info_label.text = "Incorrect IP"
def do_toggle(self): try: if not self.sensorEnabled: compass.enable() Clock.schedule_interval(self.get_readings, 1 / 20.) self.sensorEnabled = True self.ids.toggle_button.text = "Stop compass" else: compass.disable() Clock.unschedule(self.get_readings) self.sensorEnabled = False self.ids.toggle_button.text = "Start compass" except NotImplementedError: import traceback; traceback.print_exc() self.ids.status.text = "Compass is not implemented for your platform"
def do_toggle(self): try: if not self.sensorEnabled: compass.enable() Clock.schedule_interval(self.get_readings, 1 / 20.) self.sensorEnabled = True self.ids.toggle_button.text = "Stop compass" else: compass.disable() Clock.unschedule(self.get_readings) self.sensorEnabled = False self.ids.toggle_button.text = "Start compass" except NotImplementedError: import traceback traceback.print_exc() self.ids.status.text = "Compass is not implemented for your platform"
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)
def __init__(self,gui): self.gui = gui self.boat = {} self.sensorsList = [] self.th = TimeHelper() self.fa = FileActions() self.playingFromFile = False self.FromFile = "" self.FromFileData = {} self.replayFps = 60 self.filesToPlay = self.fa.getFileList( self.gui.workingFolderAdress ) print("files to play --\ \n",str(self.filesToPlay)) sPlaFroFil = Spinner( values = list(self.filesToPlay), text = "play from file:", size_hint = (None,None), size = (self.gui.btH*4,self.gui.btH) ) sPlaFroFil.bind(text=self.on_PlaFroFile) bl = self.gui.rl.ids.bl_sensorsPlaFroFil bl.add_widget(sPlaFroFil) print("new Spinner with updated list DONE") #self.wHeelBoat = waveCicleHolder(gui,'boat_heel') self.calibrateStep = 0 self.recordToFile = "ready" self.toFileList = [] self.mic = micData(gui) #self.mic.runIt() self.device = deviceSensors(gui) self.sensorsList.append( self.device ) self.device.initSensors() self.gpsD = gpsData(gui, { 'lat': self.gui.rl.ids.senLGpsLat, 'lon': self.gui.rl.ids.senLGpsLon, 'sog': self.gui.rl.ids.senLGpsSog, 'lSRacSog': self.gui.rl.ids.lSRacSog, 'lSRacSogMax': self.gui.rl.ids.lSRacSogMax, 'lSRacSogAvg': self.gui.rl.ids.lSRacSogAvg, 'cog': self.gui.rl.ids.senLGpsCog, 'accur': self.gui.rl.ids.senLGpsAcc }) self.sensorsList.append( self.gpsD ) self.gyro = xyzData(gui, "gyro", [ self.gui.rl.ids.senLGyrX, self.gui.rl.ids.senLGyrY, self.gui.rl.ids.senLGyrZ ]) self.sensorsList.append( self.gyro ) self.gyroFlipt = xyzData(gui, "gyroFlipt",[ self.gui.rl.ids.senLGyrCalX, self.gui.rl.ids.senLGyrCalY, self.gui.rl.ids.senLGyrCalZ ]) self.sensorsList.append( self.gyroFlipt ) self.accel = xyzData(gui, "accel", [ self.gui.rl.ids.senLAccX, self.gui.rl.ids.senLAccY, self.gui.rl.ids.senLAccZ ]) self.sensorsList.append( self.accel ) self.spacialOrientation = xyzData(gui, "spacorientation", [ self.gui.rl.ids.senLSpaOriX, self.gui.rl.ids.senLSpaOriY, self.gui.rl.ids.senLSpaOriZ ]) self.sensorsList.append( self.spacialOrientation ) self.accelFlipt = xyzData(gui, "accelFlipt") self.sensorsList.append( self.accelFlipt ) self.orientation = xyzData(gui, "orientation") self.sensorsList.append( self.orientation ) self.comCal = xyzData(gui, "comCal", [ self.gui.rl.ids.senLComCalX, self.gui.rl.ids.senLComCalY, self.gui.rl.ids.senLComCalZ ]) self.sensorsList.append( self.comCal ) self.comCalAccelGyro = xyzData(gui, "comCalAccelGyro") self.sensorsList.append( self.comCalAccelGyro ) 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 ... gyroscope ...") try: gyroscope.enable() print(" gyroscope OK") except: print("no accelerometers") print("trying ... compass calibrated...") try: compass.enable() print(" compass calibrated OK") except: print("no compass calibrated")
def Encender(self, *args): print "Se esta encendiendo" compass.enable()