注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
damiaa的个人空间 https://home.eeworld.com.cn/space-uid-59433.html [收藏] [复制] [分享] [RSS]
日志

【STM32H7S78-DK】 六 可设置时钟及代码分析

已有 165 次阅读2024-11-3 22:14 |个人分类:STM32

                      【STM32H7S78-DK】 五 乱序键盘实现及分析
 
 

一、打开touchgfx designer ,加上提示文本数字时钟显示文本和模拟显示界面这里直接使用例子里面的界面导过来。
加上时钟的时分秒设置的加减键,时钟设置的开始键,OK键其实没什么用,这里页懒得删除了。如下图所示:

 

二、给每个按钮设置Interactions为按下后调用虚函数。每个虚函数名字不一样 如下。

 

三、打开代码MainView.hpp中加入虚函数和一些时钟变量和时钟设置标记如下:

 

四、MainView.cpp中加入虚函数和更新按键函数的具体实现如下:

每秒更新实现
时分秒设置按键实现
允许设置和OK键 这里其实OK键没什么用懒得删除了,允许设置在没选中
也可以设置时间,只是时间还是走,设置允许就时钟不走,可以专注设置。
 
五、主要代码:
MainView.hpp:
#ifndef MAIN_VIEW_HPP
#define MAIN_VIEW_HPP

#include <gui_generated/main_screen/MainViewBase.hpp>
#include <gui/main_screen/MainPresenter.hpp>

class MainView : public MainViewBase
{
public:
    MainView();
    virtual ~MainView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();

    virtual void handleTickEvent();
	virtual void bt1_function();
	virtual void bt2_function();
	virtual void bt3_function();
	virtual void bt4_function();
	virtual void bt5_function();
	virtual void bt6_function();
	virtual void toggle_function();
	virtual void OK_function();
protected:
    int tickCounter;
    int analogHours;
    int analogMinutes;
    int analogSeconds;
    int digitalHours;
    int digitalMinutes;
    int digitalSeconds;
	
	bool setflag;
};

#endif // MAIN_VIEW_HPP

MainView.cpp:

#include <gui/main_screen/MainView.hpp>

MainView::MainView() :
    tickCounter(0)
{
}

void MainView::setupScreen()
{
    MainViewBase::setupScreen();
    digitalHours = digitalClock.getCurrentHour();
    digitalMinutes = digitalClock.getCurrentMinute();
    digitalSeconds = digitalClock.getCurrentSecond();

    analogHours = analogClock.getCurrentHour();
    analogMinutes = analogClock.getCurrentMinute();
    analogSeconds = analogClock.getCurrentSecond();
}

void MainView::tearDownScreen()
{
    MainViewBase::tearDownScreen();
}

void MainView::handleTickEvent()
{
    if(true != setflag )
	{
		tickCounter++;
		if (tickCounter % 60 == 0)
		{
			if (++digitalSeconds >= 60)
			{
				digitalSeconds = 0;
				if (++digitalMinutes >= 60)
				{
					digitalMinutes = 0;
					if (++digitalHours >= 24)
					{
						digitalHours = 0;
					}
				}
			}
			if (++analogSeconds >= 60)
			{
				analogSeconds = 0;
				if (++analogMinutes >= 60)
				{
					analogMinutes = 0;
					if (++analogHours >= 24)
					{
					    analogHours = 0;
					}
				}
			}
			// Update the clocks		
			digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
			analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
		}
	}
}

void MainView::bt1_function()
{
	if(digitalHours >=23)
		digitalHours =0;
	else
		digitalHours++;
	analogHours =digitalHours;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt2_function()
{
	if(digitalHours ==0)
		digitalHours =23;
	else
		digitalHours--;
	analogHours =digitalHours;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt3_function()
{
	if(digitalMinutes >=59)
		digitalMinutes =0;
	else
		digitalMinutes++;
	analogMinutes =digitalMinutes;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt4_function()
{
	if(digitalMinutes == 0)
		digitalMinutes=59;
	else
		digitalMinutes--;
	analogMinutes =digitalMinutes;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt5_function()
{
	if(digitalSeconds >=59)
		digitalSeconds=0;
	else
		digitalSeconds++;
	analogSeconds =digitalSeconds;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::bt6_function()
{
	if(0 ==digitalSeconds)
		digitalSeconds=59;
	else
		digitalSeconds--;
	analogSeconds =digitalSeconds;
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
}
void MainView::toggle_function()
{
	// Override and implement this function in Main
	//setflag 
	 setflag =toggleButton1.getState();
}
void MainView::OK_function()
{
	digitalClock.setTime24Hour(digitalHours, digitalMinutes, digitalSeconds);
	analogClock.setTime24Hour(analogHours, analogMinutes, analogSeconds);
	toggleButton1.forceState(false);
	digitalClock.invalidate();
	toggleButton1.invalidate();
}

 

六、编译运行,效果如下:
5

 
好,先分析到这里。
                                                                                           谢谢

本文来自论坛,点击查看完整帖子内容。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章