-
Notifications
You must be signed in to change notification settings - Fork 2
/
TouchWheel.cpp
120 lines (101 loc) · 2.41 KB
/
TouchWheel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Little Helper -- your best friend in your lab
* http://www.appfruits.com/littlehelper
*
* This software is part of the firmware running Little Helper. You may use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software
* but you must include this copyright notice and this permission in all copies or
* substantial portions of the Software.
*
* Appfruits invests time and resources to make this open source. Please support us
* and the open-source hardware initiative.
*
* Copyright 2014-2015 Phillip Schuster (@appfruits)
* http://www.appfruits.com
*
* MIT-License
*/
#include "TouchWheel.h"
//#include "Application.h"
TouchWheel::TouchWheel(Appfruits_QTouch* driver)
{
this->_driver = driver;
this->_driver->setDelegate(this);
this->resetStates();
}
void TouchWheel::begin()
{
this->_driver->begin();
this->_driver->enableWheel();
this->_driver->setDetectThreshold(0,41);
this->_driver->setDetectThreshold(1,41);
this->_driver->setDetectThreshold(2,41);
this->_driver->setDetectionIntegrator(3);
}
void TouchWheel::update()
{
this->resetStates();
if (this->_driver->eventAvailable())
{
if (this->_driver->wheelDetected())
{
this->_sliderDelta = this->_driver->sliderDelta();
}
}
}
void TouchWheel::resetStates()
{
for (int i=0;i<4;i++)
{
this->_button[i] = 0;
}
this->_sliderDelta = 0;
this->_sliderPos = 0;
}
bool TouchWheel::isButtonReleased(Direction direction)
{
return (this->_button[direction] > 0);
}
bool TouchWheel::isSliding()
{
return this->_sliding;
}
int8_t TouchWheel::getSliderDelta()
{
return this->_sliderDelta;
}
uint8_t TouchWheel::getSliderPosition()
{
return this->_sliderPos;
}
void TouchWheel::onTouchLeftButtonPressed(uint32_t duration)
{
_button[Direction::Left] = duration;
}
void TouchWheel::onTouchTopButtonPressed(uint32_t duration)
{
_button[Direction::Top] = duration;
}
void TouchWheel::onTouchRightButtonPressed(uint32_t duration)
{
_button[Direction::Right] = duration;
}
void TouchWheel::onTouchBottomButtonPressed(uint32_t duration)
{
_button[Direction::Bottom] = duration;
}
void TouchWheel::onSlider(uint8_t sliderPos, int8_t sliderDelta)
{
//LOG_VALUE("Slider detected",sliderDelta);
this->_sliderPos = sliderPos;
this->_sliderDelta = sliderDelta;
this->_sliding = true;
}
void TouchWheel::onTouchDown()
{
this->_touching = true;
}
void TouchWheel::onTouchUp(uint32_t duration)
{
this->_touching = false;
}