Files
@ 675c16cde5b1
Branch filter:
Location: therm/libraries/oleddrv/menu.c - annotation
675c16cde5b1
5.3 KiB
text/plain
Intial unworking USB library import
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 | 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa 1c5909c633fa | /*******************************************************************************
* File Name : menu.c
* Author : lxyppc
* Version : V1.0
* Date : 10-03-05
* Description : Menu implement
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "menu.h"
#include "SSD1303.h"
#include "Graphics\Graphics.h"
#include "time.h"
#include "icon.h"
#include "bsp.h"
#include "ClockUI.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static const MenuItem* curMenuItem;
static u8 preQuit = 0;
extern const LPCSTR* curLang;
extern const MenuItem MainMenu[];
extern const MenuItem RootMenu;
static MenuFunc_t menuProc = 0;
extern Device appDevice;
/* Private function prototypes -----------------------------------------------*/
void UpdateMenu(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : InitialMenu
* Description : Initialize the menu
* Input : None
* Output : None
* Return : None
*******************************************************************************/
MenuFunc_t InitialMenu()
{
InitialDevice(&appDevice,&SSD1303_Prop,SongSmall5_DrawChar);
curMenuItem = MainMenu;
menuProc = RootMenu.pfnMenu;
Msg msg = {.param = 0, .message = MSG_INIT};
menuProc(0,&msg);
return MR_Finish;
}
unsigned long MenuProcess(Msg* msg)
{
if(menuProc){
if(menuProc((void*)curMenuItem,msg) == MR_Finish){
menuProc = 0;
UpdateMenu();
}
return 0;
}
unsigned char menuUpdate = 0;
switch(msg->message){
case MSG_SCROLL:
if((signed long)msg->param > 0){
// Scroll down
if(preQuit){
preQuit = 0;
menuUpdate = 1;
}else{
unsigned char idx = curMenuItem->index+1;
if(idx >= curMenuItem->cnt){
//curMenuItem = curMenuItem - curMenuItem->index;
}else{
curMenuItem++;
menuUpdate = 1;
}
}
}else{
// Scroll up
if(curMenuItem->index){
curMenuItem--;
menuUpdate = 1;
}else{
menuUpdate = !preQuit;
preQuit = 1;
}
}
break;
case MSG_KEY_UP:
if(preQuit){
preQuit = 0;
curMenuItem = curMenuItem->parent;
menuUpdate = 1;
if(!curMenuItem){
menuProc = RootMenu.pfnMenu;
}
}else{
if(curMenuItem->type & MT_SUB){
curMenuItem = curMenuItem->child;
menuUpdate = 1;
}else{
menuProc = curMenuItem->pfnMenu;
}
}
break;
default:
return 0;
}
if(menuProc){
Msg ini = { .param = 0, .message = MSG_INIT};
menuProc((void*)curMenuItem,&ini);
}else{
if(menuUpdate){
UpdateMenu();
}
}
return 0;
}
#define MARGIN 1
#define LEFT_MARGIN 12
#define MENU_HEIGHT 12
void UpdateMenu(void)
{
const char* text;
if(!curMenuItem)return;
SetColor(BLACK);
ClearDevice();
if(curMenuItem->parent){
text = curLang[curMenuItem->parent->res];
}else{
text = curLang[RootMenu.res];
}
Pos_t x;
if(preQuit){
x = TextOut_HighLight(&appDevice, 0, 0, text ,0xFF);
}else{
x = TextOut(&appDevice, 0, 0, text ,0xFF);
}
TextOut(&appDevice, x, 0, "<<" ,0xFF);
Pos_t y = MENU_HEIGHT + MARGIN;
const MenuItem* items = curMenuItem;
if(curMenuItem->index){
items--;
}
for(u32 i=0; i<4; i++){
text = curLang[items->res];
if(items == curMenuItem && !preQuit){
TextOut_HighLight(&appDevice, LEFT_MARGIN, y, text ,0xFF);
}else{
TextOut(&appDevice, LEFT_MARGIN, y, text ,0xFF);
}
if(items->index + 1 == items->cnt){
break;
}
items++;
y += MENU_HEIGHT + MARGIN;
}
}
MenuResult PopupMenu(const MenuItem* menu)
{
curMenuItem = menu;
return MR_Finish;
}
/**
Message realted definitions
*/
#define MSG_STACK_SIZE 16
#define MSG_STACK_MASK 15
static unsigned char wrMsgIndex = 0;
static unsigned char rdMsgIndex = 0;
static Msg msgStack[MSG_STACK_SIZE];
/*******************************************************************************
* Function Name : GetMessage
* Description : Get message
* Input : None
* Output : None
* Return : None
*******************************************************************************/
unsigned long GetMessage(Msg* msg)
{
if(wrMsgIndex != rdMsgIndex){
Msg* p = &msgStack[rdMsgIndex & MSG_STACK_MASK];
msg->message = p->message;
msg->param = p->param;
rdMsgIndex++;
return 1;
}
return 0;
}
unsigned long PostMessage(Msg* msg)
{
Msg* p = &msgStack[wrMsgIndex & MSG_STACK_MASK];
p->message = msg->message;
p->param = msg->param;
wrMsgIndex++;
return 0;
}
|