AWTK 开源串口屏开发(5) - MCU端 SDK 用法

news/2024/7/10 19:52:44 标签: 开源, 单片机, 嵌入式硬件, AWTK, 串口屏, MVVM

AWTK 开源智能串口屏,不但开放了串口屏端全部源码,还提供了MCU 端 SDK,大大加快 MCU 软件的开发。本介绍一下 MCU 端 SDK 在不同平台上的用法。

完整示例可以参考下面的几个例子:

  • 普通嵌入式系统 mcu/stm32/hmi_app/hmi_app.c

  • 低端嵌入式系统 mcu/mini-sdk/hmi/examples/socket/main.c

  • Arduino 系统 mcu/mini-sdk/hmi/examples/arduino/awtk_hmi_demo.ino

在这里插入图片描述

  • MCU 模拟器 simulator/src/pages/home_page.c

在这里插入图片描述

基本用法

  • 创建 hmi 对象

创建 hmi 对象时,需要提供一个回调函数,当属性变化时,会调用这个函数。

示例

static ret_t hmi_on_prop_change(hmi_t* hmi, const char* name, const value_t* v) {
  /*处理参数变化*/
  if (tk_str_eq(name, "温度")) {
    int32_t temp = value_int(v);
    log_debug("temp=%d\n", temp);
  }

  return RET_OK;
}

...
  io = tk_stream_factory_create_iostream(url);
  hmi = hmi_create(io, hmi_on_prop_change, NULL);
  • 设置属性

示例

  hmi_set_prop_int(hmi, "温度", 36);
  • 获取属性

示例

  int32_t temp = hmi_get_prop_int(hmi, "温度", 0);
  • 在主循环中分发事件

示例

  hmi_dispatch(hmi);

完整示例


/*本文必须保存为 UTF-8 BOM 格式 */

#include "tkc/mem.h"
#include "hmi/hmi.h"

static int s_value = 0;
static uint32_t s_heap_mem[10240];

#define HMI_PROP_TEMP "温度"

/*回调函数*/
static ret_t hmi_on_prop_change(hmi_t* hmi, const char* name, const value_t* v) {
  if (strcmp(name, "温度") == 0) {
    s_value = value_int(v);
  }

  return RET_OK;
}

static void system_init(void) {
  Cache_Enable();                  //打开L1-Cache
  HAL_Init();                      //初始化HAL库
  Stm32_Clock_Init(160, 5, 2, 4);  //设置时钟,400Mhz
  delay_init(400);                 //延时初始化
  LED_Init();                      //初始化LED
  KEY_Init();                      //初始化按键
}

int main(void) {
  u8 key = 0;
  hmi_t* hmi = NULL;

  system_init();

  /*初始化内存*/
  tk_mem_init(s_heap_mem, sizeof(s_heap_mem));

  /*创建HMI对象*/
  hmi = hmi_create_with_serial("1", hmi_on_prop_change, NULL);

  while (1) {
    key = KEY_Scan(0);
    if (key) {
      switch (key) {
        case KEY2_PRES: {
          s_value = 0;
          break;
        }
        case KEY1_PRES: {
          s_value--;
          break;
        }
        case KEY0_PRES: {
          s_value++;
          break;
        }
        default: {
          break;
        }
      }

      /*修改数据*/
      hmi_set_prop_int(hmi, HMI_PROP_TEMP, s_value);
    } else {
      delay_ms(10);
    }

    /*分发事件*/
    hmi_dispatch(hmi);
  }
}

API 参考

串口屏客户端(供 MCU 使用)。


函数

函数名称说明
hmi_create创建hmi对象。
hmi_create_with_serial创建hmi对象。
hmi_destroy销毁hmi对象。
hmi_dispatch处理事件。
hmi_get_prop获取属性。
hmi_get_prop_bool获取布尔属性。
hmi_get_prop_float获取浮点数属性。
hmi_get_prop_int获取整数属性。
hmi_get_prop_int64获取64位整数属性。
hmi_get_prop_str获取字符串属性。
hmi_set_prop设置属性。
hmi_set_prop_bool设置布尔属性。
hmi_set_prop_float设置浮点数属性。
hmi_set_prop_int设置整数属性。
hmi_set_prop_int64设置64位整数属性。
hmi_set_prop_str设置字符串属性。

