@@ -61,6 +61,8 @@ class SSD1306Brzo : public OLEDDisplay {
6161 }
6262
6363 void display (void ) {
64+ const int x_offset = (128 - this ->width ()) / 2 ;
65+
6466 #ifdef OLEDDISPLAY_DOUBLE_BUFFER
6567 uint8_t minBoundY = UINT8_MAX;
6668 uint8_t maxBoundY = 0 ;
@@ -72,9 +74,9 @@ class SSD1306Brzo : public OLEDDisplay {
7274
7375 // Calculate the Y bounding box of changes
7476 // and copy buffer[pos] to buffer_back[pos];
75- for (y = 0 ; y < (displayHeight / 8 ); y++) {
76- for (x = 0 ; x < displayWidth ; x++) {
77- uint16_t pos = x + y * displayWidth ;
77+ for (y = 0 ; y < (this -> height () / 8 ); y++) {
78+ for (x = 0 ; x < this -> width () ; x++) {
79+ uint16_t pos = x + y * this -> width () ;
7880 if (buffer[pos] != buffer_back[pos]) {
7981 minBoundY = _min (minBoundY, y);
8082 maxBoundY = _max (maxBoundY, y);
@@ -92,23 +94,26 @@ class SSD1306Brzo : public OLEDDisplay {
9294 if (minBoundY == UINT8_MAX) return ;
9395
9496 sendCommand (COLUMNADDR);
95- sendCommand (minBoundX);
96- sendCommand (maxBoundX);
97+ sendCommand (x_offset + minBoundX);
98+ sendCommand (x_offset + maxBoundX);
9799
98100 sendCommand (PAGEADDR);
99101 sendCommand (minBoundY);
100102 sendCommand (maxBoundY);
101103
102104 byte k = 0 ;
103- uint8_t sendBuffer[17 ];
105+
106+ int buflen = ( this ->width () / 8 ) + 1 ;
107+
108+ uint8_t sendBuffer[buflen];
104109 sendBuffer[0 ] = 0x40 ;
105110 brzo_i2c_start_transaction (this ->_address , BRZO_I2C_SPEED);
106111 for (y = minBoundY; y <= maxBoundY; y++) {
107112 for (x = minBoundX; x <= maxBoundX; x++) {
108113 k++;
109- sendBuffer[k] = buffer[x + y * displayWidth ];
110- if (k == 16 ) {
111- brzo_i2c_write (sendBuffer, 17 , true );
114+ sendBuffer[k] = buffer[x + y * this -> width () ];
115+ if (k == (buflen- 1 ) ) {
116+ brzo_i2c_write (sendBuffer, buflen , true );
112117 k = 0 ;
113118 }
114119 }
@@ -119,28 +124,28 @@ class SSD1306Brzo : public OLEDDisplay {
119124 #else
120125 // No double buffering
121126 sendCommand (COLUMNADDR);
122- sendCommand (0x0 );
123- sendCommand (0x7F );
127+
128+ sendCommand (x_offset);
129+ sendCommand (x_offset + (this ->width () - 1 ));
124130
125131 sendCommand (PAGEADDR);
126132 sendCommand (0x0 );
133+ sendCommand ((this ->height () / 8 ) - 1 );
127134
128- if (geometry == GEOMETRY_128_64) {
129- sendCommand (0x7 );
130- } else if (geometry == GEOMETRY_128_32) {
131- sendCommand (0x3 );
132- }
135+ int buflen = ( this ->width () / 8 ) + 1 ;
133136
134- uint8_t sendBuffer[17 ];
137+ uint8_t sendBuffer[buflen ];
135138 sendBuffer[0 ] = 0x40 ;
139+
136140 brzo_i2c_start_transaction (this ->_address , BRZO_I2C_SPEED);
141+
137142 for (uint16_t i=0 ; i<displayBufferSize; i++) {
138- for (uint8_t x=1 ; x<17 ; x++) {
143+ for (uint8_t x=1 ; x<buflen ; x++) {
139144 sendBuffer[x] = buffer[i];
140145 i++;
141146 }
142147 i--;
143- brzo_i2c_write (sendBuffer, 17 , true );
148+ brzo_i2c_write (sendBuffer, buflen , true );
144149 yield ();
145150 }
146151 brzo_i2c_end_transaction ();
0 commit comments