COSA
An Object-Oriented Platform for Arduino Programming
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Button.hh
Go to the documentation of this file.
1
21
#ifndef COSA_BUTTON_HH
22
#define COSA_BUTTON_HH
23
24
#include "
Cosa/Types.h
"
25
#include "
Cosa/InputPin.hh
"
26
#include "
Cosa/Periodic.hh
"
27
#include "
Cosa/Watchdog.hh
"
28
56
class
Button
:
public
InputPin
,
public
Periodic
{
57
public
:
62
enum
Mode
{
63
ON_FALLING_MODE
= 0,
// High to low transition.
64
ON_RISING_MODE
= 1,
// Low to high transition.
65
ON_CHANGE_MODE
= 2
// Any transition.
66
} __attribute__((packed));
67
77
Button
(
Job::Scheduler
* scheduler,
78
Board::DigitalPin
pin
,
79
Mode
mode
=
ON_CHANGE_MODE
) :
80
InputPin
(pin,
InputPin
::
PULLUP_MODE
),
81
Periodic
(scheduler,
SAMPLE_MS
),
82
MODE
(
mode
),
83
m_state
(
is_set
())
84
{}
85
94
virtual
void
on_change
(uint8_t type) = 0;
95
96
protected
:
98
static
const
uint16_t
SAMPLE_MS
= 64;
99
101
const
Mode
MODE
;
102
104
uint8_t
m_state
;
105
112
virtual
void
run
()
113
{
114
// Update the button state
115
uint8_t old_state =
m_state
;
116
m_state =
is_set
();
117
uint8_t new_state =
m_state
;
118
119
// If changed according to mode call the pin change handler
120
if
((old_state != new_state) &&
121
((MODE ==
ON_CHANGE_MODE
) || (new_state == MODE)))
122
on_change
(
Event::FALLING_TYPE
+ MODE);
123
}
124
};
125
126
#endif
Board::DigitalPin
DigitalPin
Definition:
ATmega1284P.hh:106
Types.h
Button::m_state
uint8_t m_state
Definition:
Button.hh:104
InputPin.hh
Pin::pin
uint8_t pin() const
Definition:
Pin.hh:103
Periodic.hh
Button::ON_CHANGE_MODE
Definition:
Button.hh:65
Button
Definition:
Button.hh:56
Job::Scheduler
Definition:
Job.hh:43
Periodic
Definition:
Periodic.hh:38
InputPin
Definition:
InputPin.hh:29
Event::FALLING_TYPE
Definition:
Event.hh:56
InputPin::PULLUP_MODE
Definition:
InputPin.hh:33
InputPin::mode
Mode mode() const
Definition:
InputPin.hh:52
Pin::is_set
bool is_set() const
Definition:
Pin.hh:112
Button::on_change
virtual void on_change(uint8_t type)=0
Button::Mode
Mode
Definition:
Button.hh:62
Button::ON_RISING_MODE
Definition:
Button.hh:64
Watchdog.hh
Button::MODE
const Mode MODE
Definition:
Button.hh:101
Button::SAMPLE_MS
static const uint16_t SAMPLE_MS
Definition:
Button.hh:98
Button::run
virtual void run()
Definition:
Button.hh:112
Button::Button
Button(Job::Scheduler *scheduler, Board::DigitalPin pin, Mode mode=ON_CHANGE_MODE)
Definition:
Button.hh:77
Button::ON_FALLING_MODE
Definition:
Button.hh:63
cores
cosa
Cosa
Button.hh
Generated on Thu Aug 31 2017 17:02:02 for COSA by
1.8.11