Pages: [1]   Go Down
Author Topic: SoftwareSerial child class to drive a netmedia serial lcd  (Read 758 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
    I've got this serial lcd:

http://www.robot-italy.com/it/netmedia-serial-lcd-display-2x16-blue.html

And this is a SoftwareSerial child class that implements some of LiquidCrystal methods using the netmedia commands.

It's not finished yet, but I hope it can be useful.

Code:
class NetmediaSerialLCD : public SoftwareSerial {
public:
    NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(rxPin, txPin) {
    };
   
    void setBacklight(uint8_t brightnessLevel) {
        this->write(20);
        this->write(brightnessLevel);
    };
   
    void clear() {
        this->write(12);
    };
   
    void setCursor(uint8_t column, uint8_t row) {
        this->write(17);
        this->write(row);
        this->write(column);
    };
   
    void createChar(uint8_t location, uint8_t* charmap) {
        this->write(18);
       
        location &= 0x7; // we only have 8 locations 0-7
        location = 64 + (location << 3);
        this->write(location);
        for (uint8_t i = 0; i < 7; i++) {
            this->write(charmap[i]);
        }
    };
};
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13846
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


A serial LCD should only use a TX pin and no RX pin

Does this constructor work?
Code:
NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(-1, txPin) {
    };
if so you saved an IO pin ...
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50111
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
        this->write(17);
        this->write(row);
        this->write(column);
In the absence of a specific instance, this is implied. Why do you feel the need to explicitly use this->?

I'm not saying it's wrong. I'm asking why. The only time I use this-> is when a class field has the same name as a local variable (typically a method argument).
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


A serial LCD should only use a TX pin and no RX pin

Does this constructor work?
Code:
NetmediaSerialLCD(uint8_t rxPin, uint8_t txPin) : SoftwareSerial(-1, txPin) {
    };
if so you saved an IO pin ...

I have looked at SoftwareSerial source, and didn't see any test to skip pin initialization in case it has a "special" value. I've put in my todo list the task of looking closer to SS code and see if I can patch it to _actually_ save a pin.
Another solution could be to shamelessly copy the tx code from SoftwareSerial and put it into a new "tx-only" SoftwareSerial class.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
        this->write(17);
        this->write(row);
        this->write(column);
In the absence of a specific instance, this is implied. Why do you feel the need to explicitly use this->?

I'm not saying it's wrong. I'm asking why. The only time I use this-> is when a class field has the same name as a local variable (typically a method argument).

It just looked clearer to me when I wrote it. Since it's implied, it becomes just a matter of taste IMHO.
Logged

Pages: [1]   Go Up
Jump to: