Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate and implement a fix for echod serial characters #43

Open
PropGit opened this issue Sep 8, 2016 · 1 comment
Open

Evaluate and implement a fix for echod serial characters #43

PropGit opened this issue Sep 8, 2016 · 1 comment
Labels

Comments

@PropGit
Copy link
Contributor

PropGit commented Sep 8, 2016

Regarding echoed characters as indicated by BlocklyProp's Issue #690, (Look for posts describing "An underlying function inside of getStr() is generating an echo"), we need to evaluate and fix this in Simple Libraries.

@PropGit PropGit added the bug label Sep 8, 2016
@MatzElectronics
Copy link
Contributor

I have some candidate code for this, but since I'm here, there is an opportunity to address #41 and possibly #42 here as well (which I have not done in the code below)

safe_gets.c:

/*
 * Small modifications for using text_t interface by Steve Denson.
 * Super-simple text I/O for PropGCC, stripped of all stdio overhead.
 * Copyright (c) 2012, Ted Stefanik. Concept inspired by:
 *
 *     very simple printf, adapted from one written by me [Eric Smith]
 *     for the MiNT OS long ago
 *     placed in the public domain
 *       - Eric Smith
 *     Propeller specific adaptations
 *     Copyright (c) 2011 Parallax, Inc.
 *     Written by Eric R. Smith, Total Spectrum Software Inc.
 *
 * MIT licensed (see terms at end of file)
 */
#include <ctype.h>
#include "simpletext.h"

static volatile char _textScanTerminalCharEchoing = 1;


void scanEchoDisable()
{
  _textScanTerminalCharEchoing = 0;
}  

void scanEchoEnable()
{
  _textScanTerminalCharEchoing = 1;
}  

char* _safe_gets(text_t *text, char* origBuf, int count)
{
  char* buf = origBuf;
  while (count-- > 0)
  {
      int ch = text->rxChar(text);

      if (ch == 8 || ch == 127)
      {
          if (buf > origBuf)
          {
              if(_textScanTerminalCharEchoing)
              {
                text->txChar(text, '\010');
                text->txChar(text, ' ');
                text->txChar(text, '\010');
              }                
              count += 1;
              buf--;
          }
          count += 1;
          continue;
      }

      if(_textScanTerminalCharEchoing)
      {
        text->txChar(text, ch);
        if (ch == '\r')
            text->txChar(text, '\n');
      }            

      if (ch == '\r' || ch == '\n')
          break;

      *(buf++) = ch;
  }
  *buf = 0;

  return (origBuf);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants