mthread  0.5.1
Public Types | Public Member Functions | Protected Member Functions | Private Attributes
SwitchInput Class Reference

Handler for a switch input. More...

#include <mthread.h>

Inheritance diagram for SwitchInput:
Thread

List of all members.

Public Types

enum  Type { pull_up_internal, pull_up, pull_down }
 Types of switches. More...

Public Member Functions

 SwitchInput (int pin, unsigned long debounce=DEFAULT_DEBOUNCE, Type type=pull_up_internal)
 Constructor.
virtual ~SwitchInput ()
 Destructor.
bool is_closed () const
 Checks to see if the switch is closed.
bool is_open () const
 Checks to see if the switch is open.
virtual void on_close ()
 Called once when the switch closes.
virtual void on_open ()
 Called once when the switch opens.
unsigned long time_closed () const
 Checks the length of time the switch has been closed.
unsigned long time_open () const
 Checks the length of time the switch has been open.

Protected Member Functions

bool loop ()
 Main loop.

Private Attributes

unsigned long debounce
 The debounce time (in milliseconds).
unsigned long last_change
 The time of the last change (in millisecnods, ignoring debounce).
unsigned long last_debounce
 The time of the last change (in milliseconds, after debounce filtering).
int current_value
 The switch's current value (after debounce filtering).
int last_value
 The switch's value on the last read (ignoring debounce).
int pin
 The pin the switch is connected to.
Type type
 The type of switch connected.

Detailed Description

Handler for a switch input.


Member Enumeration Documentation

Types of switches.

Enumerator:
pull_up_internal 

Switch uses the internal pull-up resistor.

pull_up 

Switch uses an external pull-up resistor.

pull_down 

Switch uses an external pull-down resistor.


Constructor & Destructor Documentation

SwitchInput::SwitchInput ( int  pin,
unsigned long  debounce = DEFAULT_DEBOUNCE,
Type  type = pull_up_internal 
)

Constructor.

Parameters:
pinThe pin number the switch is connected to.
debounceThe debounce time (in milliseconds).
typeThe type of switch connected.

Member Function Documentation

bool SwitchInput::is_closed ( ) const

Checks to see if the switch is closed.

Returns:
true if the switch is closed, false if it's open.
bool SwitchInput::is_open ( ) const

Checks to see if the switch is open.

Returns:
true if the switch is open, false if it's closed.
bool SwitchInput::loop ( void  ) [protected, virtual]

Main loop.

See also:
Thread::loop().

Reimplemented from Thread.

unsigned long SwitchInput::time_closed ( ) const

Checks the length of time the switch has been closed.

Returns:
The amount of time (in milliseconds) the switch has been closed, or 0 if the switch is open.
unsigned long SwitchInput::time_open ( ) const

Checks the length of time the switch has been open.

Returns:
The amount of time (in milliseconds) the switch has been open, or 0 if the switch is closed.

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator Defines