Add support for backspace and a cursor to NxConsole

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4546 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-03-31 16:26:32 +00:00
parent b277d5c193
commit 02354c2284
10 changed files with 181 additions and 1 deletions

View File

@ -2612,3 +2612,6 @@
VT100 escape sequence definitions. VT100 escape sequence definitions.
* graphics/nxconsole/nxcon_vt100.c: Add add framework to support VT100 escape * graphics/nxconsole/nxcon_vt100.c: Add add framework to support VT100 escape
sequences in NxConsole. 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. <dd>Currently, NxConsole supports only a single pixel depth.
This configuration setting must be provided to support that 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>) 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>: <dt><code>CONFIG_NXCONSOLE_NOGETRUN</code>:
<dd>NxConsole needs to know if it can read from the LCD or not. <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. 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 Currently, NxConsole supports only a single pixel depth. This
configuration setting must be provided to support that single pixel depth. configuration setting must be provided to support that single pixel depth.
Default: The smallest enabled pixel depth. (see CONFIG_NX_DISABLE_*BPP) 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 CONFIG_NXCONSOLE_NOGETRUN
NxConsole needs to know if it can read from the LCD or not. If reading 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 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; return ret;
} }
/* Hide the cursor while we update the display */
nxcon_hidecursor(priv);
/* Loop writing each character to the display */ /* Loop writing each character to the display */
for (remaining = (ssize_t)buflen; remaining > 0; remaining--) 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); while (state == VT100_ABORT);
} }
/* Show the cursor at its new position */
nxcon_showcursor(priv);
nxcon_sempost(priv); nxcon_sempost(priv);
return (ssize_t)buflen; return (ssize_t)buflen;
} }

View File

@ -41,6 +41,7 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
@ -441,6 +442,88 @@ nxcon_addchar(NXHANDLE hfont, FAR struct nxcon_state_s *priv, uint8_t ch)
return bm; 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 * Name: nxcon_home
* *

View File

@ -162,6 +162,7 @@ struct nxcon_state_s
/* Font cache data storage */ /* Font cache data storage */
struct nxcon_bitmap_s cursor;
struct nxcon_bitmap_s bm[CONFIG_NXCONSOLE_MXCHARS]; struct nxcon_bitmap_s bm[CONFIG_NXCONSOLE_MXCHARS];
/* Glyph cache data storage */ /* 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_home(FAR struct nxcon_state_s *priv);
void nxcon_newline(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 const struct nxcon_bitmap_s *nxcon_addchar(NXHANDLE hfont,
FAR struct nxcon_state_s *priv, uint8_t ch); 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, void nxcon_fillchar(FAR struct nxcon_state_s *priv,
FAR const struct nxgl_rect_s *rect, FAR const struct nxcon_bitmap_s *bm); 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 */ /* Scrolling support */
void nxcon_scroll(FAR struct nxcon_state_s *priv, int scrollheight); void nxcon_scroll(FAR struct nxcon_state_s *priv, int scrollheight);

View File

@ -39,6 +39,8 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/ascii.h>
#include "nxcon_internal.h" #include "nxcon_internal.h"
/**************************************************************************** /****************************************************************************
@ -85,6 +87,14 @@ void nxcon_putc(FAR struct nxcon_state_s *priv, uint8_t ch)
return; 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? */ /* Will another character fit on this line? */
if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w) 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); 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); nxcon_home(priv);
/* Show the cursor */
priv->cursor.code = CONFIG_NXCONSOLE_CURSORCHAR;
nxcon_showcursor(priv);
/* Register the driver */ /* Register the driver */
snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor); snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor);

View File

@ -69,6 +69,8 @@
* Currently, NxConsole supports only a single pixel depth. This * Currently, NxConsole supports only a single pixel depth. This
* configuration setting must be provided to support that single pixel depth. * configuration setting must be provided to support that single pixel depth.
* Default: The smallest enabled pixel depth. (see CONFIG_NX_DISABLE_*BPP) * 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 * CONFIG_NXCONSOLE_NOGETRUN
* NxConsole needs to know if it can read from the LCD or not. If reading * 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 * 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. * 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 */ /* The maximum number of characters that can be remembered */
#ifndef CONFIG_NXCONSOLE_MXCHARS #ifndef CONFIG_NXCONSOLE_MXCHARS

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