COSA
An Object-Oriented Platform for Arduino Programming
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Touch.cpp
Go to the documentation of this file.
1
21
#include "
Touch.hh
"
22
#include "
Cosa/RTT.hh
"
23
24
Touch::Touch
(
Job::Scheduler
* scheduler,
Board::DigitalPin
pin, uint16_t threshold) :
25
IOPin
(pin),
26
Periodic
(scheduler, SAMPLE_RATE),
27
THRESHOLD(threshold),
28
m_sampling(false),
29
m_touched(false)
30
{
31
mode
(
OUTPUT_MODE
);
32
clear
();
33
}
34
35
void
36
Touch::run
()
37
{
38
// Check if sampling should be initiated
39
if
(!
m_sampling
) {
40
mode
(
INPUT_MODE
);
41
m_sampling
=
true
;
42
return
;
43
}
44
45
// Sample the pin and discharge
46
uint8_t state =
is_clear
();
47
mode
(
OUTPUT_MODE
);
48
clear
();
49
m_sampling
=
false
;
50
51
// Was the pin discharge during the sampling period
52
if
(state) {
53
m_start
=
RTT::millis
();
54
if
(!
m_touched
) {
55
on_touch
();
56
m_touched
=
true
;
57
}
58
return
;
59
}
60
61
// The pin was discharge; low-pass filter pin change
62
if
(
m_touched
&& (
RTT::since
(
m_start
) >
THRESHOLD
)) {
63
m_touched
=
false
;
64
}
65
}
66
Board::DigitalPin
DigitalPin
Definition:
ATmega1284P.hh:106
Touch::m_touched
uint8_t m_touched
Definition:
Touch.hh:73
IOPin::INPUT_MODE
Definition:
IOPin.hh:33
Job::Scheduler
Definition:
Job.hh:43
Touch.hh
Periodic
Definition:
Periodic.hh:38
IOPin::mode
Mode mode() const
Definition:
IOPin.hh:71
IOPin::OUTPUT_MODE
Definition:
IOPin.hh:32
Touch::Touch
Touch(Job::Scheduler *scheduler, Board::DigitalPin pin, uint16_t threshold=250)
Definition:
Touch.cpp:24
RTT::since
static uint32_t since(uint32_t start)
Definition:
RTT.hh:107
Touch::m_start
uint32_t m_start
Definition:
Touch.hh:67
Touch::on_touch
virtual void on_touch()=0
RTT::millis
static uint32_t millis()
Definition:
RTT.cpp:121
RTT.hh
Touch::run
virtual void run()
Definition:
Touch.cpp:36
IOPin
Definition:
IOPin.hh:29
Pin::is_clear
bool is_clear() const
Definition:
Pin.hh:142
OutputPin::clear
void clear() const
Definition:
OutputPin.hh:124
Touch::THRESHOLD
const uint16_t THRESHOLD
Definition:
Touch.hh:64
Touch::m_sampling
uint8_t m_sampling
Definition:
Touch.hh:70
libraries
Touch
Touch.cpp
Generated on Thu Aug 31 2017 17:02:04 for COSA by
1.8.11