手机网站生成app客户端,广告品牌营销策划公司,wordpress wp-postviews插件,免费的网站后台touchGFX采用MVP架构#xff0c;如下所示#xff1a; 本文界面如下所示#xff1a; 本文将实现两个操作#xff1a; 1、触摸屏点击开关按键实现打印开关显示信息#xff0c;模拟开关灯效果 2、板载案按键控制触摸屏LED灯的显示和隐藏
一、触摸屏点击开关按键实现打印开…touchGFX采用MVP架构如下所示 本文界面如下所示 本文将实现两个操作 1、触摸屏点击开关按键实现打印开关显示信息模拟开关灯效果 2、板载案按键控制触摸屏LED灯的显示和隐藏
一、触摸屏点击开关按键实现打印开关显示信息模拟开关灯效果
实现的方向为view-present-model
1、添加led开关交互事件button_clicked_led 2、screenView.hpp中声明button_clicked_led函数再到screenView.cpp中定义此函数并执行通知Presenter层 3、screenPresenter.hpp中声明button_clicked_led函数screenPresenter.cpp中定义此函数将消息传递给model层 4、Model.hpp中声明button_clicked_led函数Model.cpp中定义此函数将依据此消息执行开关灯操作 如此即可完成触摸屏开关控制硬件led灯的亮灭
二、板载案按键控制触摸屏LED灯的显示和隐藏
流程方向model-modelListener-present-view
1、ModelListener.hpp中声明函数notify_key_event并在Model.cpp中定义此函数将外部按键的动作通知给modelListener
因为ModelListener被Model继承了也被screenPresenter继承了
2、screenPresenter.hpp中声明函数notify_key_event并在screenPresenter.cpp中定义此函数并通知给view 3、screenView.hpp中声明函数notify_key_event并在screenView.cpp中定义此函数并更改界面灯的显示隐藏 image1_led是这个灯的名字哈 如此就实现了外部按键控制触摸屏
三、补充另一个按键切换屏幕背景色 添加KeyController.cpp|KeyController.hpp文件
KeyController.cpp
#include KeyController.hpp
#include Key_Driver.husing namespace touchgfx;void KeyController::init()//按键初始化
{//Key_Init();//在BSP中统一初始化
}bool KeyController::sample(uint8_t key)//按键扫描
{uint8_t value 0;if(Key_ScanPin(value) 0)return false;//Key_ScanPin按键扫描并获取键值key value;return true;
}
KeyController.hpp
#ifndef SCREENVIEW_HPP
#define SCREENVIEW_HPP#include gui_generated/screen_screen/screenViewBase.hpp
#include gui/screen_screen/screenPresenter.hpp
#include stdint.hclass screenView : public screenViewBase
{
public:screenView();virtual ~screenView() {}virtual void setupScreen();virtual void tearDownScreen();virtual void button_clicked_led();virtual void notify_key_event(uint8_t event,uint8_t KeyValue);
protected:
};#endif // SCREENVIEW_HPP
TouchGFXHAL.cpp添加按键执行代码 打开TouchGFXHAL.cpp文件新建一个KeyController对象 然后在void TouchGFXHAL::initialize()里面这个对象赋值给系统记得调用初始化函数 如此即可实现按键改变屏幕背景色
三、参考文章
没使用过touchGFX则先看视频https://www.yuanzige.com/course/detail/80229 Model-View-Presenter设计模式示例https://smallash.blog.csdn.net/article/details/127047799?spm1001.2014.3001.5502
四、学习笔记