]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sitara-linux/evse-hmi.git/blob - evse_hmi.cpp
evse_hmi.ui: fix character truncation issue
[sitara-linux/evse-hmi.git] / evse_hmi.cpp
1 /*
2  * Copyright (C) 2017 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 */
36 #include "evse_hmi.h"
37 #include "ui_evse_hmi.h"
39 #include <QProgressBar>
40 #include <QTimer>
41 #include <iostream>
44 evse_hmi::evse_hmi(QWidget *parent) :
45     QMainWindow(parent),
46     ui(new Ui::evse_hmi)
47 {
48     ui->setupUi(this);
49     ui->stackedWidget->setCurrentIndex(0);
50     resetProgressBar();
51 }
53 evse_hmi::~evse_hmi()
54 {
55     delete ui;
56 }
59 /* Page 0 Functions */
60 void evse_hmi::on_ContinueButton_clicked()
61 {
62     ui -> stackedWidget -> setCurrentIndex(1);
63 }
65 void evse_hmi::on_ExitButton_clicked()
66 {
67     qApp -> quit();
68 }
71 /* Page 1 Functions */
72 void evse_hmi::on_ChargingMode1_clicked()
73 {
74       ui -> stackedWidget -> setCurrentIndex(2);
75 }
77 void evse_hmi::on_ChargingMode2_clicked()
78 {
79     ui -> stackedWidget -> setCurrentIndex(2);
80 }
82 void evse_hmi::on_ChargingMode3_clicked()
83 {
84     ui -> stackedWidget -> setCurrentIndex(2);
85 }
87 void evse_hmi::on_ChargingMode4_clicked()
88 {
89     ui -> stackedWidget -> setCurrentIndex(2);
90 }
92 void evse_hmi::on_Page1Home_clicked()
93 {
94     ui -> stackedWidget -> setCurrentIndex(0);
95 }
99 /* Page 2 Functions*/
100 void evse_hmi::on_OkButton_clicked()
102      ui -> stackedWidget -> setCurrentIndex(3);
106 void evse_hmi::on_Page2Home_clicked()
108     ui -> stackedWidget -> setCurrentIndex(0);
113 /* Page 3 Functions */
114 void evse_hmi::on_BeginChargeButton_clicked()
116     /* startTimer function will trigger the timerEvent function to be
117        called every 10 milliseconds */
118     timerId = startTimer(175);
119     start = 1;
122 void evse_hmi::timerEvent(QTimerEvent *event)
124     if(milliseconds >= 0 && start) {
126         /* The accept method is used to satisfy the compiler. If it
127          *  is not used the compiler will give the following warning:
128          *  "Warning unused event" */
129         event -> accept();
131         // Remaining charge time calculations
132         minutes = (milliseconds % (1000*60*60)) / (1000*60);
133         seconds = ((milliseconds % (1000*60*60)) % (1000*60)) / 1000;
134         milliseconds = milliseconds - 5000;
135         //Hours = Milliseconds / (1000*60*60);
137         // Time elapsed calculations
138         millisecondsElapsed = millisecondsElapsed + 5000;
139         secondsElapsed = ((millisecondsElapsed % (1000*60*60)) % (1000*60)) / 1000;
140         minutesElapsed = (millisecondsElapsed % (1000*60*60)) / (1000*60);
142         // Percentage charged calculations
143         percentComplete = (((double) milliseconds / (double) 3600000))*100;
144         percentComplete = 100 - percentComplete;
145         ui -> ProgressBar -> setValue(percentComplete);
147         // Remaining time and elapsed time screen updates
148         char rBuffer[30];
149         char eBuffer[30];
150         sprintf(rBuffer,"%i:%02i",minutes,seconds);
151         sprintf(eBuffer,"%i:%02i",minutesElapsed,secondsElapsed);
152         ui -> RemainingTimeLabel -> setStyleSheet("font-size:10pt;font-weight:600; color:#ffffff;border:none;");
153         ui -> RemainingTimeLabel->setText(rBuffer);
154         ui -> RemainingTimeLabel -> setStyleSheet("font-size:10pt;font-weight:600; color:#ffffff;border:none;");
155         ui -> ElapsedTimeLabel->setText(eBuffer);
156     }
159 void evse_hmi::on_EndChargeButton_clicked()
161     /*  Setting the start variable to 0 will stop
162      *  the progress bar from updating any further */
163     start = 0;
164     ui -> stackedWidget -> setCurrentIndex(0);
165     resetProgressBar();
168 void evse_hmi::resetProgressBar() {
169     //setting start flag to 0
170     start = 0;
172     //setting progress bar's value attribute to 0
173     ui -> ProgressBar -> setValue(0);
175     // Initalizing percentComplete variable
176     percentComplete = 0;
178     // Initializing all variables needed for calculating charge time remaining and elapsed
179     milliseconds = 3600000;
180     minutes = 0;
181     seconds = 0;
182     millisecondsElapsed = -10000;
183     secondsElapsed = 0;
184     minutesElapsed = 0;
185     //hours = 0;
187     // Resetting remaining time and elapsed time values
188     ui -> RemainingTimeLabel -> setStyleSheet("font-size:10pt;font-weight:600; color:#ffffff;border:none;");
189     ui -> RemainingTimeLabel->setText("60:00");
190     ui -> ElapsedTimeLabel -> setStyleSheet("font-size:10pt;font-weight:600; color:#ffffff;border:none;");
191     ui -> ElapsedTimeLabel->setText("0:00");