Project

General

Profile

Statistics
| Branch: | Revision:

pse-2015-16-grupo-3 / tpf / display.c @ 6d70682c

History | View | Annotate | Download (3.79 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
static int lcdHandler;
12
static pse_time_t LCDClock;
13
static uint16_t LCDppower;
14

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

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

    
67

    
68
        }
69
        else
70
        {
71

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

    
74

    
75

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

    
90
uint8_t clearDisplay()
91
{
92
    return 0;
93
}
94

    
95

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

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

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

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

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

    
157
uint8_t initDisplay()
158
{
159
    uint8_t result = 0;
160
    
161
    if(getLCDHandler(&lcdHandler)!=0)
162
    {
163
        result=1;
164
    }
165
    
166
    return result;
167
}
168

    
169

    
170

    
171

    
172

    
173

    
174
#endif