grove.button.button_i2c

Classes

class grove.button.button_i2c.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.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)

Variables

grove.button.button_i2c.NAME_5_WAY_SWITCH

The Button name to compare with return value of ButtonTypedI2c.name

'Grove-5-Way-Switch'
grove.button.button_i2c.NAME_6_POS_DIP_SWITCH

The Button name to compare with return value of ButtonTypedI2c.name

'Grove-6-Pos-DIP-Switch'