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?