Switch module

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 switch attribute of the client.

Example usage:

from pymetawear.client import MetaWearClient

c = MetaWearClient('DD:3A:7D:4D:56:F0')

def switch_callback(data):
    """Handle a switch status integer (1 for pressed, 0 for released.)."""
    if data == 1:
        print("Switch pressed!")
    elif data == 0:
        print("Switch released!")

# Enable notifications and register a callback for them.
c.switch.notifications(switch_callback)

API

Switch module

Created by hbldh <henrik.blidh@nedomkull.com> on 2016-04-14

class pymetawear.modules.switch.SwitchModule(board)[source]

MetaWear Switch 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 or ctypes.c_int
module_name

Get module name.

Returns:The name of this module.
Return type:str
notifications(callback=None)[source]

Subscribe or unsubscribe to switch notifications.

Convenience method for handling switch usage.

Example:

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)
Parameters:callback (callable) – Switch notification callback function. If None, unsubscription to switch notifications is registered.