-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreens.c
186 lines (154 loc) · 3.84 KB
/
screens.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
176
177
178
179
180
181
182
183
184
185
//==============================================================================
// aegis/src/screens.c
//------------------------------------------------------------------------------
// Screens management
//==============================================================================
#include "aegis.h"
#include "screens.h"
//------------------------------------------------------------------------------
// Screen object definition
//------------------------------------------------------------------------------
typedef struct screen_desc
{
uint8_t dialog;
uint32_t refresh_rate;
uint32_t duration;
void (*pf_init)( void );
int (*pf_draw)( void );
int (*pf_refresh)( void );
void (*pf_close)( void );
int (*pf_event)( Event_t *ev );
}
screen_desc_t;
static int screen_cls( void ) { display->CLS(); return 1; }
static void screen_null( void ) {}
static int screen_null_draw( void ) { return 1; }
static int screen_noev( Event_t *ev ) { return 0; }
static const screen_desc_t screens[] =
{
[SCREEN_OFF] =
{
0,
0,
0,
screen_null,
screen_cls,
screen_null_draw,
screen_null,
screen_noev
},
[SCREEN_MAIN] =
{
0,
50,
0,
ScrMainInit,
ScrMainDraw,
ScrMainRefresh,
ScrMainClose,
ScrMainEvent
},
[SCREEN_IDLE] =
{
0,
0,
0,
ScrIdleInit,
ScrIdleDraw,
screen_null_draw,
ScrIdleClose,
ScrIdleEvent
}
};
#define NUM_SCREENS (sizeof(screens)/sizeof(screen_desc_t))
typedef struct screen
{
const screen_desc_t *s;
uint32_t opening_tick;
uint32_t last_refresh;
SCREENID sid;
SCREENID last_sid;
}
screen_t;
static screen_t screen =
{
.sid = SCREEN_NONE,
.last_sid = SCREEN_NONE
};
//------------------------------------------------------------------------------
// Initialization. Call at startup.
//------------------------------------------------------------------------------
void SMStartup( void )
{
SMScreen( SCREEN_OFF );
}
//------------------------------------------------------------------------------
// Screen invocation (gently asked).
//------------------------------------------------------------------------------
void SMScreen( SCREENID sid )
{
EMSendEvent1P( EVENT_DISPLAY, EV_D_SCREEN, sid );
}
//------------------------------------------------------------------------------
// Screen invocation (now do it).
//------------------------------------------------------------------------------
void SMShowScreen( SCREENID sid )
{
if ( sid >= NUM_SCREENS ) return;
const screen_desc_t *s = &screens[sid];
if ( screen.s )
{
if ( s->dialog )
{
if ( !screen.s->dialog )
screen.last_sid = screen.sid;
}
screen.s->pf_close();
}
screen.s = s;
screen.sid = sid;
screen.s->pf_init();
screen.last_refresh = 0;
}
//------------------------------------------------------------------------------
// Screen refresh.
//------------------------------------------------------------------------------
void SMRefresh( void )
{
if ( DMGetStatus() != DISPLAY_ON ) return;
uint32_t t = GetSysTick();
if ( ( screen.s->duration ) && ( t - screen.opening_tick > screen.s->duration ) )
{
SMScreen( screen.last_sid );
return;
}
if ( !screen.last_refresh )
{
if ( screen.s->pf_draw() )
{
screen.opening_tick = t;
screen.last_refresh = t;
}
}
else if ( ( screen.s->refresh_rate ) && ( t - screen.last_refresh > screen.s->refresh_rate ) )
{
if ( screen.s->pf_refresh() )
{
screen.last_refresh = t;
}
}
}
//------------------------------------------------------------------------------
// Key Event.
//------------------------------------------------------------------------------
int SMInputEvent( Event_t *ev )
{
return screen.s->pf_event( ev );
}
//------------------------------------------------------------------------------
// Display/Screen Event.
//------------------------------------------------------------------------------
int SMDisplayEvent( Event_t *ev )
{
return 0;
}