summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Reimer <manuel.reimer@gmx.de>2018-02-24 11:27:39 +0100
committerManuel Reimer <manuel.reimer@gmx.de>2018-02-24 11:29:13 +0100
commitc1d6e1a19fabef4ae8fcd1306c0e18492b2dea02 (patch)
treeb1e99cf8f758ded48fd91aa425920e426bf9531f
parent6a814f713485e55e7374e9bd66a29af882c40ce0 (diff)
downloadgraphlcd-base-c1d6e1a19fabef4ae8fcd1306c0e18492b2dea02.tar.gz
graphlcd-base-c1d6e1a19fabef4ae8fcd1306c0e18492b2dea02.tar.bz2
usbserlcd: Move serial stream creation to buffer class
-rw-r--r--glcddrivers/usbserlcd.c77
-rw-r--r--glcddrivers/usbserlcd.h12
-rw-r--r--graphlcd.conf1
3 files changed, 53 insertions, 37 deletions
diff --git a/glcddrivers/usbserlcd.c b/glcddrivers/usbserlcd.c
index 44efb31..ab4e710 100644
--- a/glcddrivers/usbserlcd.c
+++ b/glcddrivers/usbserlcd.c
@@ -174,7 +174,6 @@ void cDriverUSBserLCD::Refresh(bool refreshAll)
{
int x,y;
uint16_t addr = 0;
- uint16_t len = 0;
if (CheckSetup() == 1)
refreshAll = true;
@@ -187,12 +186,9 @@ void cDriverUSBserLCD::Refresh(bool refreshAll)
}
// draw all
- std::string full_seq = "GLCD";
- full_seq.reserve(8500);
- full_seq += PKGTYPE_DATA; // Have to do it this way to get the NULL added
- full_seq.append((char*)&addr, 2);
-
+ cDriverUSBserLCDBuffer full_seq(8500);
std::string bytes = "";
+ bytes.reserve(8500);
for (y = 0; y < height; y++)
{
for (x = 0; x < (width + (FS - 1)) / FS; x++)
@@ -203,23 +199,17 @@ void cDriverUSBserLCD::Refresh(bool refreshAll)
oldLCD[x][y] = newLCD[x][y];
}
}
- len = bytes.length();
- full_seq.append((char*)&len, 2);
- full_seq.append(bytes);
- // and reset RefreshCounter
- refreshCounter = 0;
+ full_seq.Append(bytes, 0);
if (refreshAll) {
- port->WriteData(full_seq);
+ port->WriteData(full_seq.GetString());
+ // and reset RefreshCounter
+ refreshCounter = 0;
return;
}
// draw only the changed bytes
- std::string part_seq = "";
- part_seq.reserve(8500);
- std::string block_seq = "GLCD";
- block_seq.reserve(8500);
- block_seq += PKGTYPE_DATA;
+ cDriverUSBserLCDBuffer part_seq(8500);
bool cs = false;
bytes = "";
for (y = 0; y < height; y++)
@@ -234,11 +224,7 @@ void cDriverUSBserLCD::Refresh(bool refreshAll)
addr = (y * (width / FS)) + x;
else
addr = (y * (width / FS + 1)) + x;
- block_seq = "GLCD";
- block_seq += PKGTYPE_DATA;
- block_seq.append((char*)&addr, 2);
bytes = "";
- len = 0;
cs = true;
}
char byte = (newLCD[x][y]) ^ (config->invert ? 0xff : 0x00);
@@ -247,38 +233,55 @@ void cDriverUSBserLCD::Refresh(bool refreshAll)
}
else if (bytes != "")
{
- part_seq.append(block_seq);
- len = bytes.length();
- part_seq.append((char*)&len, 2);
- part_seq.append(bytes);
+ part_seq.Append(bytes, addr);
cs = false;
bytes = "";
- block_seq = "";
}
}
}
if (bytes != "")
- {
- part_seq.append(block_seq);
- len = bytes.length();
- part_seq.append((char*)&len, 2);
- part_seq.append(bytes);
- }
+ part_seq.Append(bytes, addr);
// Send the smaller data block.
- if (part_seq.length() < full_seq.length())
- port->WriteData(part_seq);
+ if (part_seq.GetLength() < full_seq.GetLength())
+ port->WriteData(part_seq.GetString());
else
- port->WriteData(full_seq);
+ port->WriteData(full_seq.GetString());
}
void cDriverUSBserLCD::SetBrightness(unsigned int percent)
{
- return;
unsigned char brightness = 255 * percent / 100;
- std::string pkg = "GLCD" + PKGTYPE_BRIGHTNESS + brightness;
+ std::string pkg = "GLCD";
+ pkg += PKGTYPE_BRIGHTNESS;
+ pkg += brightness;
port->WriteData(pkg);
}
+
+cDriverUSBserLCDBuffer::cDriverUSBserLCDBuffer(int aExpectedBytes)
+{
+ buffer = "";
+ buffer.reserve(aExpectedBytes);
+}
+void cDriverUSBserLCDBuffer::Append(std::string aBytes, uint16_t aAddress)
+{
+ buffer += "GLCD";
+ buffer += PKGTYPE_DATA;
+ buffer.append((char*)&aAddress, 2);
+ uint16_t len = aBytes.length();
+ buffer.append((char*)&len, 2);
+ buffer.append(aBytes);
+}
+int cDriverUSBserLCDBuffer::GetLength() const
+{
+ return buffer.length();
}
+std::string cDriverUSBserLCDBuffer::GetString() const
+{
+ return buffer;
+}
+
+
+} // end of namespace
diff --git a/glcddrivers/usbserlcd.h b/glcddrivers/usbserlcd.h
index 698e90c..abd6f8d 100644
--- a/glcddrivers/usbserlcd.h
+++ b/glcddrivers/usbserlcd.h
@@ -56,6 +56,18 @@ public:
virtual void SetBrightness(unsigned int percent);
};
+
+class cDriverUSBserLCDBuffer {
+private:
+ std::string buffer;
+
+public:
+ cDriverUSBserLCDBuffer(int aExpectedBytes);
+ int GetLength() const;
+ void Append(std::string aBytes, uint16_t aAddress);
+ std::string GetString() const;
+};
+
} // end of namespace
#endif
diff --git a/graphlcd.conf b/graphlcd.conf
index 0083dbc..ad9a573 100644
--- a/graphlcd.conf
+++ b/graphlcd.conf
@@ -724,3 +724,4 @@ Backlight=yes
# https://github.com/M-Reimer/usbserlcd
Driver=usbserlcd
Device=/dev/ttyUSB0
+RefreshDisplay=0