bricknil.bricknil

Utility functions to attach sensors/motors and start the whole event loop

  1. The decorator attach to specify peripherals that connect to a hub (which enables sensing and motor control functions),
  2. The function start() that starts running the BLE communication queue, and all the hubs, in the event-loop system

Classes

attach(peripheral_type, **kwargs) Class-decorator to attach peripherals onto a Hub

Functions

start(user_system_setup_func) Main entry point into running everything.

Members

class bricknil.bricknil.attach(peripheral_type, **kwargs)[source]

Bases: object

Class-decorator to attach peripherals onto a Hub

Injects sub-classes of Peripheral as instance variables on a Hub such as the PoweredUp Hub, akin to “attaching” a physical sensor or motor onto the Hub.

Before you attach a peripheral with sensing capabilities, you need to ensure your Peripheral sub-class has the matching call-back method ‘peripheralname_change’.

Examples:

@attach(PeripheralType,
        name="instance name",
        port='port',
        capabilities=[])

Warning

  • No support for checking to make sure user put in correct parameters
  • Identifies capabilities that need a callback update handler based purely on checking if the capability name starts with the string “sense*”
bricknil.bricknil.start(user_system_setup_func)[source]

Main entry point into running everything.

Just pass in the async co-routine that instantiates all your hubs, and this function will take care of the rest. This includes:

  • Initializing the Adafruit bluetooth interface object
  • Starting a run loop inside this bluetooth interface for executing the Curio event loop
  • Starting up the user async co-routines inside the Curio event loop