def notifications(self, callback=None): """Subscribe or unsubscribe to accelerometer notifications. Convenience method for handling gpio usage. Example: .. code-block:: python def handle_gpio_notification(data) # Handle a (epoch_time, int value) type. epoch = data[0] value = data[1] print("[{0}] value: {1}".format(epoch, *value)) mwclient.gpio.notifications(handle_gpio_notification) :param callable callback: Gpio notification callback function. If `None`, unsubscription to accelerometer notifications is registered. """ if callback is None: self.stop() super(GpioModule, self).notifications(None) else: super(GpioModule, self).notifications(data_handler(callback)) self.start()
def notifications(self, callback=None): """Subscribe or unsubscribe to notifications. Convenience method for handling ambient light sensor usage. Example: .. code-block:: python def al_callback(data): print(data) mwclient.ambient_light.notifications(al_callback) :param callable callback: Ambient Light notification callback function. If `None`, unsubscription to ambient light notifications is registered. """ if callback is None: super(AmbientLightModule, self).notifications(None) self.stop() else: super(AmbientLightModule, self).notifications( data_handler(callback)) self.start()
def notifications(self, callback=None): """Subscribe or unsubscribe to switch notifications. Convenience method for handling switch usage. Example: .. code-block:: python def switch_callback(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] value = data["value"] if value == 1: print("[{0}] Switch pressed!".format(epoch)) elif status == 0: print("[{0}] Switch released!".format(epoch)) mwclient.switch.notifications(switch_callback) :param callable callback: Switch notification callback function. If `None`, unsubscription to switch notifications is registered. """ super(SwitchModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, callback=None): """Subscribe or unsubscribe to gyroscope notifications. Convenience method for handling gyroscope usage. Example: .. code-block:: python def handle_notification(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.gyroscope.notifications(handle_notification) :param callable callback: Gyroscope notification callback function. If `None`, unsubscription to gyroscope notifications is registered. """ if callback is None: self.stop() self.toggle_sampling(False) super(GyroscopeModule, self).notifications(None) else: super(GyroscopeModule, self).notifications(data_handler(callback)) self.toggle_sampling(True) self.start()
def notifications(self, callback=None): """Subscribe to or unsubscribe from barometer notifications. Convenience method for handling barometer usage. Example: .. code-block:: python def handle_barometer_notification(data) # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] value = data["value"] print(data) mwclient.barometer.notifications(handle_barometer_notification) :param callable callback: Barometer notification callback function. If `None`, unsubscription to barometer notifications is registered. """ if callback is None: self.stop() super(BarometerModule, self).notifications(None) else: super(BarometerModule, self).notifications(data_handler(callback)) self.start()
def notifications(self, callback=None): """Subscribe or unsubscribe to switch notifications. Convenience method for handling switch usage. Example: .. code-block:: python def switch_callback(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] value = data["value"] if value == 1: print("[{0}] Switch pressed!".format(epoch)) elif status == 0: print("[{0}] Switch released!".format(epoch)) mwclient.switch.notifications(switch_callback) :param callable callback: Switch notification callback function. If `None`, unsubscription to switch notifications is registered. """ super(SwitchModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, callback=None): """Subscribe or unsubscribe to battery notifications. Convenience method for handling battery notifications. The data to the callback method comes as a tuple of two integer values, the first one representing the voltage and the second one is an integer in [0, 100] representing battery percentage. Example: .. code-block:: python def battery_callback(data): epoch = data[0] battery = data[1] print("[{0}] Voltage: {1}, Charge: {2}".format( epoch, battery[0], battery[1])) mwclient.settings.notifications(battery_callback) mwclient.settings.read_battery_state() :param callable callback: Battery data notification callback function. If `None`, unsubscription to battery notifications is registered. """ super(SettingsModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, callback=None): """Subscribe or unsubscribe to gyroscope notifications. Convenience method for handling gyroscope usage. Example: .. code-block:: python def handle_notification(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.gyroscope.notifications(handle_notification) :param callable callback: Gyroscope notification callback function. If `None`, unsubscription to gyroscope notifications is registered. """ if callback is None: self.stop() self.toggle_sampling(False) super(GyroscopeModule, self).notifications(None) else: super(GyroscopeModule, self).notifications(data_handler(callback)) self.toggle_sampling(True) self.start()
def notifications(self, callback=None): """Subscribe or unsubscribe to notifications. Convenience method for handling ambient light sensor usage. Example: .. code-block:: python def al_callback(data): print(data) mwclient.ambient_light.notifications(al_callback) :param callable callback: Ambient Light notification callback function. If `None`, unsubscription to ambient light notifications is registered. """ if callback is None: super(AmbientLightModule, self).notifications(None) self.stop() else: super(AmbientLightModule, self).notifications(data_handler(callback)) self.start()
def notifications(self, callback=None): """Subscribe or unsubscribe to battery notifications. Convenience method for handling battery notifications. The data to the callback method comes as a tuple of two integer values, the first one representing the voltage and the second one is an integer in [0, 100] representing battery percentage. Example: .. code-block:: python def battery_callback(data): epoch = data[0] battery = data[1] print("[{0}] Voltage: {1}, Charge: {2}".format( epoch, battery[0], battery[1])) mwclient.settings.notifications(battery_callback) mwclient.settings.read_battery_state() :param callable callback: Battery data notification callback function. If `None`, unsubscription to battery notifications is registered. """ super(SettingsModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, callback=None): """Subscribe or unsubscribe to temperature notifications. Convenience method for handling temperature usage. Example: .. code-block:: python def temperature_callback(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.temperature_func.notifications(temperature_callback) :param callable callback: Temperature notification callback function. If `None`, unsubscription to temperature_func notifications is registered. """ super(TemperatureModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, callback=None): """Subscribe or unsubscribe to temperature notifications. Convenience method for handling temperature usage. Example: .. code-block:: python def temperature_callback(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.temperature_func.notifications(temperature_callback) :param callable callback: Temperature notification callback function. If `None`, unsubscription to temperature_func notifications is registered. """ super(TemperatureModule, self).notifications( data_handler(callback) if callback is not None else None)
def notifications(self, corrected_acc_callback=None, corrected_gyro_callback=None, corrected_mag_callback=None, quaternion_callback=None, euler_angle_callback=None, gravity_callback=None, linear_acc_callback=None, calibration_state_callback=None): """Subscribe or unsubscribe to sensor fusion notifications. Convenience method for handling sensor fusion usage. Example: .. code-block:: python def handle_notification(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.sensorfusion.notifications( corrected_acc_callback=handle_notification) :param callable corrected_acc_callback: Acceleration notification callback function. If `None`, unsubscription to acceleration notifications is registered. :param callable corrected_gyro_callback: Gyroscope notification callback function. If `None`, unsubscription to gyroscope notifications is registered. :param callable corrected_mag_callback: Magnetometer notification callback function. If `None`, unsubscription to magnetometer notifications is registered. :param callable quaternion_callback: Quaternion notification callback function. If `None`, unsubscription to quaternion notifications is registered. :param callable euler_angle_callback: Euler angle notification callback function. If `None`, unsubscription to euler angle notifications is registered. :param callable gravity_callback: Gravity vector notification callback function. If `None`, unsubscription to gravity notifications is registered. :param callable linear_acc_callback: Linear acceleration notification callback function. If `None`, unsubscription to linear acceleration notifications is registered. :param callable calibration_state_callback: Calibration state notification callback function. If `None`, unsubscription to calibration state notifications is registered. """ callback_data_source_map = { SensorFusionData.CORRECTED_ACC: corrected_acc_callback, SensorFusionData.CORRECTED_GYRO: corrected_gyro_callback, SensorFusionData.CORRECTED_MAG: corrected_mag_callback, SensorFusionData.QUATERNION: quaternion_callback, SensorFusionData.EULER_ANGLE: euler_angle_callback, SensorFusionData.GRAVITY_VECTOR: gravity_callback, SensorFusionData.LINEAR_ACC: linear_acc_callback } for data_source in callback_data_source_map: if callback_data_source_map[data_source] is not None: self._streams_to_enable[data_source] = True else: self._streams_to_enable[data_source] = False enable = False in [ x is None for x in callback_data_source_map.values() ] log.debug("Enable: %s" % enable) self._calibration_state_callback = calibration_state_callback if not enable: self.stop() self.toggle_sampling(False) for data_source in callback_data_source_map: self.current_active_signal = self.get_data_signal(data_source) callback = callback_data_source_map[data_source] if callback is not None: self.check_and_change_callback( self.get_data_signal(data_source), data_handler(callback)) else: self.check_and_change_callback( self.get_data_signal(data_source), None) if calibration_state_callback is not None: self.check_and_change_callback( self.get_calibration_state_data_signal(), data_handler(calibration_state_callback)) else: self.check_and_change_callback( self.get_calibration_state_data_signal(), None) if enable: self.toggle_sampling(True) self.start()
def notifications(self, corrected_acc_callback=None, corrected_gyro_callback=None, corrected_mag_callback=None, quaternion_callback=None, euler_angle_callback=None, gravity_callback=None, linear_acc_callback=None, calibration_state_callback=None): """Subscribe or unsubscribe to sensor fusion notifications. Convenience method for handling sensor fusion usage. Example: .. code-block:: python def handle_notification(data): # Handle dictionary with [epoch, value] keys. epoch = data["epoch"] xyz = data["value"] print(str(data)) mwclient.sensorfusion.notifications( corrected_acc_callback=handle_notification) :param callable corrected_acc_callback: Acceleration notification callback function. If `None`, unsubscription to acceleration notifications is registered. :param callable corrected_gyro_callback: Gyroscope notification callback function. If `None`, unsubscription to gyroscope notifications is registered. :param callable corrected_mag_callback: Magnetometer notification callback function. If `None`, unsubscription to magnetometer notifications is registered. :param callable quaternion_callback: Quaternion notification callback function. If `None`, unsubscription to quaternion notifications is registered. :param callable euler_angle_callback: Euler angle notification callback function. If `None`, unsubscription to euler angle notifications is registered. :param callable gravity_callback: Gravity vector notification callback function. If `None`, unsubscription to gravity notifications is registered. :param callable linear_acc_callback: Linear acceleration notification callback function. If `None`, unsubscription to linear acceleration notifications is registered. :param callable calibration_state_callback: Calibration state notification callback function. If `None`, unsubscription to calibration state notifications is registered. """ callback_data_source_map = { SensorFusionData.CORRECTED_ACC: corrected_acc_callback, SensorFusionData.CORRECTED_GYRO: corrected_gyro_callback, SensorFusionData.CORRECTED_MAG: corrected_mag_callback, SensorFusionData.QUATERNION: quaternion_callback, SensorFusionData.EULER_ANGLE: euler_angle_callback, SensorFusionData.GRAVITY_VECTOR: gravity_callback, SensorFusionData.LINEAR_ACC: linear_acc_callback } for data_source in callback_data_source_map: if callback_data_source_map[data_source] is not None: self._streams_to_enable[data_source] = True else: self._streams_to_enable[data_source] = False enable = False in [x is None for x in callback_data_source_map.values()] log.debug("Enable: %s" % enable) self._calibration_state_callback = calibration_state_callback if not enable: self.stop() self.toggle_sampling(False) for data_source in callback_data_source_map: self.current_active_signal = self.get_data_signal(data_source) callback = callback_data_source_map[data_source] if callback is not None: self.check_and_change_callback( self.get_data_signal(data_source), data_handler(callback) ) else: self.check_and_change_callback( self.get_data_signal(data_source), None ) if calibration_state_callback is not None: self.check_and_change_callback( self.get_calibration_state_data_signal(), data_handler(calibration_state_callback)) else: self.check_and_change_callback( self.get_calibration_state_data_signal(), None) if enable: self.toggle_sampling(True) self.start()