加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入
  • 正文
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

产品应用 | AWTK 串口屏开发(5) - MCU端 SDK 用法

01/07 09:25
2157
阅读需 18 分钟
加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论

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

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

普通嵌入式系统

mcu/stm32h743/USER/main.c

低端嵌入式系统

mcu/mini-sdk/hmi/examples/socket/main.c

MCU 模拟器

simulator/src/pages/home_page.c

基本用法

1. 创建 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=%dn", temp);  }
  return RET_OK;}
...  io = tk_stream_factory_create_iostream(url);  hmi = hmi_create(io, hmi_on_prop_change, NULL);

2. 设置属性

示例:

 hmi_set_prop_int(hmi, "温度", 36);

3. 获取属性示例:

 int32_t temp = hmi_get_prop_int(hmi, "温度", 0);

4. 在主循环中分发事件

示例:

 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 使用)。

1. 函数

函数名称 说明
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 设置字符串属性。

2. 属性

属性名称 类型 说明
remote_ui remote_ui_t* emote ui 对象。

2.1 hmi_create 函数

    函数功能:

创建hmi对象。

函数原型:

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

2.2 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对象。
device const char* 串口设备。
on_prop_changed hmi_on_prop_changed_t 属性变化回调函数。
ctx void* 上下文。

2.3 hmi_destroy 函数

函数功能:

销毁hmi对象。

函数原型:

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

2.4 hmi_dispatch 函数

函数功能:

处理事件。。

函数原型:

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

2.5 hmi_get_prop 函数

函数功能:

获取属性。

函数原型:

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

2.6 hmi_get_prop_bool 函数

函数功能:

获取布尔属性。

函数原型:

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

2.7 hmi_get_prop_float 函数

函数功能:

获取浮点数属性。

函数原型:

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

2.8 hmi_get_prop_int 函数

函数功能:

获取整数属性。

函数原型:

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

2.9 hmi_get_prop_int64 函数

函数功能:

获取64位整数属性。

函数原型:

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

2.10 hmi_get_prop_str 函数

函数功能:

获取字符串属性。

函数原型:

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

2.11 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表示成功,否则表示失败。
hmi hmi_t* hmi对象。
target const char* 目标对象。
name const char* 属性名称。
v const value_t* 属性值。

2.12 hmi_set_prop_bool 函数

函数功能:

设置布尔属性。

函数原型:

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

2.13 hmi_set_prop_float 函数

函数功能:

设置浮点数属性。

函数原型:

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

2.14 hmi_set_prop_int 函数

函数功能:

设置整数属性。

函数原型:

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

2.15 hmi_set_prop_int64 函数

函数功能:

设置64位整数属性。

函数原型:

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

2.16 hmi_set_prop_str 函数

函数功能:

设置字符串属性。

函数原型:

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

2.17 remote_ui 属性

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

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

推荐器件

更多器件
器件型号 数量 器件厂商 器件描述 数据手册 ECAD模型 风险等级 参考价格 更多信息
TJA1055T/1J 1 NXP Semiconductors TJA1055 - Enhanced fault-tolerant CAN transceiver SOIC 14-Pin
$1.72 查看
AD9361BBCZ-REEL 1 Analog Devices Inc RF Agile Transceiver

ECAD模型

下载ECAD模型
暂无数据 查看
KSZ9477STXI-TR 1 Microchip Technology Inc IC ETHERNET SWITCH 7PORT 128TQFP

ECAD模型

下载ECAD模型
$17.3 查看
致远电子

致远电子

广州致远电子股份有限公司成立于2001年,注册资金5000万元,国家级高新技术认证企业,广州市高端工控测量仪器工程技术研究开发中心,Intel ECA全球合作伙伴和微软嵌入式系统金牌合作伙伴。

广州致远电子股份有限公司成立于2001年,注册资金5000万元,国家级高新技术认证企业,广州市高端工控测量仪器工程技术研究开发中心,Intel ECA全球合作伙伴和微软嵌入式系统金牌合作伙伴。收起

查看更多

相关推荐

电子产业图谱