def _process_send_queue(self, timeout): """Process commands to be sent from the queue synchronously. Commands are sent sequentially. :param int timeout: The amount of time to wait between executions in milliseconds. :raises: raspy.object_disposed_exception.ObjectDisposedException if this instance has been disposed. """ if (not self.__ready or self.__sendQueue is None or len(self.__sendQueue) == 0): return self.__ready = False if timeout is None: timeout = 0 # TODO should we do this in a thread? for _ in itertools.repeat(None, len(self.__sendQueue)): cmd = self.__sendQueue.pop(0) # Grab the first item in the queue. if cmd is not None: self.send_command(cmd) core_utils.sleep(timeout) self.__ready = True
def read_gyro(self): """Read the gyro and store the value internally. :raise: raspy.object_disposed_exception.ObjectDisposedException if this instance has been disposed. :raises: raspy.io.io_exception.IOException if unable to write to the gyro. """ if self.is_disposed: raise ObjectDisposedException("ADXL345") now = system_info.get_current_time_millis() self.__timeDelta = now - self.__lastRead self.__lastRead = now self.__device.write_byte(self.__address, 0x00) core_utils.sleep(10) data = self.__device.read_bytes(self.__address, 6) if len(data) != 6: msg = "Couldn't read compass data; Return buffer size: " msg += str(len(data)) raise IOException(msg) self.a_x.raw_value = ((data[0] & 0xff) << 8) + (data[1] & 0xff) self.a_y.raw_value = ((data[2] & 0xff) << 8) + (data[3] & 0xff) self.a_z.raw_value = ((data[3] & 0xff) << 8) + (data[5] & 0xff)
def _execute_poll(self): """Execute the poll cycle.""" while not self.__stopEvent.is_set(): new_state = self.state if new_state != self.__lastState: old_state = self.__lastState self.__lastState = new_state evt = SensorStateChangeEvent(self, old_state, new_state) self.on_sensor_state_change(evt) core_utils.sleep(200)
def _execute_poll(self): """Execute the poll cycle.""" while not self.__stopEvent.is_set(): detected = self.is_motion_detected if detected != self.__lastCheckDetected: self.__lastCheckDetected = detected now = datetime.now() evt = MotionDetectedEvent(self.__lastCheckDetected, now) self.on_motion_state_changed(evt) core_utils.sleep(500)
def _execute_poll(self): """Execute the poll cycle.""" while not self.__stopEvent.is_set(): new_temp = self.get_raw_temperature() if new_temp != self.__lastTemp: old_temp = self.__lastTemp self.__lastTemp = new_temp evt = TempChangeEvent(old_temp, new_temp) self.on_temperature_change(evt) core_utils.sleep(200)
def cancel(self): """Cancel the still capture process, if running. Should emit EVENT_CAPTURE_DONE and include the termination signal. """ if not self.__isRunning: return self.__syncLock.acquire() self.__isRunning = False self.__syncLock.release() core_utils.sleep(500) if self.__captureProc is not None: if self.__captureProc.poll() is not None: try: self.__captureProc.kill() except OSError: # Process probably already died. pass
def _execute_poll(self): """Execute the poll cycle.""" while not self.__stopEvent.is_set(): self.__pin.read() core_utils.sleep(500)