属性

属性名称类型说明
remote_uiremote_ui_t*remote ui 对象。
hmi_create 函数

  • 函数功能:

创建hmi对象。

  • 函数原型:
hmi_t* hmi_create (tk_iostream_t* io, hmi_on_prop_changed_t on_prop_changed, void* ctx);
  • 参数说明:
参数类型说明
返回值hmi_t*返回hmi对象。
iotk_iostream_t*流对象。
on_prop_changedhmi_on_prop_changed_t属性变化回调函数。
ctxvoid*上下文。
hmi_create_with_serial 函数

  • 函数功能:

创建hmi对象。

  • 函数原型:
hmi_t* hmi_create_with_serial (const char* device, hmi_on_prop_changed_t on_prop_changed, void* ctx);
  • 参数说明:
参数类型说明
返回值hmi_t*返回hmi对象。
deviceconst char*串口设备。
on_prop_changedhmi_on_prop_changed_t属性变化回调函数。
ctxvoid*上下文。
hmi_destroy 函数

  • 函数功能:

销毁hmi对象。

  • 函数原型:
ret_t hmi_destroy (hmi_t* hmi);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
hmi_dispatch 函数

  • 函数功能:

处理事件。

  • 函数原型:
ret_t hmi_dispatch (hmi_t* hmi);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
hmi_get_prop 函数

  • 函数功能:

获取属性。

  • 函数原型:
ret_t hmi_get_prop (hmi_t* hmi, const char* target, const char* name, value_t* v);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
targetconst char*目标对象。
nameconst char*属性名称。
vvalue_t*属性值。
hmi_get_prop_bool 函数

  • 函数功能:

获取布尔属性。

  • 函数原型:
bool_t hmi_get_prop_bool (hmi_t* hmi, const char* name, bool_t defvalue);
  • 参数说明:
参数类型说明
返回值bool_t返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvaluebool_t默认值。
hmi_get_prop_float 函数

  • 函数功能:

获取浮点数属性。

  • 函数原型:
float hmi_get_prop_float (hmi_t* hmi, const char* name, float defvalue);
  • 参数说明:
参数类型说明
返回值float返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvaluefloat默认值。
hmi_get_prop_int 函数

  • 函数功能:

获取整数属性。

  • 函数原型:
int32_t hmi_get_prop_int (hmi_t* hmi, const char* name, int32_t defvalue);
  • 参数说明:
参数类型说明
返回值int32_t返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvalueint32_t默认值。
hmi_get_prop_int64 函数

  • 函数功能:

获取64位整数属性。

  • 函数原型:
int64_t hmi_get_prop_int64 (hmi_t* hmi, const char* name, int64_t defvalue);
  • 参数说明:
参数类型说明
返回值int64_t返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvalueint64_t默认值。
hmi_get_prop_str 函数

  • 函数功能:

获取字符串属性。

  • 函数原型:
const char* hmi_get_prop_str (hmi_t* hmi, const char* name, const char* defvalue);
  • 参数说明:
参数类型说明
返回值const char*返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvalueconst char*默认值。
hmi_set_prop 函数

  • 函数功能:

设置属性。

  • 函数原型:
ret_t hmi_set_prop (hmi_t* hmi, const char* target, const char* name, const value_t* v);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
targetconst char*目标对象。
nameconst char*属性名称。
vconst value_t*属性值。
hmi_set_prop_bool 函数

  • 函数功能:

设置布尔属性。

  • 函数原型:
