Settings module¶
Battery submodule¶
The PyMetaWear implementation of the libmetawear
switch module.
It is initialized at the creation of the MetaWearClient
client and can then be accessed in the settings
attribute of the client.
Example usage:
from pymetawear.client import MetaWearClient
c = MetaWearClient('DD:3A:7D:4D:56:F0')
def battery_callback(data):
"""Handle a battery status tuple."""
print("Voltage: {0}, Charge: {1}".format(
data[0], data[1]))
# Enable notifications and register a callback for them.
mwclient.settings.notifications(battery_callback)
# Trigger battery status notification.
mwclient.settings.read_battery_state()
API¶
Settings module¶
Created by hbldh <henrik.blidh@nedomkull.com> on 2016-04-14
-
class
pymetawear.modules.settings.
SettingsModule
(board)[source]¶ MetaWear Settings module implementation.
Parameters: - board (ctypes.c_long) – The MetaWear board pointer value.
- debug (bool) – If
True
, module prints out debug information.
-
data_signal
¶ Returns the data signal pointer value for the switch module.
Returns: The pointer value. (Long if on x64 architecture.) Return type: ctypes.c_long
orctypes.c_int
-
disconnected_event
()[source]¶ Create a disconnect event.
Convenience method for sending commands during a disconnect event.
-
module_name
¶ Get module name.
Returns: The name of this module. Return type: str
-
notifications
(callback=None)[source]¶ 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:
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()
Parameters: callback (callable) – Battery data notification callback function. If None, unsubscription to battery notifications is registered.
-
read_battery_state
()[source]¶ Triggers a battery state notification.
N.B. that a
notifications()
call that registers a callback for battery state should have been done prior to calling this method.
-
sensor_name
¶ Get sensor name, if applicable.
Returns: The name of this module. Return type: str or None