0

まず、いくつかの背景。これらのAvago HCMS-29xx LED ディスプレイをいくつか入手しました。それらを制御するためのArduinoライブラリがありますが、ラズベリーパイを使いたいです。そこで、元のライブラリの GitHub をフォークして移植を開始しました。

ライブラリ ポートは基本的な印刷の例でほとんど動作しますが、ライブラリに文字列を渡す方法はせいぜい一緒にハッキングされています。そのため、検索を行ったところ、Stream クラスをライブラリ クラスのベースとして使用し、printf() を使用して文字をディスプレイに出力する方法を示す例を見つけました。

次に例を示します。

//New class setup to drive a display
class NEWLCDCLASS : public Stream //use Stream base class
{
……
// lots of code for the new LCD class - not shown here to keep it simple
.....
//and add this to the end of the class
protected
    //used by printf - supply a new _putc virtual function for the new device
    virtual int _putc(int c) {
        myLCDputc(c); //your new LCD put to print an ASCII character on LCD
        return 0;
    };
//assuming no reads from LCD
    virtual int _getc() {
        return -1;
    } 

と私のコード:

#ifndef LedDisplay_h
#define LedDisplay_h
#include <cstring>
#include <cstdint>
#include <cstdio>

namespace LedDisplay
{

    class LedDisplay : public Stream
    {

    //lots of code to drive the display
    .....


      protected:
        //used by printf - supply a new _putc virtual function for the new device
        virtual int _putc(int c) {
            write(c); //your new LCD put to print an ASCII character on LCD
            return 0;
        };
    //assuming no reads from LCD
        virtual int _getc() {
            return -1;
        }



    };
}
#endif

しかし、コンパイルしようとすると、エラーが発生します

In file included from print.cpp:1:0:
LedDisplayPi.h:20:1: error: expected class-name before ‘{’ token
 {
 ^
print.cpp: In function ‘int main()’:
print.cpp:38:13: error: ‘class LedDisplayNs::LedDisplay’ has no member named ‘printf’; did you mean ‘write’?
   myDisplay.printf("%s",helloWorldstring.c_str());
             ^~~~~~

私は何を間違っていますか?これは、標準の printf() 関数を使用する正気な方法ですか?

4

0 に答える 0