-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.c
241 lines (164 loc) · 5.84 KB
/
menu.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*------------------------------------------------------------------------------*/
/* INCLUDE FILES */
/*------------------------------------------------------------------------------*/
// standard headers
#include <p18cxxx.h>
// user headers
#include "Menu.h"
#include "oled.h"
#include "mtouch.h"
#include "BMA150.h"
#include "Timer.h"
#include "WDT.h"
#include "Game.h"
/*------------------------------------------------------------------------------*/
/* LOCAL CONSTATS DEFINITION */
/*------------------------------------------------------------------------------*/
#define MENU_ENTRIES_SHIFT 20
#define ENTRY_NAME_MAX_LEN 20
#define MENU_MAX_ENRIES 4
/*------------------------------------------------------------------------------*/
/* LOCAL MACROS DEFINITION */
/*------------------------------------------------------------------------------*/
#ifndef NULL
#define NULL 0
#endif
/*------------------------------------------------------------------------------*/
/* TYPES DEFINITION */
/*------------------------------------------------------------------------------*/
typedef enum {
EVMenuIndex_Main = 0,
EVMenuIndex_Timers,
EVMenuIndex_Len
} EMenuIndex;
typedef struct {
char entryName[ENTRY_NAME_MAX_LEN];
char nextMenu;
PFMenuHandler pfHandler;
} SMenuEntry;
typedef struct {
char menuTitle[ENTRY_NAME_MAX_LEN];
int len;
char prevMenu;
SMenuEntry entries[MENU_MAX_ENRIES];
} SMenu;
/*------------------------------------------------------------------------------*/
/* LOCAL FUNCTIONS DECLERATION */
/*------------------------------------------------------------------------------*/
static void Menu_Show(SMenu *menu, int select);
/*------------------------------------------------------------------------------*/
/* LOCAL VARIABLES */
/*------------------------------------------------------------------------------*/
static SMenu sMenu[] = {
{"Main", 2, -1, {
{"Game", -1, game},
{"About", -1, about},
}
}
};
/*------------------------------------------------------------------------------*/
/* EXPORT FUNCTIONS DEFINITIONS */
/*------------------------------------------------------------------------------*/
/********************************************************************************
* *
* DATE: 15/01/2012 *
* *
* DESCRIPTION: *
* *
* RETURN VALUE: *
* *
* AUTHOR: Oren Kapah *
* *
********************************************************************************/
void Menu_Run(void)
{
EMenuIndex menuIndex = EVMenuIndex_Main;
int curSel = 0;
BOOL refresh = TRUE;
Static_menu(); // my addition, show the static menu
while (1)
{
// show the menu
if (refresh)
{
Menu_Show(&sMenu[menuIndex], curSel);
refresh = FALSE;
while (mTouch_GetPushedButton() != EVmTouchButton_NumberOfPads); // wait for the finger to be removed
}
// check which button was touched
switch (mTouch_GetPushedButton())
{
case EVmTouchButton_Right: // select
// check if we should change the current menu
if (sMenu[menuIndex].entries[curSel].nextMenu != (-1))
{
menuIndex = sMenu[menuIndex].entries[curSel].nextMenu;
curSel = 0;
refresh = TRUE;
}
// check if we should run a handler function
else if (sMenu[menuIndex].entries[curSel].pfHandler != NULL)
{
(*sMenu[menuIndex].entries[curSel].pfHandler)();
refresh = TRUE;
Static_menu(); // my addition, show the static menu
}
break;
case EVmTouchButton_Up: // move one entry up
if (curSel > 0)
curSel--;
refresh = TRUE;
break;
case EVmTouchButton_Down: // move one entry up
if (curSel < (sMenu[menuIndex].len-1))
curSel++;
refresh = TRUE;
break;
case EVmTouchButton_Left: // cancel
// check if we have a previous menu
if (sMenu[menuIndex].prevMenu != (-1))
{
menuIndex = sMenu[menuIndex].prevMenu;
curSel = 0;
refresh = TRUE;
}
break;
}
ClrWdt(); // clear the watchdog
}
} // End of Menu_Run
static void Menu_Show(SMenu *menu, int select)
{
int i;
for (i=0; i<menu->len; i++)
Oled_PutString(menu->entries[i].entryName, i+6, MENU_ENTRIES_SHIFT, i==select);
} // End of Menu_Show
void Static_menu()
{
char score[] = {"hi-score"};
char buff[4];
char play[] = {"PLAY"};
char space[] = {"SPACE INVADERS"};
char press[] = {"Press R button"};
char alien1[] = {"C = 10 pts"};
char alien2[] = {"A = 20 pts"};
unsigned short int address = 0xAAAA; // adress in the EEPROM
int temp, len = 2; // 1 high score (8 bit MSB and 8 bit LSB)
static BYTE data[2];
Oled_Init();
Oled_Clear();
mTouch_Init();
mTouch_Calibrate();
SetMode(Aliens);
Oled_PutString(alien1, 4, 30, 0);
Oled_PutString(alien2, 5, 30, 0);
SetMode(Words);
Oled_PutString(score, 0, 15, 0);
Oled_PutString(play, 2, 50, 0);
Oled_PutString(space, 3, 20, 0);
RomRead(address, data, len); // get the high score.
temp = (data[0]*256) + (data[1]); //**note for calculation** 8 bit MSB*256 + 8 bit LSB == 16 bit word
SetMode(Words);
sprintf(buff,"%d", temp);
Oled_PutString(buff, 0, 85, 0);
}