Part 1
요약·해설
ANSI C porting model, UART 요구 사항, QEMU run·exit와 control character 시험을 설명합니다.
console_getchar
Character
QEMU x86
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
A81FB74E5C9A6ED48AE7F8534E02545FC91B6CD0EC1D6BAF3E630EB2657C6229
.. zephyr:code-sample:: console_getchar
:name: console_getchar()
Use console_getchar() to read an input character from the console.
Overview
********
This example shows how to use :c:func:`console_getchar` function.
Similar to the well-known ANSI C getchar() function,
:c:func:`console_getchar` either returns the next available input
character or blocks waiting for one. Using this function, it should be
fairly easy to port existing ANSI C, POSIX, or Linux applications which
process console input character by character. The sample also allows to
see key/character codes as returned by the function.
If you are interested in line by line console input, see
:zephyr:code-sample:`console_getline`.
Requirements
************
UART console is required to run this sample.
Building and Running
********************
The easiest way to run this sample is using QEMU:
.. zephyr-app-commands::
:zephyr-app: samples/subsys/console/getchar
:host-os: unix
:board: qemu_x86
:goals: run
:compact:
Now start pressing keys on a keyboard, and they will be printed both as
hex values and in character form. Be sure to press Enter, Up/Down, etc.
key to check what control characters are produced for them.
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
Part 3
한국어 전문 번역
개요
console_getchar() function으로 console input character 하나를 읽는 example입니다.
널리 알려진 ANSI C getchar()와 비슷하게, console_getchar()는 다음 input character가 있으면 반환하고 없으면 character가 들어올 때까지 block합니다. Console input을 character 단위로 처리하는 기존 ANSI C, POSIX 또는 Linux application을 port할 때 이 동작을 그대로 활용할 수 있습니다.
Sample은 function이 반환한 key·character code를 보여 줍니다. Line 단위 input이 필요하면 console_getline() sample을 사용합니다.
요구 사항
UART console이 필요합니다.
빌드 및 실행
가장 쉬운 실행 방법은 QEMU입니다. qemu_x86로 build한 뒤 run target을 실행합니다.
west build -b qemu_x86 samples/subsys/console/getchar
west build -t run
Keyboard key를 누르면 hex value와 character form이 함께 표시됩니다. Enter와 Up·Down key도 눌러 LF·escape sequence 같은 control character가 어떤 code로 들어오는지 확인하십시오. QEMU는 CTRL+A를 누른 뒤 x를 눌러 종료합니다.
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.