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

printLED の引数に文字列だけでなく数値なども送れるようにしたい #16

Open
dynamis opened this issue Aug 22, 2020 · 0 comments

Comments

@dynamis
Copy link
Contributor

dynamis commented Aug 22, 2020

現在の microBitBle.printLED() は以下のコード実装で引数が文字列型でなければ ptext.subscribe is no a function エラーで停止する。初学者は数字を表示するときに数値型データを入力しがちであるがこの原因を特定して修正するのは困難なので、数値型の場合 (または任意の toString() メソッドを持つオブジェクト) も受け側で型変換して動くようにしたい。

https://github.com/chirimen-oh/chirimen-micro-bit/blob/master/polyfill/microBitBLE.js#L289-L291

      async function printLED(ptext) {
        return await printLedInt(mbBleUart, ptext);
      }

https://github.com/chirimen-oh/chirimen-micro-bit/blob/master/polyfill/microBitBLE.js#L1096-L1111

    async function printLedInt(mbBleUart, ptext) {
      // MAX strLen:19 (sendVal: L012345678901234567) リミッターを設けた(2019/8/30)
      ptext = ptext.substring(0, 18);
      if (debugLog) {
        console.log("printLED:", ptext);
      }
      var ret = await mbBleUart.sendCmd2MicroBit("L" + ptext);
      if (ret == null) {
        console.error("mbBLE com error...");
        return;
      }
      if (debugLog) {
        console.log("printLED:", ret);
      }
      return ret;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant