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
基本用法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表示成功,否则表示失败。
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*特性
是否支持
可直接读取
是
可直接修改
否
剩余电流监测仪在施工场地的应用
大联大携手展讯打造新一代2.5G手机平台解决方案
集成数字下变频器功能的高速ADC的奇怪行为
采样保持输出噪声有两个关键分量!
人工智能指出有天体撞地球?
AWTK 串口屏开发(5) - MCU端 SDK 用法
天马支持真我10 Pro+全球首发 2160Hz超高频PWM调光联合定制
如何选择合适的PCB原理图设计软件
直流调速器维修常见检测方法
SDRAM的布线规则 基于Allegro嵌入式高速电路布线设计
基于FPGA的DDC的设计
net程序员工作两年的总结
人工智能具备哪一些识别功能
CKS32F4xx系列低功耗模式之STANDBY模式
镍铁合金薄壁零件车削加工研究
PicScope高级函数功能应用—编辑函数公式测量相位漂移
芯片巨头高层动荡:ARM任命新CEO挑战英特尔
捷扬微电子发布超宽带系统级芯片GT1000
2014年全球移动互联网收入将超过固定宽带
辐射状分齿蝶形天线的研究设计