-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.c
176 lines (144 loc) · 3.38 KB
/
display.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//==============================================================================
// aegis/src/display.c
//------------------------------------------------------------------------------
// Display management
//==============================================================================
#include "aegis.h"
const display_t *display;
DISPLAY_STATUS display_status = DISPLAY_OFF;
uint16_t fgcolor;
uint16_t bgcolor;
uint8_t brightness;
//------------------------------------------------------------------------------
// Display startup.
//------------------------------------------------------------------------------
// Initializes the display global variable and calls the startup process.
//------------------------------------------------------------------------------
void DMStartup( void )
{
display = &ST7735S;
display->Startup();
}
void DMShutdown( void )
{
display->Shutdown();
}
//------------------------------------------------------------------------------
// Display status
//------------------------------------------------------------------------------
void DMSetStatus( DISPLAY_STATUS status )
{
display_status = status;
EMSendEvent1P( EVENT_DISPLAY, EV_D_DISPLAY_STATUS, status );
}
DISPLAY_STATUS DMGetStatus( void )
{
return display_status;
}
//------------------------------------------------------------------------------
// Brightness
//------------------------------------------------------------------------------
void DMSetBrightness( uint8_t b )
{
if ( b > 100 ) b = 100;
brightness = b;
display->SetBrightness( b );
}
void DMDimmer( void )
{
}
//------------------------------------------------------------------------------
// Event Management
//------------------------------------------------------------------------------
void DMEvent( Event_t *ev )
{
switch ( ev->d )
{
case EV_D_DISPLAY_STATUS:
{
switch ( ev->p1 )
{
case DISPLAY_ON:
{
uint8_t b;
VOIGet( VOI_BRIGHTNESS, &b );
DELAYED_EVENT( 1, EVENT_DISPLAY, EV_D_BRIGHTNESS, b, 0 );
break;
}
}
break;
}
case EV_D_SCREEN:
{
SMShowScreen( ev->p1 );
break;
}
case EV_D_BRIGHTNESS:
{
DMSetBrightness( ev->p1 );
break;
}
case EV_D_NULL:
default:
break;
}
}
//------------------------------------------------------------------------------
// Number formatting
//------------------------------------------------------------------------------
// - str: Output buffer. Must be large enough (nbdig+2).
// - num: The number.
// - nbdig: Maximum number of output digits.
// - nbdec: Maximum number of decimal places.
// - exp: Number divider in powers of 10.
//------------------------------------------------------------------------------
void FormatNumber( char *str, uint32_t num, int nbdig, int nbdec, int exp )
{
char buf[10];
int idx = 0;
if ( !nbdig )
{
*str = 0;
return;
}
while ( num )
{
num /= 10;
uint16_t rem = HDIV->DIVREM;
buf[idx++] = '0' + rem;
}
if ( idx <= exp )
{
*str++ = '0';
if ( !nbdec || !--nbdig )
{
*str = 0;
return;
}
if ( idx < exp )
{
*str++ = '.';
int nbz = 0;
while ( nbz++ < ( exp - idx ) )
{
*str++ = '0';
if ( !--nbdec || !--nbdig )
{
*str = 0;
return;
}
}
}
}
while ( nbdig-- )
{
if ( idx == exp && nbdec ) *str++ = '.';
if ( idx <= exp && !nbdec-- )
{
*str = 0;
return;
}
*str++ = idx ? buf[--idx] : '0';
}
*str = 0;
}