0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TouchGFXを使おう6~Lチカ編2~

Posted at

TouchGFXを使おう5~Lチカ編~の続きです。

今回は、Modelにプログラムを記述し、呼び出すプログラムにします。
今回のプログラムはModelにプログラムを集約できる反面、presenterとviewを繋げる必要があり、コードが増えます。

画面製作

新規プロジェクトを作成し、ボタン2個作成 します。
今回は、LED ONLED OFF の二つにします。
スクリーンショット 2025-01-31 112510.png

インタラクションの設定

Interaction を以下のように設定します。

Interaction1 Interaction2
Trigger Button is clicked Button is clicked
Choose clicked source On_switch Off_switch
Action Call new virtual function new virtual function
Function Name On_Switch_func Off_Switch_func

image.png
image.png

ピン設定

STM32CubeIDEを立ち上げた状態で STM32CubeIDEフォルダprojectファイルダブルクリック しプロジェクトを インポート します。
image.png
OKクリック します。
image.png
立ち上げ後、iocファイル から LED につながる PC2 ピンを GPIO Output にし Generation します。
image.png
image.png
Warning が出ますが Yes で進みます。
image.png
TouchGFXでも変更されたことが表示されますので Yesクリック します。
image.png

model

model.hppOn_LEDOff_LED追加 します。

void On_LED();
void Off_LED();

image.png
model.cppOn_LEDOff_LED追加 します。
ヘッダー

#ifndef SIMULATOR
#include "stm32h7xx_hal.h"
#endif

プログラム内

void Model::On_LED()
{
	#ifndef SIMULATOR
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET);
	#endif
}
void Model::Off_LED()
{
	#ifndef SIMULATOR
	HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET);
	#endif
}

image.png

Screen1View

Screen1View.hpp に関数を宣言します。

protected:
    virtual void On_Switch_func();
    virtual void Off_Switch_func();

image.png
Screen1View.cppにOn_Switch_funcとOff_Switch_funcを追加します。

void Screen1View::On_Switch_func()
{
	presenter -> onlight();

	#ifndef SIMULATOR
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_3);
    #endif
}
void Screen1View::Off_Switch_func()
{
	presenter -> offlight();
}

image.png

Screen1presenter

ModelScreen1View を繋げるコードを Screen1presenter追加 します。
最初に Screen1presenter.hpp に関数を宣言します。

void onlight();
void offlight();

image.png
Screen1presenter.cpp関数追加 します。

void Screen1Presenter::onlight()
{
	model -> On_LED();
}

void Screen1Presenter::offlight()
{
	model -> Off_LED();
}

image.png
コンパイルすることでLEDの点滅が出来るようになります。
TouchGFXを使おう7~ハードウェアボタン編~に続きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?