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

描述

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

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

普通嵌入式系统

mcu/stm32h743/USER/main.c

低端嵌入式系统

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

MCU 模拟器

simulator/src/pages/home_page.c

awtk

基本用法

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=%d\n", 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表示成功,否则表示失败。
hmihmi_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返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvaluebool_t默认值。

2.7 hmi_get_prop_float 函数

函数功能:

获取浮点数属性。

函数原型:

  •  

float hmi_get_prop_float (hmi_t* hmi, const char* name, float defvalue);

  • 参数说明:
参数类型说明
返回值float返回属性值。
hmihmi_t*hmi对象。
nameconst char*属性名称。
defvaluefloat默认值。

2.8 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默认值。

2.9 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默认值。

2.10 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*默认值。

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表示成功,否则表示失败。
hmihmi_t*hmi对象。
targetconst char*目标对象。
name
 
const char*属性名称。
vconst 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表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valuebool_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表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valuefloat默认值。

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表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueint32_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表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueint64_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表示成功,否则表示失败。
hmihmi_t*hmi对象。
nameconst char*属性名称。
valueconst char*默认值。

2.17 remote_ui 属性

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

  • 类型:remote_ui_t*

特性

是否支持

可直接读取

可直接修改

 

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分