35
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Qiita > 要望 > コード左側に行番号を表示

Last updated at Posted at 2016-02-20

Qiitaでは以下のようにコードを記載できますが、現状ではコードの行は表示されません。

直接会うことが難しい人とチームとして作業するとき、「if (code == kCodeLF) {」については「if (code == kCodeCR) {とした方がいいのでは?」 と記載した時に相手は「どの行のこと?」と探さないといけません。

コードの左側に行がある時は「43行目のif (code == kCodeLF) {」については「if (code == kCodeCR) {とした方がいいのでは?」となり、相手も「このコードのことか」とすぐに分かります。

この理由からコードの左側に行数を表示していただくよう、ご検討をいただきたいと思います。

esp8266_160220_BYOP.ino
/*
 * This program is used for a message station shown at
 * https://hackaday.io/project/9526-bring-your-own-pizero-byop
 */


/*
 * v0.2 2016 Feb 20
 *  - fix Serial_readCommand() to handle CR code
 *  - add Serial_replyToCommand()
 * v0.1 2016 Feb 20
 *  - add Serial_readCommand()
 *  - add serial setup
 */

//-------------------------------------------------------------------------
// static declarations

static const char kCodeCR = '\r';
static const char kCodeLF = '\n';

static String s_serialReceiveBuff = "";
static bool s_serialClearOnNext = false;
//-------------------------------------------------------------------------
void setup() {
  Serial.begin(115200); 
}

String Serial_readCommand()
{
  if (Serial.available() == 0) {
    return "";  
  }

  if (s_serialClearOnNext) {
    s_serialClearOnNext = false;
    s_serialReceiveBuff = "";
  }

  char code;
  while(Serial.available() > 0) {
    code = Serial.read();
    if (code == kCodeCR) {
      continue;
    }
    if (code == kCodeLF) {
      s_serialClearOnNext = true;
      return s_serialReceiveBuff;
    } else {
      s_serialReceiveBuff += code;
    }
  }
}

void Serial_replyToCommand(String cmdline)
{
  if (cmdline.equals("hello")) {
    Serial.println("hello, 7of9");
  } else {
    Serial.println(cmdline);    
  }
}

void loop() {
  String rcvd = Serial_readCommand();
  if (rcvd.length() > 0) {
    Serial_replyToCommand(rcvd);
  }
}
35
8
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?