Add support for backspace and a cursor to NxConsole

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4546 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-03-31 16:26:32 +00:00
parent 3b74716862
commit a540f4727a
10 changed files with 181 additions and 1 deletions

View File

@ -2612,3 +2612,6 @@
VT100 escape sequence definitions.
* graphics/nxconsole/nxcon_vt100.c: Add add framework to support VT100 escape
sequences in NxConsole.
* fs/fs_read.c: Fix read() return value for attempt to read from write-only
file or device. Was returning EBADF, should return EACCES.
* graphics/nxconsole.c: NxConsole now supports backspace and a cursor.

View File

@ -3360,6 +3360,8 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
<dd>Currently, NxConsole supports only a single pixel depth.
This configuration setting must be provided to support that single pixel depth.
Default: The smallest enabled pixel depth. (see <code>CONFIG_NX_DISABLE_*BPP</code>)
<dt><code>CONFIG_NXCONSOLE_CURSORCHAR</code>:
<dd>The bitmap code to use as the cursor. Default '_'
<dt><code>CONFIG_NXCONSOLE_NOGETRUN</code>:
<dd>NxConsole needs to know if it can read from the LCD or not.
If reading from the LCD is supported, then NxConsole can do more efficient scrolling.

View File

@ -328,6 +328,8 @@ CONFIG_NXCONSOLE_BPP
Currently, NxConsole supports only a single pixel depth. This
configuration setting must be provided to support that single pixel depth.
Default: The smallest enabled pixel depth. (see CONFIG_NX_DISABLE_*BPP)
CONFIG_NXCONSOLE_CURSORCHAR
The bitmap code to use as the cursor. Default '_'
CONFIG_NXCONSOLE_NOGETRUN
NxConsole needs to know if it can read from the LCD or not. If reading
from the LCD is supported, then NxConsole can do more efficient

View File

@ -142,6 +142,10 @@ static ssize_t nxcon_write(FAR struct file *filep, FAR const char *buffer,
return ret;
}
/* Hide the cursor while we update the display */
nxcon_hidecursor(priv);
/* Loop writing each character to the display */
for (remaining = (ssize_t)buflen; remaining > 0; remaining--)
@ -217,6 +221,9 @@ static ssize_t nxcon_write(FAR struct file *filep, FAR const char *buffer,
while (state == VT100_ABORT);
}
/* Show the cursor at its new position */
nxcon_showcursor(priv);
nxcon_sempost(priv);
return (ssize_t)buflen;
}

View File

@ -41,6 +41,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
@ -441,6 +442,88 @@ nxcon_addchar(NXHANDLE hfont, FAR struct nxcon_state_s *priv, uint8_t ch)
return bm;
}
/****************************************************************************
* Name: nxcon_hidechar
*
* Description:
* Erase a character from the window.
*
****************************************************************************/
int nxcon_hidechar(FAR struct nxcon_state_s *priv,
FAR const struct nxcon_bitmap_s *bm)
{
struct nxgl_rect_s bounds;
struct nxgl_size_s fsize;
int ret;
/* Get the size of the font glyph. If nxcon_fontsize, then the
* character will have been rendered as a space, and no display
* modification is required (not an error).
*/
ret = nxcon_fontsize(priv->font, bm->code, &fsize);
if (ret < 0)
{
/* It was rendered as a space. */
return OK;
}
/* Construct a bounding box for the glyph */
bounds.pt1.x = bm->pos.x;
bounds.pt1.y = bm->pos.y;
bounds.pt2.x = bm->pos.x + fsize.w - 1;
bounds.pt2.y = bm->pos.y + fsize.h - 1;
/* Fill the bitmap region with the background color, erasing the
* character from the display. NOTE: This region might actually
* be obscured... NX will handle that case.
*/
return priv->ops->fill(priv, &bounds, priv->wndo.wcolor);
}
/****************************************************************************
* Name: nxcon_backspace
*
* Description:
* Remove the last character from the window.
*
****************************************************************************/
int nxcon_backspace(FAR struct nxcon_state_s *priv)
{
FAR struct nxcon_bitmap_s *bm;
int ndx;
int ret = -ENOENT;
/* Is there a character on the display? */
if (priv->nchars > 0)
{
/* Yes.. Get the index to the last bitmap on the display */
ndx = priv->nchars - 1;
bm = &priv->bm[ndx];
/* Erase the character from the display */
ret = nxcon_hidechar(priv, bm);
/* The current position to the location where the last character was */
priv->fpos.x = bm->pos.x;
priv->fpos.y = bm->pos.y;
/* Decrement nchars to discard this character */
priv->nchars = ndx;
}
return ret;
}
/****************************************************************************
* Name: nxcon_home
*

View File

@ -162,6 +162,7 @@ struct nxcon_state_s
/* Font cache data storage */
struct nxcon_bitmap_s cursor;
struct nxcon_bitmap_s bm[CONFIG_NXCONSOLE_MXCHARS];
/* Glyph cache data storage */
@ -204,12 +205,18 @@ enum nxcon_vt100state_e nxcon_vt100(FAR struct nxcon_state_s *priv, char ch);
void nxcon_home(FAR struct nxcon_state_s *priv);
void nxcon_newline(FAR struct nxcon_state_s *priv);
void nxcon_putc(FAR struct nxcon_state_s *priv, uint8_t ch);
FAR const struct nxcon_bitmap_s *nxcon_addchar(NXHANDLE hfont,
FAR struct nxcon_state_s *priv, uint8_t ch);
int nxcon_hidechar(FAR struct nxcon_state_s *priv,
FAR const struct nxcon_bitmap_s *bm);
int nxcon_backspace(FAR struct nxcon_state_s *priv);
void nxcon_fillchar(FAR struct nxcon_state_s *priv,
FAR const struct nxgl_rect_s *rect, FAR const struct nxcon_bitmap_s *bm);
void nxcon_putc(FAR struct nxcon_state_s *priv, uint8_t ch);
void nxcon_showcursor(FAR struct nxcon_state_s *priv);
void nxcon_hidecursor(FAR struct nxcon_state_s *priv);
/* Scrolling support */
void nxcon_scroll(FAR struct nxcon_state_s *priv, int scrollheight);

