Skip to content

Commit 8ba09f8

Browse files
committed
Added partial update pixel count.
1 parent af38e58 commit 8ba09f8

File tree

5 files changed

+81
-25
lines changed

5 files changed

+81
-25
lines changed

src/Inkplate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Inkplate : public System, public Graphics
4747
void clearDisplay();
4848
void display(bool leaveOn = false);
4949
// void writeRow(uint8_t data);
50-
void partialUpdate(bool _forced = false, bool leaveOn = false);
50+
uint32_t partialUpdate(bool _forced = false, bool leaveOn = false);
5151

5252
#ifdef ARDUINO_INKPLATECOLOR
5353
void clean();

src/boards/Inkplate10.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,17 @@ void IRAM_ATTR Inkplate::display3b(bool leaveOn)
311311
* deep sleep
312312
*
313313
* @note Partial update only works in black and white mode
314+
*
315+
* @return Number of pixels changed from black to white, leaving blur
314316
*/
315-
void Inkplate::partialUpdate(bool _forced, bool leaveOn)
317+
uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
316318
{
317319
if (getDisplayMode() == 1)
318-
return;
320+
return 0;
319321
if (_blockPartial == 1 && !_forced)
320322
{
321323
display1b(leaveOn);
322-
return;
324+
return 0;
323325
}
324326

325327
uint32_t _pos = (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
@@ -328,12 +330,22 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
328330
uint8_t diffw, diffb;
329331
uint32_t n = (E_INK_WIDTH * E_INK_HEIGHT / 4) - 1;
330332

333+
uint32_t changeCount = 0;
334+
331335
for (int i = 0; i < E_INK_HEIGHT; ++i)
332336
{
333337
for (int j = 0; j < E_INK_WIDTH / 8; ++j)
334338
{
335339
diffw = *(DMemoryNew + _pos) & ~*(_partial + _pos);
336340
diffb = ~*(DMemoryNew + _pos) & *(_partial + _pos);
341+
if (diffw) // count pixels turning from black to white as these are visible blur
342+
{
343+
for (int bv = 1; bv < 256; bv <<= 1)
344+
{
345+
if (diffw & bv)
346+
++changeCount;
347+
}
348+
}
337349
_pos--;
338350
*(_pBuffer + n) = LUTW[diffw >> 4] & (LUTB[diffb >> 4]);
339351
n--;
@@ -346,7 +358,7 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
346358
{
347359
if (!einkOn())
348360
{
349-
return;
361+
return 0;
350362
}
351363
}
352364

@@ -382,6 +394,8 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
382394
einkOff();
383395

384396
memcpy(DMemoryNew, _partial, E_INK_WIDTH * E_INK_HEIGHT / 8);
397+
398+
return changeCount;
385399
}
386400

387401
/**

src/boards/Inkplate5.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,28 +345,40 @@ void IRAM_ATTR Inkplate::display3b(bool leaveOn)
345345
* deep sleep
346346
*
347347
* @note Partial update only works in black and white mode
348+
*
349+
* @return Number of pixels changed from black to white, leaving blur
348350
*/
349-
void Inkplate::partialUpdate(bool _forced, bool leaveOn)
351+
uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
350352
{
351353
if (getDisplayMode() == 1)
352-
return;
354+
return 0;
353355

354356
if (_blockPartial == 1 && !_forced)
355357
{
356358
display1b(leaveOn);
357-
return;
359+
return 0;
358360
}
359361
uint32_t _pos = (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
360362
uint8_t data;
361363
uint8_t diffw, diffb;
362364
uint32_t n = (E_INK_WIDTH * E_INK_HEIGHT / 4) - 1;
363365

364-
for (int i = 0; i < E_INK_HEIGHT; i++)
366+
uint32_t changeCount = 0;
367+
368+
for (int i = 0; i < E_INK_HEIGHT; ++i)
365369
{
366-
for (int j = 0; j < E_INK_WIDTH / 8; j++)
370+
for (int j = 0; j < E_INK_WIDTH / 8; ++j)
367371
{
368-
diffw = ((*(DMemoryNew + _pos)) ^ (*(_partial + _pos))) & (~(*(_partial + _pos)));
369-
diffb = ((*(DMemoryNew + _pos)) ^ (*(_partial + _pos))) & ((*(_partial + _pos)));
372+
diffw = *(DMemoryNew + _pos) & ~*(_partial + _pos);
373+
diffb = ~*(DMemoryNew + _pos) & *(_partial + _pos);
374+
if (diffw) // count pixels turning from black to white as these are visible blur
375+
{
376+
for (int bv = 1; bv < 256; bv <<= 1)
377+
{
378+
if (diffw & bv)
379+
++changeCount;
380+
}
381+
}
370382
_pos--;
371383
*(_pBuffer + n) = LUTW[diffw >> 4] & (LUTB[diffb >> 4]);
372384
n--;
@@ -379,7 +391,7 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
379391
{
380392
if (!einkOn())
381393
{
382-
return;
394+
return 0;
383395
}
384396
}
385397

@@ -416,6 +428,8 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
416428
*(DMemoryNew + i) &= *(_partial + i);
417429
*(DMemoryNew + i) |= (*(_partial + i));
418430
}
431+
432+
return changeCount;
419433
}
420434

421435
/**

src/boards/Inkplate6.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,18 @@ void Inkplate::display3b(bool leaveOn)
361361
* deep sleep
362362
*
363363
* @note Partial update only works in black and white mode
364+
*
365+
* @return Number of pixels changed from black to white, leaving blur
364366
*/
365-
void Inkplate::partialUpdate(bool _forced, bool leaveOn)
367+
uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
366368
{
367369
if (getDisplayMode() == 1)
368-
return;
370+
return 0;
369371

370372
if (_blockPartial == 1 && !_forced)
371373
{
372374
display1b(leaveOn);
373-
return;
375+
return 0;
374376
}
375377

376378
uint16_t _pos = (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
@@ -379,12 +381,22 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
379381
uint8_t diffw, diffb;
380382
uint32_t n = (E_INK_WIDTH * E_INK_HEIGHT / 4) - 1;
381383

384+
uint32_t changeCount = 0;
385+
382386
for (int i = 0; i < E_INK_HEIGHT; ++i)
383387
{
384388
for (int j = 0; j < E_INK_WIDTH / 8; ++j)
385389
{
386390
diffw = *(DMemoryNew + _pos) & ~*(_partial + _pos);
387391
diffb = ~*(DMemoryNew + _pos) & *(_partial + _pos);
392+
if (diffw) // count pixels turning from black to white as these are visible blur
393+
{
394+
for (int bv = 1; bv < 256; bv <<= 1)
395+
{
396+
if (diffw & bv)
397+
++changeCount;
398+
}
399+
}
388400
_pos--;
389401
*(_pBuffer + n) = LUTW[diffw >> 4] & (LUTB[diffb >> 4]);
390402
n--;
@@ -397,7 +409,7 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
397409
{
398410
if (!einkOn())
399411
{
400-
return;
412+
return 0;
401413
}
402414
}
403415

@@ -433,6 +445,8 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
433445
einkOff();
434446

435447
memcpy(DMemoryNew, _partial, E_INK_WIDTH * E_INK_HEIGHT / 8);
448+
449+
return changeCount;
436450
}
437451

438452
/**

src/boards/Inkplate6plus.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,17 @@ void Inkplate::display3b(bool leaveOn)
413413
* deep sleep
414414
*
415415
* @note Partial update only works in black and white mode
416+
*
417+
* @return Number of pixels changed from black to white, leaving blur
416418
*/
417-
void Inkplate::partialUpdate(bool _forced, bool leaveOn)
419+
uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
418420
{
419421
if (getDisplayMode() == 1)
420-
return;
422+
return 0;
421423
if (_blockPartial == 1 && !_forced)
422424
{
423425
display1b(leaveOn);
424-
return;
426+
return 0;
425427
}
426428

427429
uint32_t _pos = (E_INK_WIDTH * E_INK_HEIGHT / 8) - 1;
@@ -430,12 +432,22 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
430432
uint8_t diffw, diffb;
431433
uint32_t n = (E_INK_WIDTH * E_INK_HEIGHT / 4) - 1;
432434

433-
for (int i = 0; i < E_INK_HEIGHT; i++)
435+
uint32_t changeCount = 0;
436+
437+
for (int i = 0; i < E_INK_HEIGHT; ++i)
434438
{
435-
for (int j = 0; j < E_INK_WIDTH / 8; j++)
439+
for (int j = 0; j < E_INK_WIDTH / 8; ++j)
436440
{
437-
diffw = ((*(DMemoryNew + _pos)) ^ (*(_partial + _pos))) & (~(*(_partial + _pos)));
438-
diffb = ((*(DMemoryNew + _pos)) ^ (*(_partial + _pos))) & ((*(_partial + _pos)));
441+
diffw = *(DMemoryNew + _pos) & ~*(_partial + _pos);
442+
diffb = ~*(DMemoryNew + _pos) & *(_partial + _pos);
443+
if (diffw) // count pixels turning from black to white as these are visible blur
444+
{
445+
for (int bv = 1; bv < 256; bv <<= 1)
446+
{
447+
if (diffw & bv)
448+
++changeCount;
449+
}
450+
}
439451
_pos--;
440452
*(_pBuffer + n) = LUTW[diffw >> 4] & (LUTB[diffb >> 4]);
441453
n--;
@@ -448,7 +460,7 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
448460
{
449461
if (!einkOn())
450462
{
451-
return;
463+
return 0;
452464
}
453465
}
454466

@@ -506,6 +518,8 @@ void Inkplate::partialUpdate(bool _forced, bool leaveOn)
506518
if (!leaveOn)
507519
einkOff();
508520
memcpy(DMemoryNew, _partial, E_INK_WIDTH * E_INK_HEIGHT / 8);
521+
522+
return changeCount;
509523
}
510524

511525
#endif

0 commit comments

Comments
 (0)