-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathTM16xxMatrix16.cpp
53 lines (43 loc) · 1.33 KB
/
TM16xxMatrix16.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
TM16xxMatrix.h - LED Matrix library for TM16xx, max 16 segments.
Made by Maxint R&D. See https://github.com/maxint-rd/
*/
#include "TM16xxMatrix16.h"
TM16xxMatrix16::TM16xxMatrix16(TM16xx *pTM16xx, byte nColumns, byte nRows)
{
_pTM16xx=pTM16xx;
_nColumns=nColumns;
_nRows=nRows;
// offscreen bitmap is required to set an individual pixel, while retaining the others
// TODO: use dynamic memory allocation for the off-screen bitmap
// as different chips support different sizes
}
void TM16xxMatrix16::setColumn(byte nCol, uint16_t uPixels, bool fRender)
{
_uColumns[nCol]=uPixels;
if(fRender)
_pTM16xx->setSegments16(uPixels, nCol);
}
void TM16xxMatrix16::setAll(bool fOn, bool fRender)
{
for(byte nCol=0; nCol<_nColumns; nCol++)
setColumn(nCol, fOn?0xFFFF:0, fRender);
}
void TM16xxMatrix16::setPixel(byte nCol, byte nRow, bool fOn, bool fRender)
{
uint16_t uColumn=_uColumns[nCol];
if(fOn)
uColumn=uColumn | _BV(nRow);
else
uColumn=uColumn & ~_BV(nRow);
setColumn(nCol, uColumn, fRender);
}
void TM16xxMatrix16::render(void)
{ // render the offscreen bitmap to display all pixels
for(byte nCol=0; nCol<_nColumns; nCol++)
_pTM16xx->setSegments16(_uColumns[nCol], nCol);
}
bool TM16xxMatrix16::getPixel(byte nCol, byte nRow)
{
return((_uColumns[nCol]&bit(nRow))!=0);
}