abner_ma 发表于 2023-2-27 19:55

基于STM32G0的低成本UI设计软件

本帖最后由 abner_ma 于 2023-2-27 19:56 编辑

#申请原创#      项目开发,基于STM32+flash做GUI,发现一个比较不错的GUI设计软件:FlyThings Lite,FlyThings Lite 等价于 FlyThings for MCU。它是 FlyThings 为 MCU 提供的无操作系统简化版本。 超低成本界面系统。低于 2K 的 RAM,16KFlash的硬件资源消耗。使用 FlyThingsLite IDE 开发工具快速设计界面。支持 ZKBITMAP 高达 90%压缩率的 BITMAP 编解码算法。Opencpu 的模式,更便于用户使用,相比传统串口屏直接节省一个 MCU。如果用STM32高性能MCU加持FlyThings Lite,GUI更加绚丽!
   

适配不同MCU平台:





软件接口:
    src/logic 目录下的文件每个界面都会对应一个 c 文件如 main.c。
每一个UI文件都会在logic文件夹下生成同名的头文件及.c源文件。 默认实现了所有的回调函数,包括定时器、按键点击动作、进度条的改变事件等。
可以在对应的函数体内,添加自己的逻辑代码,实现各种操作




#ifndef _LOGIC_MAIN_H_
#define _LOGIC_MAIN_H_

#include "context/guicontext.h"

#define UI_WIDGET_MAIN_ArtText1             ((imagetext_t*)gui_context_find_widget(2))

void ui_main_on_page_open(uint8_t page);

/**
* @brief 定时器回调接口
* @param time   定时器周期,单位 ms
* @param count累计次数
*/
void ui_main_on_timer(uint32_t millisecond, uint32_t count);

/**
* @brief 按钮点击事件回调接口
* @param button   按钮控件指针
* @param type   触摸事件类型
*/
void ui_main_on_button_touch_event(button_t *button, touch_type_e type);

/**
* @brief 进度条回调接口
* @param progress进度条控件指针
* @param val       进度值
*/
void ui_main_on_progress_changed(progress_t *progress, uint16_t val);

/**
* @brief 动画播放结束回调接口
* @param animation动画控件指针
*/
void ui_main_on_animation_play_end(animation_t *animation);

#endif /*_LOGIC_MAIN_H_*/




#include "logic/main.h"
void ui_main_on_page_open(uint8_t page) {
页面打开的时候回调用这个页面,其中 page 是页面 id 号。
打开页面前的一些初始化可在此操作。
}
void ui_main_on_timer(uint32_t millisecond, uint32_t count) {
在 flyport/timer.c 中适配的定时器运行的时候这边会产生回调。其中
millisecond 是间隔时间,count 是回调次数。也就是实际工作时间
=millisecond*count
}
void ui_main_on_button_touch_event(button_t *button,
touch_type_e type) {
触控按键的时候调用,button 是按键对应的控件名,可以通过
logic/main.h 中的宏定义匹配按键。
如下是 main.h 中的内容。
#define UI_WIDGET_MAIN_Animation1
((animation_t*)gui_context_find_widget(2))
#define UI_WIDGET_MAIN_Button1
((button_t*)gui_context_find_widget(3))
代码可以描述为:
if(button == UI_WIDGET_MAIN_Button1)
来指示按键按下的是 button1.    UI框架回调接口的实现文件,包含了所有回调函数的实现,有兴趣可以查看,不要修改。
#include "context/guicontext.h"

#include "logic/main.h"
#include "logic/main01.h"
#include "logic/main02.h"
#include "logic/main03.h"
#include "logic/main04.h"
#include "logic/main05.h"
#include "logic/main06.h"

/**
* @brief 定时器回调接口
* @param millisecond   定时器周期,单位 ms
* @param count累计次数
*/
void on_timer(uint32_t millisecond, uint32_t count) {
typedef void (*Callback)(uint32_t millisecond, uint32_t count);
const Callback callbacks[] = {
    ui_main_on_timer,
    ui_main01_on_timer,
    ui_main02_on_timer,
    ui_main03_on_timer,
    ui_main04_on_timer,
    ui_main05_on_timer,
    ui_main06_on_timer
};
(callbacks)(millisecond, count);
}

/**
* @brief 页面打开回调接口
* @param page   页面ID
*/
void on_page_open(uint8_t page) {
typedef void (*Callback)();
const Callback callbacks[] = {
    ui_main_on_page_open,
    ui_main01_on_page_open,
    ui_main02_on_page_open,
    ui_main03_on_page_open,
    ui_main04_on_page_open,
    ui_main05_on_page_open,
    ui_main06_on_page_open
};
(callbacks)();
}

/**
* @brief 按钮点击事件回调接口
* @param button   按钮控件指针
* @param type   触摸事件类型
*/
void on_button_touch_event(button_t *button, touch_type_e type) {
typedef void (*Callback)(button_t *button, touch_type_e type);
const Callback callbacks[] = {
    ui_main_on_button_touch_event,
    ui_main01_on_button_touch_event,
    ui_main02_on_button_touch_event,
    ui_main03_on_button_touch_event,
    ui_main04_on_button_touch_event,
    ui_main05_on_button_touch_event,
    ui_main06_on_button_touch_event
};
(callbacks)(button, type);
}

/**
* @brief 进度条回调接口
* @param progress进度条控件指针
* @param val       进度值
*/
void on_progress_changed(progress_t *progress, uint16_t val) {
typedef void (*Callback)(progress_t *progress, uint16_t val);
const Callback callbacks[] = {
    ui_main_on_progress_changed,
    ui_main01_on_progress_changed,
    ui_main02_on_progress_changed,
    ui_main03_on_progress_changed,
    ui_main04_on_progress_changed,
    ui_main05_on_progress_changed,
    ui_main06_on_progress_changed
};
(callbacks)(progress, val);
}

/**
* @brief 动画播放结束回调接口
* @param animation动画控件指针
*/
void on_animation_play_end(animation_t *animation) {
typedef void (*Callback)(animation_t *animation);
const Callback callbacks[] = {
    ui_main_on_animation_play_end,
    ui_main01_on_animation_play_end,
    ui_main02_on_animation_play_end,
    ui_main03_on_animation_play_end,
    ui_main04_on_animation_play_end,
    ui_main05_on_animation_play_end,
    ui_main06_on_animation_play_end
};
(callbacks)(animation);
}
https://www.bilibili.com/video/BV1VS4y1B7sg/?spm_id_from=333.999.0.0





页: [1]
查看完整版本: 基于STM32G0的低成本UI设计软件