0

First, some background. I have acquired a few of these Avago HCMS-29xx LED displays. there is an Arduino library for controlling them, but I want to use a raspberry pi. So I have forked the original library's GitHub and started porting.

The library port is mostly working with the basic print example, but the way I pass strings to the library is hacked together at best. So I did some searching and found an example showing how to use the Stream class as a base for my library class and use printf() to print a charactor to my display.

Here is the example:

//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;
    } 

and my code:

#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

But when I try to compile, it gives an error

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());
             ^~~~~~

What am I doing wrong? is this even a sane way to use the standard printf() function?

u6bkep
  • 1
  • 1
    I can't make sense of this. Arduino's `Stream` class has no `printf()` method defined. Have you read the [Arduino documentation on how to use printf()](https://playground.arduino.cc/main/printf)? – Steve Sep 07 '18 at 04:38
  • 1
    I realize that the page you linked to says it should work, but I think that's not the entire recipe. – Steve Sep 07 '18 at 04:39
  • @Steve The code I am writing is for raspberry pi (linux), not Arduino. The code I am porting this library from was Arduino. Though I think you have a good point in your second comment, I am beginning to suspect the example I am basing this all off is for AVR. – u6bkep Sep 07 '18 at 19:30

0 Answers0