Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
混口饭吃,
rt-thread
提交
b39837f4
R
rt-thread
项目概览
混口饭吃,
/
rt-thread
与 Fork 源项目一致
Fork自
Mr_Pangza / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b39837f4
编写于
8月 22, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ioctl] implement function of getting window's size(TIOCGWINSZ)
上级
05098bd5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
78 addition
and
7 deletion
+78
-7
components/drivers/serial/serial.c
components/drivers/serial/serial.c
+78
-7
未找到文件。
components/drivers/serial/serial.c
浏览文件 @
b39837f4
...
...
@@ -24,7 +24,8 @@
* 2018-12-08 Ernest Chen add DMA choice
* 2020-09-14 WillianChan add a line feed to the carriage return character
* when using interrupt tx
* 2020-12-14 Meco Man add function of setting window's size(TIOCSWINSZ)
* 2020-12-14 Meco Man implement function of setting window's size(TIOCSWINSZ)
* 2021-08-22 Meco Man implement function of getting window's size(TIOCGWINSZ)
*/
#include <rthw.h>
...
...
@@ -1122,13 +1123,83 @@ static rt_err_t rt_serial_control(struct rt_device *dev,
case
TIOCGWINSZ
:
{
struct
winsize
*
p_winsize
;
p_winsize
=
(
struct
winsize
*
)
args
;
/* TODO: get windows size from console */
p_winsize
->
ws_col
=
80
;
p_winsize
->
ws_row
=
24
;
p_winsize
->
ws_xpixel
=
0
;
/*unused*/
p_winsize
->
ws_ypixel
=
0
;
/*unused*/
if
(
rt_thread_self
()
!=
rt_thread_find
(
"tshell"
))
{
/* only can be used in tshell thread; otherwise, return default size */
p_winsize
->
ws_col
=
80
;
p_winsize
->
ws_row
=
24
;
}
else
{
#define _TIO_BUFLEN 20
char
_tio_buf
[
_TIO_BUFLEN
];
unsigned
char
cnt1
,
cnt2
,
cnt3
,
i
;
char
row_s
[
4
],
col_s
[
4
];
char
*
p
;
rt_memset
(
_tio_buf
,
0
,
_TIO_BUFLEN
);
/* send the command to terminal for getting the window size of the terminal */
rt_kprintf
(
"
\033
[18t"
);
/* waiting for the response from the terminal */
i
=
0
;
while
(
i
<
_TIO_BUFLEN
)
{
_tio_buf
[
i
]
=
getchar
();
if
(
_tio_buf
[
i
]
!=
't'
)
{
i
++
;
}
else
{
break
;
}
}
if
(
i
==
_TIO_BUFLEN
)
{
/* buffer overloaded, and return default size */
p_winsize
->
ws_col
=
80
;
p_winsize
->
ws_row
=
24
;
break
;
}
/* interpreting data eg: "\033[8;1;15t" which means row is 1 and col is 15 (unit: size of ONE character) */
rt_memset
(
row_s
,
0
,
4
);
rt_memset
(
col_s
,
0
,
4
);
cnt1
=
0
;
while
(
_tio_buf
[
cnt1
]
!=
';'
&&
cnt1
<
_TIO_BUFLEN
)
{
cnt1
++
;
}
cnt2
=
++
cnt1
;
while
(
_tio_buf
[
cnt2
]
!=
';'
&&
cnt2
<
_TIO_BUFLEN
)
{
cnt2
++
;
}
p
=
row_s
;
while
(
cnt1
<
cnt2
)
{
*
p
++
=
_tio_buf
[
cnt1
++
];
}
p
=
col_s
;
cnt2
++
;
cnt3
=
rt_strlen
(
_tio_buf
)
-
1
;
while
(
cnt2
<
cnt3
)
{
*
p
++
=
_tio_buf
[
cnt2
++
];
}
/* load the window size date */
p_winsize
->
ws_col
=
atoi
(
col_s
);
p_winsize
->
ws_row
=
atoi
(
row_s
);
#undef _TIO_BUFLEN
}
p_winsize
->
ws_xpixel
=
0
;
/* unused */
p_winsize
->
ws_ypixel
=
0
;
/* unused */
}
break
;
#endif
/*RT_USING_POSIX_TERMIOS*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录