View File

@ -39,6 +39,8 @@
#include <nuttx/config.h>
#include <nuttx/ascii.h>
#include "nxcon_internal.h"
/****************************************************************************
@ -85,6 +87,14 @@ void nxcon_putc(FAR struct nxcon_state_s *priv, uint8_t ch)
return;
}
/* Handle backspace (treating both BS and DEL as backspace) */
if (ch == ASCII_BS || ch == ASCII_DEL)
{
nxcon_backspace(priv);
return;
}
/* Will another character fit on this line? */
if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w)
@ -138,3 +148,56 @@ void nxcon_putc(FAR struct nxcon_state_s *priv, uint8_t ch)
nxcon_fillchar(priv, NULL, bm);
}
}
/****************************************************************************
* Name: nxcon_showcursor
*
* Description:
* Render the cursor character at the current display position.
*
****************************************************************************/
void nxcon_showcursor(FAR struct nxcon_state_s *priv)
{
int lineheight;
/* Will another character fit on this line? */
if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w)
{
#ifndef CONFIG_NXCONSOLE_NOWRAP
/* No.. move to the next line */
nxcon_newline(priv);
#else
return;
#endif
}
/* Check if we need to scroll up */
lineheight = (priv->fheight + CONFIG_NXCONSOLE_LINESEPARATION);
while (priv->fpos.y >= priv->wndo.wsize.h - lineheight)
{
nxcon_scroll(priv, lineheight);
}
/* Render the cursor glyph onto the display. */
priv->cursor.pos.x = priv->fpos.x;
priv->cursor.pos.y = priv->fpos.y;
nxcon_fillchar(priv, NULL, &priv->cursor);
}
/****************************************************************************
* Name: nxcon_hidecursor
*
* Description:
* Render the cursor cursor character from the display.
*
****************************************************************************/
void nxcon_hidecursor(FAR struct nxcon_state_s *priv)
{
(void)nxcon_hidechar(priv, &priv->cursor);
}

View File

@ -132,6 +132,11 @@ FAR struct nxcon_state_s *
nxcon_home(priv);
/* Show the cursor */
priv->cursor.code = CONFIG_NXCONSOLE_CURSORCHAR;
nxcon_showcursor(priv);
/* Register the driver */
snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor);

View File

@ -69,6 +69,8 @@
* Currently, NxConsole supports only a single pixel depth. This
* configuration setting must be provided to support that single pixel depth.
* Default: The smallest enabled pixel depth. (see CONFIG_NX_DISABLE_*BPP)
* CONFIG_NXCONSOLE_CURSORCHAR
* The bitmap code to use as the cursor. Default '_'
* CONFIG_NXCONSOLE_NOGETRUN
* NxConsole needs to know if it can read from the LCD or not. If reading
* from the LCD is supported, then NxConsole can do more efficient
@ -95,6 +97,12 @@
* that the text is simply truncated until a new line is encountered.
*/
/* Cursor character */
#ifndef CONFIG_NXCONSOLE_CURSORCHAR
# define CONFIG_NXCONSOLE_CURSORCHAR '_'
#endif
/* The maximum number of characters that can be remembered */
#ifndef CONFIG_NXCONSOLE_MXCHARS

0
include/nuttx/vt100.h Executable file → Normal file
View File