grove.button

Submodules

Classes

class grove.button.Button(pin=0)[source]

Button Base Class

provide event callback ability to derived class

Parameters:

pin (int) – optional, for GPIO type button, it’s the GPIO pin number.

Inheritance

digraph inheritance9a3741d07e { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Button" [URL="grove.button.button.html#grove.button.button.Button",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Button Base Class"]; }
get_on_event()[source]

Get the event receiving object and callback member function

Returns:

a pair consist of event receiving object

and callback member function

Return type:

(obj, event_callback)

is_pressed(index=0)[source]

Get the button status if it’s being pressed ?

Parameters:

index (int) – optional, the index number of which button to be checked. must be specified only if it’s a multiple button device.

Returns:

True if the button is being pressed.

False if not.

Return type:

(bool)

on_event(obj, callback)[source]

Set the event receiving object and it’callback member function

Parameters:
  • obj (object) – the object to receiving event

  • callback (callable) –

    a member function of obj, will be called when there is button event

    callback prototype:

    callback(obj, evt_dict)

    callback argument:
    Args:

    obj(object) : the object that is obj argument of on_event

    evt_dict(dict): the event dictionary include items:
    • index

    • code

    • pressed

    • time

    Returns: none

class grove.button.ButtonTypedGpio(pin, low_pressed=True)[source]

GPIO Button Class

provide event checking ability to derived class, should not use directly by end-user. The checking events include:

  • Button.EV_SINGLE_CLICK

  • Button.EV_DOUBLE_CLICK

  • Button.EV_LONG_PRESS

  • Button.EV_LEVEL_CHANGED

Parameters:
  • pin (int) – GPIO pin number the button connected.

  • low_pressed (bool) –

    optional, default True

    True if the the button gpio level is low when pressed.

    False if level high when pressed

Inheritance

digraph inheritanceb602b86845 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Button" [URL="grove.button.button.html#grove.button.button.Button",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Button Base Class"]; "ButtonTypedGpio" [URL="grove.button.button_gpio.html#grove.button.button_gpio.ButtonTypedGpio",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="GPIO Button Class"]; "Button" -> "ButtonTypedGpio" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
is_pressed(index=0)[source]

Get the button status if it’s being pressed ?

Parameters:

index (int) – optional, the arg index not be used.

Returns:

True if the button is being pressed.

False if not.

Return type:

(bool)

class grove.button.ButtonTypedI2c(address=3, evt_en=True)[source]

I2C Button/Switch Array Class

provide event checking ability to derived class, should not use directly by end-user. The checking events include:

  • Button.EV_SINGLE_CLICK

  • Button.EV_DOUBLE_CLICK

  • Button.EV_LONG_PRESS

  • Button.EV_LEVEL_CHANGED

Parameters:
  • address (int) – optional, the I2C address of the connected device.

  • evt_en (bool) –

    optional, default True

    True: provide event checking ability.

    False: used in poll environment, manually call ButtonTypedI2c.read.

Inheritance

digraph inheritance669ed9cee8 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Button" [URL="grove.button.button.html#grove.button.button.Button",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Button Base Class"]; "ButtonTypedI2c" [URL="grove.button.button_i2c.html#grove.button.button_i2c.ButtonTypedI2c",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="I2C Button/Switch Array Class"]; "Button" -> "ButtonTypedI2c" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
is_pressed(index=0)[source]

Get the button status if it’s being pressed ?

ButtonTypedI2c.read must be called before this api call when used with poll method object (created with evt_en = False).

Parameters:

index (int) – optional, the index number of button to be checked. must be specified for this device.

Returns:

True if the button is being pressed. False if not.

Return type:

(bool)

name(index=None)[source]

Get the device name or specified button name

Parameters:

index (int) – optional, the index number of button to get name. if not specified, return the device name.

Returns:

the name of the device or pecified button

Return type:

(string)

read()[source]

Get the button array status

Returns:

a list has the size button count + 1
item [0] indicate if there is a event (bit 0x80).

bit 0x80 set if one or more the switches have event. bit 0x80 clear if no one has event.

item [ 1 + index ] indicate the event of button specified

by index, be bits combination of

  • Button.EV_LEVEL_CHANGED

  • Button.EV_SINGLE_CLICK

  • Button.EV_DOUBLE_CLICK

  • Button.EV_LONG_PRESS

Return type:

(list)

size()[source]

Get the button count the device have.

Returns:

button count

Return type:

(int)

version()[source]

Get the device firmware version.

Returns:

firmware version, the first version is 1

Return type:

(int)