Mechatronics
Documentation for ME 405 labs
Button.Button Class Reference

A button class that reports precisely when it is pressed. More...

Inheritance diagram for Button.Button:

Public Member Functions

def press (self, timer)
 Recognizes the button has been pressed and records it. More...
 
def __init__ (self, callback=None, epoch=None)
 Create a Button object. More...
 
def REPORT (self, message)
 Schedule a debug message to be reported with a time stamp. More...
 
def disable (self, Timer trigger=None)
 Disable the button and runs the callback function specified upon Button creation. More...
 
def enable (self)
 Enable the button after having been disabled.
 
def trigger (self, int irq_src)
 Collect and report a button action. More...
 
def press (self, int irq_src=None)
 Recognizes the button has been pressed and updates the time. More...
 
def release (self, int irq_src=None)
 Recognizes the button press has finished. More...
 
def __init__ (self, falling_callback=None, rising_callback=None, epoch=None)
 Create a Button object. More...
 

Public Attributes

 pressed_counts
 The time when this button is pressed.
 
 epoch
 Compare all timed events to this time (button zero). More...
 
 callback
 A function to return to when the button is pressed. More...
 
 triggered
 The last edge that was encountered on the button The default state is that the button has not been pressed (i.e. More...
 
 time_pressed
 Last time the button was pressed #.
 
 time_released
 Last time the button was released #.
 
 interrupt
 Interrupt for button detection and timeout handling #.
 

Detailed Description

A button class that reports precisely when it is pressed.

A Button class that reports rising and falling edges.

Subclasses the Pin object from pyb. Responds upon the falling edge (push) of the user button.

This button class extends the pyb.Pin class, so can be treated as a Pin. On creation the button can be given callback functions to call on rising and calling edges. It can also be easily enabled and disabled.

Constructor & Destructor Documentation

◆ __init__() [1/2]

def Button.Button.__init__ (   self,
  callback = None,
  epoch = None 
)

Create a Button object.

Parameters
callbackA function to optionally be called once the button is disabled
epochThe starting time of the owner of this Button. If provided, the button will synchronize with its creator.

◆ __init__() [2/2]

def Button.Button.__init__ (   self,
  falling_callback = None,
  rising_callback = None,
  epoch = None 
)

Create a Button object.

Parameters
falling_callbackA function to optionally be called when a falling edge is detected
rising_callbackA function to optionally be called when a rising edge is detected
epochA global zero time to which all other time readings are compared. If not provided, the button will create its own.

Member Function Documentation

◆ disable()

def Button.Button.disable (   self,
Timer   trigger = None 
)

Disable the button and runs the callback function specified upon Button creation.

Parameters
triggerThe timer that disabled the button (if supplied)

◆ press() [1/2]

def Button.Button.press (   self,
int   irq_src = None 
)

Recognizes the button has been pressed and updates the time.

Sets time_pressed and, if applicable, schedules a callback function with the triggered time.

Parameters
irq_srcThe interrupt request source line number (required as an interrupt callback).

◆ press() [2/2]

def Button.Button.press (   self,
  timer 
)

Recognizes the button has been pressed and records it.

If applicable, the Button's callback function is also called.

Parameters
timerThe timer which triggered this interrupt.

◆ release()

def Button.Button.release (   self,
int   irq_src = None 
)

Recognizes the button press has finished.

Updates the sequence with the type of press.

Sets time_released and, if applicable, schedules a callback function with the triggered time.

Parameters
irq_srcThe interrupt request source line number (required as an interrupt callback).

◆ REPORT()

def Button.Button.REPORT (   self,
  message 
)

Schedule a debug message to be reported with a time stamp.

Parameters
messageThe message to be reported.

◆ trigger()

def Button.Button.trigger (   self,
int  irq_src 
)

Collect and report a button action.

Currently the debug functionality in unstable within interrupts, so it has been disabled.

Parameters
irq_srcThe interrupt request source line number (required as an interrupt callback).

Member Data Documentation

◆ callback

Button.Button.callback

A function to return to when the button is pressed.

Callback functions to return to when the button is pressed or released #.

◆ epoch

Button.Button.epoch

Compare all timed events to this time (button zero).

#

◆ triggered

Button.Button.triggered

The last edge that was encountered on the button The default state is that the button has not been pressed (i.e.

previous edge was RISING).


The documentation for this class was generated from the following file: