Project

General

Profile

Statistics
| Branch: | Revision:

pse-2015-16-grupo-3 / tpf / display.c @ 87a830c5

History | View | Annotate | Download (4.8 KB)

1
#include <stdlib.h>
2
#include <stdint.h>
3
#include <stdio.h>
4
#include <lcd.h>
5
#include "display.h"
6
#include "tempo.h"
7
#include "config.h"
8

    
9
#ifdef LCD_NOT_SEG
10

    
11
#include <time.h>
12

    
13
static int lcdHandler;
14
static pse_time_t LCDClock;
15
static uint16_t LCDppower;
16

    
17
uint8_t setDisplay(pse_time_t clock, uint16_t power, char* message)
18
{
19
    uint8_t result;
20
    
21
    if(getLCDHandler(&lcdHandler)!=0)
22
    {
23
        result=1;
24
    }
25
    else
26
    {
27
        
28
        lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler,"                ");
29
        lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler,"                ");
30
    
31
        char horas[2];
32
        char minutos[2];
33
        char segundos[2];
34
        char powerChar[3];
35
                
36
        sprintf(horas, "%02d", clock.horas);
37
        sprintf(minutos, "%02d", clock.minutos);
38
        sprintf(segundos, "%02d", clock.segundos);
39
        
40
        //printf("%02hho", clock.minutos);
41
        //printf("%02d", clock.segundos);
42
        //printf(minutos);
43
        //printf(segundos);
44
        
45
        sprintf(powerChar, "%03d", power);
46
        result=0;    
47
        if(message)
48
        {
49

    
50
            lcdPosition (lcdHandler, 0, 0); 
51
            lcdPuts (lcdHandler, horas);
52
            //lcdPosition (lcdHandler, 2, 0) ; 
53
            lcdPutchar (lcdHandler, ':');
54
            //lcdPosition (lcdHandler, 3, 0) ; 
55
            lcdPuts (lcdHandler, minutos);
56
            //lcdPosition (lcdHandler, 5, 0) ; 
57
            lcdPutchar (lcdHandler, ':');
58
            //lcdPosition (lcdHandler, 6, 0) ; 
59
            lcdPuts (lcdHandler, segundos);
60
            
61
            lcdPosition (lcdHandler, 12, 0) ; 
62
            lcdPuts (lcdHandler, powerChar);
63
            lcdPosition (lcdHandler, 15, 0) ; 
64
            lcdPutchar (lcdHandler, 'W');
65
            
66
            
67
            lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler,message) ;
68

    
69

    
70
        }
71
        else
72
        {
73

    
74
            lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler, horas);// + ':' + minutos + ':' + segundos + ' ' + Power +  'W') ;
75

    
76

    
77

    
78
        }
79
    }
80
    
81
    
82
    
83
    //power
84
            
85
            
86
    //Message
87
            
88
    
89
    return result;
90
}
91

    
92
uint8_t clearDisplay()
93
{
94
    return 0;
95
}
96

    
97

    
98
uint8_t setDisplayTime(pse_time_t clock)
99
{
100
    LCDClock.horas = clock.horas;
101
    LCDClock.minutos = clock.minutos;
102
    LCDClock.segundos = clock.segundos;
103
    
104
    return 0;
105
}
106

    
107
uint8_t setDisplayPower(uint16_t power)
108
{
109
    uint8_t result=0;
110
    
111
    LCDppower = power;
112
    
113
    return result;
114
}
115

    
116
uint8_t showDisplay()
117
{
118
    //returned variable
119
    uint8_t result = 0;
120
    
121
    //clear previous displayed values
122
    lcdPosition (lcdHandler, 0, 0) ; lcdPuts (lcdHandler,"                ");
123
    lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler,"                ");
124
    
125
    //char arrays to contain values
126
    char horas[2];
127
    char minutos[2];
128
    char segundos[2];
129
    char powerChar[3];
130

    
131
    //read the values from static variables
132
    sprintf(horas, "%02d", LCDClock.horas);
133
    sprintf(minutos, "%02d", LCDClock.minutos);
134
    sprintf(segundos, "%02d", LCDClock.segundos);
135
    sprintf(powerChar, "%03d", LCDppower);
136
    
137
    //show time values on the left
138
    lcdPosition(lcdHandler, 0, 0);
139
    lcdPuts(lcdHandler, horas);
140
    //lcdPosition (lcdHandler, 2, 0) ; 
141
    lcdPutchar(lcdHandler, ':');
142
    //lcdPosition (lcdHandler, 3, 0) ; 
143
    lcdPuts(lcdHandler, minutos);
144
    //lcdPosition (lcdHandler, 5, 0) ; 
145
    lcdPutchar(lcdHandler, ':');
146
    //lcdPosition (lcdHandler, 6, 0) ; 
147
    lcdPuts(lcdHandler, segundos);
148

    
149
    //show power values on the right
150
    lcdPosition(lcdHandler, 12, 0);
151
    lcdPuts(lcdHandler, powerChar);
152
    lcdPosition(lcdHandler, 15, 0);
153
    lcdPutchar(lcdHandler, 'W');
154
  
155
    
156
    return result;
157
}
158

    
159
uint8_t initDisplay()
160
{
161
    uint8_t result = 0;
162
    
163
    LCDClock.horas=0;
164
    LCDClock.minutos=0;
165
    LCDClock.segundos=0;
166
    
167
    
168
    if(getLCDHandler(&lcdHandler)!=0)
169
    {
170
        result=1;
171
    }
172
    
173
    return result;
174
}
175

    
176

    
177

    
178
uint8_t displayShowMessage( char *message)
179
{
180
    //returned variable
181
    uint8_t result = 0;
182
    
183
    //clear previous displayed message
184
    lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler,"                ");
185
    
186
    lcdPosition(lcdHandler, 0, 1);
187
    lcdPuts(lcdHandler, message);
188
    
189
    return result;
190
}
191

    
192
uint8_t displayShowCurrentTime ()
193
{
194
    //returned variable
195
    uint8_t result = 0;
196
    
197
    //time values
198
    struct tm *t ;
199
    time_t tim ;
200
    char buf[8];
201

    
202
    //get current time
203
    tim = time (NULL) ;
204
    t = localtime (&tim) ;
205

    
206
    //create char[] from current time values
207
    sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;
208
    
209
    //clear previous displayed values
210
    lcdPosition (lcdHandler, 0, 1) ; lcdPuts (lcdHandler,"                ");
211
    
212
    //show current time values on the second row
213
    lcdPosition(lcdHandler, 0, 1);
214
    lcdPuts(lcdHandler, buf);
215
    
216
    return result;
217
}
218

    
219
#endif