mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
Changing Print class to use regular virtual write() function (instead of my hack
ed together version).
This commit is contained in:
parent
ac06b319b0
commit
8f75f0299d
@ -26,14 +26,6 @@
|
|||||||
|
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
|
|
||||||
void HardwareSerialWrite(uint8_t value, void *instance) {
|
|
||||||
((HardwareSerial *) instance)->write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructors ////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
HardwareSerial::HardwareSerial() : Print(HardwareSerialWrite) {}
|
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void HardwareSerial::begin(long speed)
|
void HardwareSerial::begin(long speed)
|
||||||
|
@ -27,12 +27,11 @@
|
|||||||
class HardwareSerial : public Print
|
class HardwareSerial : public Print
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HardwareSerial();
|
|
||||||
void begin(long);
|
void begin(long);
|
||||||
uint8_t available(void);
|
uint8_t available(void);
|
||||||
int read(void);
|
int read(void);
|
||||||
void flush(void);
|
void flush(void);
|
||||||
void write(uint8_t);
|
virtual void write(uint8_t);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern HardwareSerial Serial;
|
extern HardwareSerial Serial;
|
||||||
|
@ -26,17 +26,11 @@
|
|||||||
|
|
||||||
#include "Print.h"
|
#include "Print.h"
|
||||||
|
|
||||||
// Constructors ////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Print::Print(void (*write)(uint8_t, void *)) {
|
|
||||||
this->write = write;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Public Methods //////////////////////////////////////////////////////////////
|
// Public Methods //////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Print::print(uint8_t b)
|
void Print::print(uint8_t b)
|
||||||
{
|
{
|
||||||
write(b, this);
|
write(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Print::print(char c)
|
void Print::print(char c)
|
||||||
|
@ -32,9 +32,8 @@ class Print
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
void printNumber(unsigned long, uint8_t);
|
void printNumber(unsigned long, uint8_t);
|
||||||
void (*write)(uint8_t, void *);
|
|
||||||
public:
|
public:
|
||||||
Print(void (*)(uint8_t, void *));
|
virtual void write(uint8_t);
|
||||||
void print(char);
|
void print(char);
|
||||||
void print(const char[]);
|
void print(const char[]);
|
||||||
void print(uint8_t);
|
void print(uint8_t);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
|
||||||
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) : Print(baseWrite),
|
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) :
|
||||||
_four_bit_mode(0), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
|
_four_bit_mode(0), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
|
||||||
{
|
{
|
||||||
_data_pins[0] = d0;
|
_data_pins[0] = d0;
|
||||||
@ -52,7 +52,7 @@ LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
|
||||||
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) : Print(baseWrite),
|
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :
|
||||||
_four_bit_mode(1), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
|
_four_bit_mode(1), _rs_pin(rs), _rw_pin(rw), _enable_pin(enable)
|
||||||
{
|
{
|
||||||
_data_pins[0] = d0;
|
_data_pins[0] = d0;
|
||||||
@ -91,11 +91,15 @@ void LiquidCrystal::setCursor(int col, int row)
|
|||||||
command(0x80 | (col + row_offsets[row]));
|
command(0x80 | (col + row_offsets[row]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiquidCrystal::command(int value) {
|
void LiquidCrystal::command(uint8_t value) {
|
||||||
write(value, LOW);
|
send(value, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LiquidCrystal::write(int value, int mode) {
|
void LiquidCrystal::write(uint8_t value) {
|
||||||
|
send(value, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LiquidCrystal::send(uint8_t value, uint8_t mode) {
|
||||||
digitalWrite(_rs_pin, mode);
|
digitalWrite(_rs_pin, mode);
|
||||||
digitalWrite(_rw_pin, LOW);
|
digitalWrite(_rw_pin, LOW);
|
||||||
|
|
||||||
@ -122,7 +126,3 @@ void LiquidCrystal::write(int value, int mode) {
|
|||||||
digitalWrite(_enable_pin, LOW);
|
digitalWrite(_enable_pin, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void baseWrite(uint8_t value, void *instance) {
|
|
||||||
((LiquidCrystal *) instance)->write(value);
|
|
||||||
}
|
|
||||||
|
@ -16,9 +16,11 @@ public:
|
|||||||
void shiftDisplayLeft();
|
void shiftDisplayLeft();
|
||||||
void shiftDisplayRight();
|
void shiftDisplayRight();
|
||||||
*/
|
*/
|
||||||
void write(int, int = 1);
|
virtual void write(uint8_t);
|
||||||
void command(int);
|
void command(uint8_t);
|
||||||
private:
|
private:
|
||||||
|
void send(uint8_t, uint8_t);
|
||||||
|
|
||||||
uint8_t _four_bit_mode;
|
uint8_t _four_bit_mode;
|
||||||
uint8_t _rs_pin; // LOW: command. HIGH: character.
|
uint8_t _rs_pin; // LOW: command. HIGH: character.
|
||||||
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
|
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
|
||||||
@ -26,6 +28,4 @@ private:
|
|||||||
uint8_t _data_pins[8];
|
uint8_t _data_pins[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
void baseWrite(uint8_t, void *);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user