]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sitara-linux/mmwavegesture-hmi.git/blob - keyword.cpp
Makefile.build : add Makefile to enable build through SDK
[sitara-linux/mmwavegesture-hmi.git] / keyword.cpp
1 /*
2 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
3 *
4 *
5 *  Redistribution and use in source and binary forms, with or without
6 *  modification, are permitted provided that the following conditions
7 *  are met:
8 *
9 *    Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 *
12 *    Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the
15 *    distribution.
16 *
17 *    Neither the name of Texas Instruments Incorporated nor the names of
18 *    its contributors may be used to endorse or promote products derived
19 *    from this software without specific prior written permission.
20 *
21 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34 #include <QCoreApplication>
35 #include <QDebug>
36 #include <QTimer>
37 #include "keyword.h"
39 QT_USE_NAMESPACE
41 Keyword::Keyword(QObject *qmlCompObject)
42 {
43     m_digitArray[0] = qmlCompObject->findChild<QObject *>("myDigit1");
44     m_digitArray[1] = qmlCompObject->findChild<QObject *>("myDigit2");
45     m_digitArray[2] = qmlCompObject->findChild<QObject *>("myDigit3");
46     m_digitArray[3] = qmlCompObject->findChild<QObject *>("myDigit4");
48     m_qmlCompObject = qmlCompObject;
50     //initialize the displayed digits as 3337
51     for (int i = 0; i < 3; i++){
52         m_counter[i] = 0;
53     }
55     m_counter[3] = 5;
57     /* Substract the keyword with 3 as the keyword is matched to the "model" index and not
58      * the value at that index. Check the PathView in Digit.qml to understand model. A PathView
59      * displays data from models created from built-in QML types.  A model provides a
60      * set of data that is used to create the items for the view.  To avoid many scrolls to
61      * to set the password, password is restricted between 3 and 8 and mmWave part number is
62      * 6843, which is set as initial password*/
63     m_keyword[0] = 3;//6 - 3;
64     m_keyword[1] = 5;//8 - 3;
65     m_keyword[2] = 1;//4 - 3;
66     m_keyword[3] = 0;//3 - 3;
68     qDebug() <<  " keyword index" << m_keyword[0] << m_keyword[1] << m_keyword[2] << m_keyword[3];
69     m_activeIndex = 0;
71     m_digitArray[m_activeIndex]->setProperty("borderColor", "red");
72     m_digitArray[m_activeIndex]->setProperty("borderWidth", 9);
73     m_digitArray[m_activeIndex]->setProperty("digit", m_counter[0]);
75     for (int i = 1; i < 4; i++){
76         if(m_digitArray[i]){
77             m_digitArray[i]->setProperty("borderColor", "black");
78             m_digitArray[i]->setProperty("borderWidth", 1);
79             m_digitArray[i]->setProperty("digit", m_counter[i]);
80         }
81     }
83     m_numtimes_keyword_match = 1;
84 }
86 Keyword::~Keyword()
87 {
88     for (int i = 0; i < 4 ; i++){
89         m_digitArray[i] = nullptr;
90         m_counter[i] = 0;
91     }
92 }
94 void Keyword::emitKeywordQuit()
95 {
96     qDebug() << "Emit keywordQuit signal\n";
97     emit keywordQuit();
98 }
100 void Keyword::handleDownGesture()
102     bool keyMatch = false;
103     m_counter[m_activeIndex] = (m_counter[m_activeIndex] + 1) % 6;
105     m_digitArray[m_activeIndex]->setProperty("digit", m_counter[m_activeIndex]);
107     keyMatch = ((m_digitArray[0]->property("digit") == m_keyword[0]) &&
108             (m_digitArray[1]->property("digit") == m_keyword[1]) &&
109             (m_digitArray[2]->property("digit") == m_keyword[2]) &&
110             (m_digitArray[3]->property("digit") == m_keyword[3]));
112     //Refresh the screen with updated digit
113     QTimer::singleShot(0, m_qmlCompObject, SLOT(update()));
115     if (keyMatch == true){
116         m_qmlCompObject->setProperty("mypaused", false);
117         m_numtimes_keyword_match -= 1;
118         if(m_numtimes_keyword_match <= 0){
119             QTimer::singleShot(5000, this, SLOT(emitKeywordQuit()));
120         }
121     }
124 void Keyword::handleRightGesture()
126     m_digitArray[m_activeIndex]->setProperty("borderColor", "black");
127     m_digitArray[m_activeIndex]->setProperty("borderWidth", 2);
128     m_activeIndex = (m_activeIndex + 1) % 4;
130     m_digitArray[m_activeIndex]->setProperty("borderColor", "red");
131     m_digitArray[m_activeIndex]->setProperty("borderWidth", 9);
133     //Refresh the screen with updated digit index
134     QTimer::singleShot(0, m_qmlCompObject, SLOT(update()));
137 void Keyword::handleMotionDetected()
139     m_qmlCompObject->setProperty("color", "gray");
140     m_qmlCompObject->setProperty("myvisibility", true);
143 void Keyword::handleNoActivity()
145     m_qmlCompObject->setProperty("color", "black");
146     m_qmlCompObject->setProperty("myvisibility", false);