当前位置:网站首页>About the external entity key operation spinbox control in stemwin (fishing_2)
About the external entity key operation spinbox control in stemwin (fishing_2)
2022-07-22 18:22:00 【To_ be_ a_ fisher】
background : Participated in a competition , Then our teacher asked for STemwin Make an interface , Among them, it involves external keys to operate controls , There are mainly two input parameters , I only used two Spinbox Control , Two external keys for control , One is Table key , An increase key .Table Keys are used in two Spinbox Switch between , The increase key is used to change the value , Of course , When adding keys , Will be in Spinbox The callback function under the control sets a limit value , When the limit value is reached, set 0.
The previous problem is , According to anfulai's references in this regard , Regularly read whether the key is pressed , Press the key value if pressed , Then get the key value in the timer callback function , Send different messages according to the key value , The interface reacts differently . When I refresh the interface in real time , That is to say 1s Refresh the interface once , This can be used , Then the teacher thought not 1s Refresh once , It doesn't make much sense , Just brush it once , I'll change the program , The button doesn't move , After the result is modified , The button will not respond normally , I don't know what happened , Then I think it should be a timer for pressing buttons cbtimer There's a problem there , So I decided not to scan the keys regularly , Want to make a way of interruption , Press the key , The interrupt , And then send a message .
Next , It's the point . Change to after interruption , Press the key value in the interrupt , And then in main At the end of the function while(1) Inside , Check whether the key value changes , If there is any change, use GUI_SendKeyMsg Send the corresponding message , The main codes are as follows :
// Add build interrupt service function
void EXTI1_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line1);
//delay_ms(10);
delay_us(10000);
if(PA1==0)
{
bsp_PutKey((uint8_t)(4)); // Press key value
//CHANGE_NUM();
}
}
//Table Key interrupt service function
void EXTI0_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0);
//delay_ms(10); //
delay_us(10000);
if(PA0==0)
{
bsp_PutKey(1); // Press key value
//CHANGE_AIM();
}
}
while(1) Check whether the key value changes :
while(1)
{
keycode(bsp_GetKey());
}
Check whether the key value changes function :
void keycode(int key_code)
{
uint8_t ucKeyCode;
ucKeyCode = key_code;//bsp_GetKey()
if(ucKeyCode != KEY_NONE)
{
switch (ucKeyCode)
{
case KEY_DOWN_K1:
GUI_SendKeyMsg(GUI_KEY_TAB, 1);
GUI_Delay(5);
break;
case KEY_DOWN_K2:
GUI_SendKeyMsg(GUI_KEY_UP, 1);
GUI_Delay(5);
break;
default:
break;
}
}
}
Press key value function :
void bsp_PutKey(uint8_t _KeyCode)
{
s_tKey.Buf[s_tKey.Write] = _KeyCode;
if (++s_tKey.Write >= KEY_FIFO_SIZE)
{
s_tKey.Write = 0;
}
}
Get key value function :
uint8_t bsp_GetKey(void)
{
uint8_t ret;
if (s_tKey.Read == s_tKey.Write)
{
return KEY_NONE;
}
else
{
ret = s_tKey.Buf[s_tKey.Read];
if (++s_tKey.Read >= KEY_FIFO_SIZE)
{
s_tKey.Read = 0;
}
return ret;
}
}
typedef enum
{
KEY_NONE = 0, /* 0 Indicates a key event */
KEY_1_DOWN, /*1 Key pressed */
KEY_1_UP, /* 1 The key bounces */
KEY_1_LONG, /* 1 Long press */
KEY_2_DOWN, /* 2 Key pressed */
KEY_2_UP, /* 2 The key bounces */
KEY_2_LONG /* 2 Long press */
}KEY_ENUM;
Follow the logic and code above , It should be no problem , As a result, I didn't respond when I went down to the board , Later, I debugged online step by step , It is found that the interrupt is generated , The key value is also pressed , Key value changes have also been detected , Then I also sent a message GUI_SendKeyMsg(GUI_KEY_TAB, 1); , But there is no response on the display , Then I had an idea , It feels like there should be no interface redrawing , That is to say, the interface knows the change , But it's not drawn , So I just “ have one 's own way of doing things “” Add an interface redrawing command after sending the message , It's the red part , Then it can work normally !! This problem bothered me for threeorfour days , I have been wondering what went wrong , Then I searched all over the Internet , All the major tutorials have no instructions in this regard , It's all about using emwin Timer provided , stay cbtimer In the callback function of , Scan key values regularly , Now I can finally stop using that , Directly interrupt , In fact, it is not called interruption , Just fake interruption .
This actually explains , Why emwin Of cbtimer Can refresh , I think it's in cbtimer Where in the world , There is an instruction to refresh the interface . Feel this GUI_Delay It's easy to use , ha-ha = =, Of course, this is also because the interface is relatively simple , You can brush it , But if the interface is complex , It may be more troublesome .
Last , Sum up , Now, most of the methods of entity key operation controls on the Internet are using emwin Provided Timer Callback function for cbtimer Regularly check whether the key value changes , Then do the corresponding actions , This really works , But this timing makes me a little confused about the sequence of the program = =, For example, when is the time to query the program , Will it hinder the main program , And what happens when the interruption comes ? wait . then , What I want to share here is , I don't need to check regularly. I use “ Pseudo interrupt ” To operate controls , Press the key , Press the key value into the interrupt ,while Check whether the key value changes , And then send a message , Add another GUI_Delay You can also complete the entity key operation control .
Reference material : Anfulai _STM32-V6 Development board emWin course (V2.0)
Anfulai _STM32-V5 Development board _ User's Manual (V2.0)
emWIN5.12 Chinese Manual
Welcome criticism, correction and exchange !
ps: It took half a month to write down , Ah , I'm so lazy = =
边栏推荐
- Inscription des femmes
- Computer Graphics From Scratch - Chapter 4
- GBase8s数据库以 SET COLLATION 指定对照顺序
- go 并发编程之-工作池
- Jinan Zhangqiu subject three data collection
- Gbase8s database specifies the comparison order with set collation
- What level do programmers need to reach to get 20K monthly salary without pressure?
- "Review of software engineering in Wuhan University of technology" Chapter 5 | software architecture
- 「武汉理工大学 软件工程复习」第五章 | 软件体系结构
- "Review of software engineering in Wuhan University of technology" Chapter 1 | overview of software engineering
猜你喜欢
43. String multiplication
线程学习笔记
QT笔记——Qt动态属性 之 unpolish() 和 polish()
Female guest registration
"Review of software engineering in Wuhan University of technology" Chapter 1 | overview of software engineering
"Review of software engineering in Wuhan University of technology" Chapter 2 | software process model
「武汉理工大学 软件工程复习」第一章 | 软件工程概述
fcntl函数
QT notes - unpolish() and polish() of QT dynamic attributes
QT笔记——QtXml
随机推荐
GBase8s数据库由数据库对象执行的对照
"Review of software engineering in Wuhan University of technology" Chapter 1 | overview of software engineering
What level do programmers need to reach to get 20K monthly salary without pressure?
Web3 sharing
逆袭黑马:数据库全栈工程师(DevDBOps)培训,把最好的课程送给您!
Gbase8s database comparison performed by database objects
Gbase8s database union operator
Gbase8s database specifies the comparison order with set collation
Yunyuanyuan (10) | introduction to kubernetes in kubernetes
Calculate deposit interest
Gbase8s database set constraints statement
"Review of software engineering in Wuhan University of technology" Chapter III software requirements
飞机大战中对象池模式子弹使用
A trick to teach you how to visualize recruitment data ~ is there anyone who can't analyze these data cases?
QT notes - operation EXECL
Go flag package
计算机网络学习笔记7-TCP编程流程及面试题
QT notes - unpolish() and polish() of QT dynamic attributes
Gbase8s database identity connection
PostgreSQL 中 analyze table后most_common_elems 字段为什么不填充?