Maxim Integrated / Mbed OS MAXREFDES155#

Dependencies:   MaximInterface

Revision:
11:989eabe2a376
Parent:
10:71359af61af8
Child:
13:6a6225690c2e
--- a/Display.cpp	Mon Apr 10 11:55:33 2017 -0500
+++ b/Display.cpp	Wed May 03 16:08:59 2017 -0500
@@ -58,29 +58,29 @@
 }
 
 void Display::update()
-{   
+{
+    const int rowsPerPage = 8;
+    const int pages = height / rowsPerPage;
     sendCommand(0xAE);
     sendCommand(0x40);
-    const int rowsPerPage = 8;
-    int row = -rowsPerPage;
-    int column = m_canvas.width();
-    for (Bitmap::SegmentBuffer::const_iterator it = m_canvas.data().begin(); it != m_canvas.data().end(); it++)
+    for (int page = 0; page < pages; page++)
     {
-        if (column == m_canvas.width())
+        sendCommand(0xB0 + static_cast<uint8_t>(page));
+        sendCommand(0x10);
+        sendCommand(0x00);
+        for (int column = 0; column < width; column++)
         {
-            row += rowsPerPage;
-            if (row >= height) // Height of the canvas is greater than height of the display.
-                break;
-            column = 0;
-            sendCommand(0xB0 + static_cast<uint8_t>(row / rowsPerPage));
-            sendCommand(0x10);
-            sendCommand(0x00);
+            uint8_t segment = 0;
+            for (int pixel = 0; pixel < rowsPerPage; pixel++)
+            {
+                segment <<= 1;
+                if (m_canvas.pixelEnabled(column, ((pages - 1 - page) * rowsPerPage) + pixel))
+                {
+                    segment |= 1;
+                }
+            }
+            sendData(segment);
         }
-        if (column < width)
-        {
-            sendData(*it);
-        }
-        column++;
     }
     sendCommand(0xAF);
 }