diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-31 16:26:32 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-31 16:26:32 +0000 |
commit | 383bcc132afd8bac784c76af40002cfa38029581 (patch) | |
tree | 5c550181d08f76408da5d71e784b9cdfa8c1c8ae /nuttx/graphics/nxconsole | |
parent | 421258dad4dee7bc7fadd7619749b1bda370c773 (diff) | |
download | px4-nuttx-383bcc132afd8bac784c76af40002cfa38029581.tar.gz px4-nuttx-383bcc132afd8bac784c76af40002cfa38029581.tar.bz2 px4-nuttx-383bcc132afd8bac784c76af40002cfa38029581.zip |
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
Diffstat (limited to 'nuttx/graphics/nxconsole')
-rwxr-xr-x | nuttx/graphics/nxconsole/nxcon_driver.c | 7 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_font.c | 83 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_internal.h | 9 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_putc.c | 63 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_register.c | 5 |
5 files changed, 166 insertions, 1 deletions
diff --git a/nuttx/graphics/nxconsole/nxcon_driver.c b/nuttx/graphics/nxconsole/nxcon_driver.c index 646485146..f246070a5 100755 --- a/nuttx/graphics/nxconsole/nxcon_driver.c +++ b/nuttx/graphics/nxconsole/nxcon_driver.c @@ -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; } diff --git a/nuttx/graphics/nxconsole/nxcon_font.c b/nuttx/graphics/nxconsole/nxcon_font.c index 2677b9c15..2bdf21cf6 100644 --- a/nuttx/graphics/nxconsole/nxcon_font.c +++ b/nuttx/graphics/nxconsole/nxcon_font.c @@ -41,6 +41,7 @@ #include <string.h> #include <assert.h> +#include <errno.h> #include <debug.h> #include <nuttx/kmalloc.h> @@ -442,6 +443,88 @@ nxcon_addchar(NXHANDLE hfont, FAR struct nxcon_state_s *priv, uint8_t ch) } /**************************************************************************** + * 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 * * Description: diff --git a/nuttx/graphics/nxconsole/nxcon_internal.h b/nuttx/graphics/nxconsole/nxcon_internal.h index ebcab909b..10341f0cf 100644 --- a/nuttx/graphics/nxconsole/nxcon_internal.h +++ b/nuttx/graphics/nxconsole/nxcon_internal.h @@ -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); diff --git a/nuttx/graphics/nxconsole/nxcon_putc.c b/nuttx/graphics/nxconsole/nxcon_putc.c index 97e3314a6..d51d79c79 100644 --- a/nuttx/graphics/nxconsole/nxcon_putc.c +++ b/nuttx/graphics/nxconsole/nxcon_putc.c @@ -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); +} diff --git a/nuttx/graphics/nxconsole/nxcon_register.c b/nuttx/graphics/nxconsole/nxcon_register.c index 663764dce..bb041ca7b 100644 --- a/nuttx/graphics/nxconsole/nxcon_register.c +++ b/nuttx/graphics/nxconsole/nxcon_register.c @@ -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); |