ret_t hmi_set_prop_bool (hmi_t* hmi, const char* name, bool_t value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valuebool_t属性值。
hmi_set_prop_float 函数

  • 函数功能:

设置浮点数属性。

  • 函数原型:
ret_t hmi_set_prop_float (hmi_t* hmi, const char* name, float value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valuefloat属性值。
hmi_set_prop_int 函数

  • 函数功能:

设置整数属性。

  • 函数原型:
ret_t hmi_set_prop_int (hmi_t* hmi, const char* name, int32_t value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueint32_t属性值。
hmi_set_prop_int64 函数

  • 函数功能:

设置64位整数属性。

  • 函数原型:
ret_t hmi_set_prop_int64 (hmi_t* hmi, const char* name, int64_t value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueint64_t属性值。
hmi_set_prop_str 函数

  • 函数功能:

设置字符串属性。

  • 函数原型:
ret_t hmi_set_prop_str (hmi_t* hmi, const char* name, const char* value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueconst char*属性值。
remote_ui 属性

remote ui 对象。 高级用户可以使用此对象直接操作远程UI。

  • 类型:remote_ui_t*
特性是否支持
可直接读取
可直接修改

http://www.niftyadmin.cn/n/5306419.html

相关文章

react 6种方式编写样式

在React中,编写样式主要有以下几种方式: 内联样式:直接在React组件中使用style属性来定义样式。这种方式比较适合定义动态的样式,因为它允许你将JavaScript表达式作为样式的值。 外部样式表:通过创建外部的CSS文件&am…

mysql5.7安装-windwos免安装版本

下载地址 官网地址:https://www.mysql.com/官网下载地址:https://dev.mysql.com/downloads/mysql/阿里云镜像站下载:https://mirrors.aliyun.com/mysql/华为云镜像站地址:https://mirrors.huaweicloud.com/home华为云镜像站下载:https://mirrors.huaweicloud.com/mysql/Downlo…

深入理解Vue3中的自定义指令

Vue3是一个流行的前端框架,它引入了许多新特性和改进,其中之一是自定义指令。自定义指令是一种强大的功能,可以让开发者在模板中直接操作 DOM 元素。本文将深入探讨 Vue3中的自定义指令,包括自定义指令的基本用法、生命周期钩子函…

新手解锁语言之力:理解 PyTorch 中 Transformer 组件

目录 torch.nn子模块transformer详解 nn.Transformer Transformer 类描述 Transformer 类的功能和作用 Transformer 类的参数 forward 方法 参数 输出 示例代码 注意事项 nn.TransformerEncoder TransformerEncoder 类描述 TransformerEncoder 类的功能和作用 Tr…

牛刀小试 - C++实现贪吃蛇

参考文档 借鉴了这位大佬的博客及代码,键入代码后发现有很多报错,依次解决后成功运行 c 实现贪吃蛇(含技术难点解析和完整代码) 技术点: C中_kbhit()函数与_getch()函数 Windows API 坐标结构 COORD 句柄 HANDLE 获…

网络调试 UDP1,开发板用静态地址-入门5

https://www.bilibili.com/video/BV1zx411d7eC?p11&vd_source109fb20ee1f39e5212cd7a443a0286c5 1, 开发板连接路由器 1.1,烧录无OS UDP例程 1.2,Mini USB连接电脑 1.3,开发板LAN接口连接路由器 2. Ping开发板与电脑之间通信* 2.1 根据…

【重点】【BFS】542.01矩阵

题目 法1&#xff1a;经典BFS 下图中就展示了我们方法&#xff1a; class Solution {public int[][] updateMatrix(int[][] mat) {int m mat.length, n mat[0].length;int[][] dist new int[m][n];boolean[][] used new boolean[m][n];Queue<int[]> queue new Li…

使用requests发请求操作Elasticsearch【二】

本文为博主原创&#xff0c;未经授权&#xff0c;严禁转载及使用。 本文链接&#xff1a;https://blog.csdn.net/zyooooxie/article/details/118367832 前面刚刚分享 使用requests发请求操作Elasticsearch【一】 &#xff0c;继续分享下。 【实际这篇博客推迟发布N个月】 个…